void (Object component) { String classname = getClass(component); if ("combobox" == classname) { if (getBoolean(component, "editable", true)) { Image icon = getIcon(component, "icon", null); layoutField(component, block, false, (icon != null) ? icon.getWidth(this) : 0); } // set editable -> validate (overwrite textfield repaint) else { int selected = getInteger(component, "selected", -1); if (selected != -1) { Object choice = getItem(component, "choice", selected); set(component, "text", get(choice, "text")); set(component, "icon", get(choice, "icon")); } } } else if (("textfield" == classname) || ("passwordfield" == classname)) { layoutField(component, 0, ("passwordfield" == classname), 0); } else if ("textarea" == classname) { String text = getString(component, "text", ""); int start = getInteger(component, "start", 0); if (start > text.length()) { setInteger(component, "start", start = text.length(), 0); } int end = getInteger(component, "end", 0); if (end > text.length()) { setInteger(component, "end", end = text.length(), 0); } int caretx = 0; int carety = 0; FontMetrics fm = getFontMetrics(getFont()); //java int width = 0, height = 0; for (int i = 0, j = 0; j != -1; i = j + 1) { j = text.indexOf('\n', i); if (i != j) { // && i != text.length() String line = (j != -1) ? text.substring(i, j) : text.substring(i); //java width = Math.max(width, fm.stringWidth(line)); //java //midp width = font.substringWidth(text, i, ((j != -1) ? j : text.length()) - i); } if ((end >= i) && ((j == -1) || (end <= j))) { caretx = fm.stringWidth(text.substring(i, end)); //java //midp caretx = font.substringWidth(text, i, end - i); carety = height; } height += fm.getHeight(); } layoutScrollPane(component, width + 2, height - fm.getLeading() + 2, 0, 0); scrollToVisible(component, caretx, carety, 2, fm.getAscent() + fm.getDescent() + 2); } else if ("tabbedpane" == classname) { Rectangle bounds = getRectangle(component, "bounds"); String placement = getString(component, "placement", "top"); boolean horizontal = ((placement == "top") || (placement == "bottom")); int tabd = 0; int tabsize = 0; for (Object comp = get(component, "tab"); comp != null; comp = get(comp, ":next")) { Dimension d = getSize(comp, 8, 4, "left"); setRectangle(comp, "bounds", horizontal ? tabd : 0, horizontal ? 0 : tabd, d.width, d.height); tabd += horizontal ? d.width : d.height; tabsize = Math.max(tabsize, horizontal ? d.height : d.width); } for (Object comp = get(component, "tab"); comp != null; comp = get(comp, ":next")) { Rectangle r = getRectangle(comp, "bounds"); if (horizontal) { if (placement == "bottom") { r.y = bounds.height - tabsize; } r.height = tabsize; } else { if (placement == "right") { r.x = bounds.width - tabsize; } r.width = tabsize; } } int cx = (placement == "left") ? (tabsize + 1) : 2; int cy = (placement == "top") ? (tabsize + 1) : 2; int cwidth = bounds.width - (horizontal ? 4 : (tabsize + 3)); int cheight = bounds.height - (horizontal ? (tabsize + 3) : 4); for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { if (!getBoolean(comp, "visible", true)) { continue; } setRectangle(comp, "bounds", cx, cy, cwidth, cheight); doLayout(comp); } } else if (("panel" == classname) || (classname == "dialog")) { int gap = getInteger(component, "gap", 0); int[][] grid = getGrid(component, gap); if (grid != null) { int top = getInteger(component, "top", 0); int left = getInteger(component, "left", 0); int bottom = getInteger(component, "bottom", 0); int right = getInteger(component, "right", 0); if (classname == "dialog") { int titleheight = getInteger(component, "titleheight", 0); top += 4 + titleheight; left += 4; bottom += 4; right += 4; } Rectangle bounds = getRectangle(component, "bounds"); for (int i = 0; i < 2; i++) { int d = ((i == 0) ? (bounds.width - left - right) : (bounds.height - top - bottom)) - getSum(grid[i], 0, grid[i].length, gap, false); if (d != 0) { int w = getSum(grid[2 + i], 0, grid[2 + i].length, 0, false); if (w > 0) { for (int j = 0; j < grid[i].length; j++) { if (grid[2 + i][j] != 0) { grid[i][j] += d * grid[2 + i][j] / w; } } } } } int i = 0; for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { if (!getBoolean(comp, "visible", true)) { continue; } int ix = left + getSum(grid[0], 0, grid[4][i], gap, true); int iy = top + getSum(grid[1], 0, grid[5][i], gap, true); int iwidth = getSum(grid[0], grid[4][i], grid[6][i], gap, false); int iheight = getSum(grid[1], grid[5][i], grid[7][i], gap, false); String halign = getString(comp, "halign", "fill"); String valign = getString(comp, "valign", "fill"); if ((halign != "fill") || (valign != "fill")) { Dimension d = getPreferredSize(comp); if (halign != "fill") { int dw = Math.max(0, iwidth - d.width); if (halign == "center") { ix += dw / 2; } else if (halign == "right") { ix += dw; } iwidth -= dw; } if (valign != "fill") { int dh = Math.max(0, iheight - d.height); if (valign == "center") { iy += dh / 2; } else if (valign == "bottom") { iy += dh; } iheight -= dh; } } setRectangle(comp, "bounds", ix, iy, iwidth, iheight); doLayout(comp); i++; } } } else if ("desktop" == classname) { Rectangle bounds = getRectangle(component, "bounds"); for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { String iclass = getClass(comp); if (iclass == "dialog") { Dimension d = getPreferredSize(comp); if (get(comp, "bounds") == null) { setRectangle(comp, "bounds", Math.max(0, (bounds.width - d.width) / 2), Math.max(0, (bounds.height - d.height) / 2), Math.min(d.width, bounds.width), Math.min(d.height, bounds.height)); } } else if ((iclass == "combolist") || (iclass == "popupmenu")) { iclass = iclass; //compiler bug } else { setRectangle(comp, "bounds", 0, 0, bounds.width, bounds.height); } doLayout(comp); } } else if ("spinbox" == classname) { layoutField(component, block, false, 0); } else if ("splitpane" == classname) { Rectangle bounds = getRectangle(component, "bounds"); boolean horizontal = ("vertical" != get(component, "orientation")); int divider = getInteger(component, "divider", -1); int maxdiv = (horizontal ? bounds.width : bounds.height) - 5; Object comp1 = get(component, "component"); boolean visible1 = (comp1 != null) && getBoolean(comp1, "visible", true); if (divider == -1) { int d1 = 0; if (visible1) { Dimension d = getPreferredSize(comp1); d1 = horizontal ? d.width : d.height; } divider = Math.min(d1, maxdiv); setInteger(component, "divider", divider, -1); } else if (divider > maxdiv) { setInteger(component, "divider", divider = maxdiv, -1); } if (visible1) { setRectangle(comp1, "bounds", 0, 0, horizontal ? divider : bounds.width, horizontal ? bounds.height : divider); doLayout(comp1); } Object comp2 = (comp1 != null) ? get(comp1, ":next") : null; if ((comp2 != null) && getBoolean(comp2, "visible", true)) { setRectangle(comp2, "bounds", horizontal ? (divider + 5) : 0, horizontal ? 0 : (divider + 5), horizontal ? (bounds.width - 5 - divider) : bounds.width, horizontal ? bounds.height : (bounds.height - 5 - divider)); doLayout(comp2); } } else if (("list" == classname) || ("table" == classname) || ("tree" == classname)) { int width = 0; int columnheight = 0; if ("table" == classname) { for (Object column = get(component, "column"); column != null; column = get(column, ":next")) { width += getInteger(column, "width", 80); Dimension d = getSize(column, 2, 2, "left"); columnheight = Math.max(columnheight, d.height); } } String itemname = ("list" == classname) ? "item" : (("table" == classname) ? "row" : "node"); int y = 0; int level = 0; for (Object item = get(component, itemname); item != null; ) { int x = 0; int iwidth = 0; int iheight = 0; if ("table" == classname) { iwidth = width; for (Object cell = get(item, "cell"); cell != null; cell = get(cell, ":next")) { Dimension d = getSize(cell, 2, 3, "left"); iheight = Math.max(iheight, d.height); } } else { if ("tree" == classname) { x = (level + 1) * block; } Dimension d = getSize(item, 2, 3, "left"); iwidth = d.width; iheight = d.height; width = Math.max(width, x + d.width); } setRectangle(item, "bounds", x, y, iwidth, iheight); y += iheight; if ("tree" == classname) { Object next = get(item, "node"); if ((next != null) && getBoolean(item, "expanded", true)) { level++; } else { while (((next = get(item, ":next")) == null) && (level > 0)) { item = getParent(item); level--; } } item = next; } else { item = get(item, ":next"); } } layoutScrollPane(component, width, y - 1, 0, columnheight); } else if ("menubar" == classname) { Rectangle bounds = getRectangle(component, "bounds"); int x = 0; for (Object menu = get(component, "menu"); menu != null; menu = get(menu, ":next")) { Dimension d = getSize(menu, 8, 4, "left"); setRectangle(menu, "bounds", x, 0, d.width, bounds.height); x += d.width; } } else if (("combolist" == classname) || ("popupmenu" == classname)) { boolean combo = ("combolist" == classname); int pw = 0; int ph = 0; int pxy = combo ? 0 : 1; for (Object item = get(get(component, combo ? "combobox" : "menu"), combo ? "choice" : "menu"); item != null; item = get(item, ":next")) { String itemclass = combo ? null : getClass(item); Dimension d = (itemclass == "separator") ? new Dimension(1, 1) : getSize(item, 8, 4, "left"); if (itemclass == "checkboxmenuitem") { d.width = d.width + block + 3; d.height = Math.max(block, d.height); } else if (itemclass == "menu") { d.width += block; } setRectangle(item, "bounds", pxy, pxy + ph, d.width, d.height); pw = Math.max(pw, d.width); ph += d.height; } Rectangle r = getRectangle(component, "bounds"); r.width = pw + 2; r.height = ph + 2; if (combo) { Rectangle db = getRectangle(content, "bounds"); if (r.y + ph + 2 > db.height) { r.width = pw + 2 + block; r.height = db.height - r.y; } else { r.height = Math.min(r.height, db.height - r.y); } r.width = Math.min(r.width, db.width - r.x); layoutScrollPane(component, pw, ph, 0, 0);//~ } } //java> else if ("bean" == classname) { Rectangle r = getRectangle(component, "bounds"); ((Component)get(component, "bean")).setBounds(r); } //<java }