Dimension (Object component) { int width = getInteger(component, "width", 0); int height = getInteger(component, "height", 0); if ((width > 0) && (height > 0)) { return new Dimension(width, height); } String classname = getClass(component); //System.out.println("classname: " + classname); if ("label" == classname) { return getSize(component, 0, 0, "left"); } if ("button" == classname) { return getSize(component, 12, 6, "center"); } if ("checkbox" == classname) { Dimension d = getSize(component, 0, 0, "left"); d.width = d.width + block + 3; d.height = Math.max(block, d.height); return d; } if ("combobox" == classname) { if (getBoolean(component, "editable", true)) { Dimension size = getFieldSize(component); Image icon = getIcon(component, "icon", null); if (icon != null) { size.width += icon.getWidth(this); size.height = Math.max(size.height, icon.getHeight(this) + 2); } size.width += block; return size; } else { int selected = getInteger(component, "selected", -1); return getSize((selected != -1) ? getItemImpl(component, "choice", selected) : get(component, "choice"), 4 + block, 4, "left"); } } if (("textfield" == classname) || ("passwordfield" == classname)) { return getFieldSize(component); } if ("textarea" == classname) { int columns = getInteger(component, "columns", 0); int rows = getInteger(component, "rows", 0); // 'e' -> 'm' ? FontMetrics fm = getFontMetrics(getFont()); //java return new Dimension( ((columns > 0) ? (columns * fm.charWidth('e') + 2) : 76) + 2 + block, ((rows > 0) ? (rows * fm.getHeight() - fm.getLeading() + 2) : 76) + 2 + block); } if ("tabbedpane" == classname) { String placement = getString(component, "placement", "top"); boolean horizontal = ((placement == "top") || (placement == "bottom")); int tabsize = 0; int contentwidth = 0; int contentheight = 0; for (Object comp = get(component, "tab"); comp != null; comp = get(comp, ":next")) { Dimension d = getSize(comp, 8, 4, "left"); tabsize = Math.max(tabsize, horizontal ? d.height : d.width); } for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { if (!getBoolean(comp, "visible", true)) { continue; } Dimension d = getPreferredSize(comp); contentwidth = Math.max(contentwidth, d.width); contentheight = Math.max(contentheight, d.height); } return new Dimension(contentwidth + (horizontal ? 4 : (tabsize + 3)), contentheight + (horizontal ? (tabsize + 3) : 4)); } if (("panel" == classname) || (classname == "dialog")) { Dimension size = new Dimension( getInteger(component, "left", 0) + getInteger(component, "right", 0), getInteger(component, "top", 0) + getInteger(component, "bottom", 0)); if (classname == "dialog") { int titleheight = getSize(component, 0, 0, "left").height; setInteger(component, "titleheight", titleheight, 0); size.width += 8; size.height += 8 + titleheight; } int gap = getInteger(component, "gap", 0); int[][] grid = getGrid(component, gap); if (grid != null) { size.width += getSum(grid[0], 0, grid[0].length, gap, false); size.height += getSum(grid[1], 0, grid[1].length, gap, false); } return size; } else if ("desktop" == classname) { Dimension size = new Dimension(); for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { String iclass = getClass(comp); if ((iclass != "dialog") && (iclass != "popupmenu") && (iclass != "combolist")) { Dimension d = getPreferredSize(comp); size.width = Math.max(d.width, size.width); size.height = Math.max(d.height, size.height); } } return size; } if ("spinbox" == classname) { Dimension size = getFieldSize(component); size.width += block; return size; } if ("progressbar" == classname) { boolean horizontal = ("vertical" != get(component, "orientation")); return new Dimension(horizontal ? 76 : 6, horizontal ? 6 : 76); } if ("slider" == classname) { boolean horizontal = ("vertical" != get(component, "orientation")); return new Dimension(horizontal ? 76 : 10, horizontal ? 10 : 76); } if ("splitpane" == classname) { boolean horizontal = ("vertical" != get(component, "orientation")); Object comp1 = get(component, "component"); Dimension size = ((comp1 == null) || !getBoolean(comp1, "visible", true)) ? new Dimension() : getPreferredSize(comp1); Object comp2 = get(comp1, ":next"); if ((comp2 != null) && getBoolean(comp2, "visible", true)) { Dimension d = getPreferredSize(comp2); size.width = horizontal ? (size.width + d.width) : Math.max(size.width, d.width); size.height = horizontal ? Math.max(size.height, d.height) : (size.height + d.height); } if (horizontal) { size.width += 5; } else { size.height += 5; } return size; } if (("list" == classname) || ("table" == classname) || ("tree" == classname)) { return new Dimension(76 + 2 + block, 76 + 2 + block); } if ("separator" == classname) { return new Dimension(1, 1); } if ("menubar" == classname) { Dimension size = new Dimension(0, 0); for (Object menu = get(component, "menu"); menu != null; menu = get(menu, ":next")) { Dimension d = getSize(menu, 8, 4, "left"); size.width += d.width; size.height = Math.max(size.height, d.height); } return size; } //java> if ("bean" == classname) { return ((Component)get(component, "bean")).getPreferredSize(); } //<java throw new IllegalArgumentException((String)classname); }