/* * Make a prettier Dialog box * * (c)2000 David R. Adaskin * */ import com.sun.kjava.*; public class InfoDialog extends Dialog { int left = 20; // Defaults int top = 20; int width; int height; int tbX; int tbY; int tbW; int tbH; int buttonX; int buttonY; static final int BITMAP_HEIGHT = 32; static final int BUTTON_HEIGHT = 14; static final int BITMAP_SPACE = 1; static final int BUTTON_SPACE = 2; static final int SIDE_MARGIN = 5; static final int TOP_MARGIN = 5; static final int BOTTOM_MARGIN = 10; public InfoDialog(DialogOwner o, String title, String text) { super(o,title,text,"OK"); scaleToText(text); super.g.setDrawRegion(left, top, width, height); tbX = left + SIDE_MARGIN; tbY = top + TOP_MARGIN; tbW = width - SIDE_MARGIN; tbH = height - (BOTTOM_MARGIN+BUTTON_HEIGHT); super.tb = new TextBox(text, tbX, tbY, tbW, tbH); buttonX = left + width - (super.g.getWidth("OK") + 5) - 2; buttonY = top+height-BUTTON_HEIGHT-2; super.button = new Button("OK", buttonX, buttonY); } public void showDialog() { super.showDialog(); super.g.drawBorder(left, top, width, height, super.g.GRAY, super.g.RAISED); } void scaleToText(String str) { int pointer=0; int count=0; int newPtr; int tmp; int additional = TOP_MARGIN + BOTTOM_MARGIN; int end = str.length(); height = super.g.getHeight(str); width = 0; while (pointer<=end){ newPtr=str.indexOf(10, pointer); // "\n" is decimal 10 if (newPtr == -1) newPtr = end; count++; tmp=g.getWidth(str.substring(pointer, newPtr)); if (tmp > width) { width = tmp; } pointer = newPtr + 1; } additional += BUTTON_HEIGHT; height = height * count + additional; width = width + 2 * SIDE_MARGIN + 1; } }