Beispiel #1
0
 /** Calculate the minimum and preferred size for every row and column. */
 private void calculateSizes() {
   Dimension dim[] = new Dimension[child.size()];
   for (int i = 0; i < dim.length; i++) dim[i] = child.get(i).widget.getMinimumSize();
   minRowSize = calculateRequiredSizes(dim, true);
   minColSize = calculateRequiredSizes(dim, false);
   for (int i = 0; i < dim.length; i++) {
     ChildInfo info = child.get(i);
     LayoutInfo layout = (info.layout == null ? defaultLayout : info.layout);
     dim[i] = layout.getPreferredSize(info.widget);
   }
   prefRowSize = calculateRequiredSizes(dim, true);
   prefColSize = calculateRequiredSizes(dim, false);
 }
Beispiel #2
0
 /**
  * Layout the child Widgets. This may be invoked whenever something has changed (the size of this
  * WidgetContainer, the preferred size of one of its children, etc.) that causes the layout to no
  * longer be correct. If a child is itself a WidgetContainer, its layoutChildren() method will be
  * called in turn.
  */
 public void layoutChildren() {
   if (minColSize == null) calculateSizes();
   Dimension size = getComponent().getSize();
   int rowPos[] = calculatePositions(minRowSize, prefRowSize, rowWeight, size.height);
   int colPos[] = calculatePositions(minColSize, prefColSize, colWeight, size.width);
   Rectangle cell = new Rectangle();
   for (int i = 0; i < child.size(); i++) {
     ChildInfo info = child.get(i);
     LayoutInfo layout = (info.layout == null ? defaultLayout : info.layout);
     cell.x = (info.x == 0 ? 0 : colPos[info.x - 1]);
     cell.y = (info.y == 0 ? 0 : rowPos[info.y - 1]);
     cell.width = colPos[info.x + info.width - 1] - cell.x;
     cell.height = rowPos[info.y + info.height - 1] - cell.y;
     info.widget.getComponent().setBounds(layout.getWidgetLayout(info.widget, cell));
     if (info.widget instanceof WidgetContainer) ((WidgetContainer) info.widget).layoutChildren();
   }
 }