Пример #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);
 }
Пример #2
0
 /**
  * Set the number of columns in this FormContainer. If this increases the number of columns, the
  * new columns will have weights of 1.0 by default. If this decreases the number of columns, any
  * child Widgets that extend beyond the last column will be removed.
  */
 public void setColumnCount(int columns) {
   double newWeight[] = new double[columns];
   if (columns > colWeight.length) {
     for (int i = 0; i < colWeight.length; i++) newWeight[i] = colWeight[i];
     for (int i = colWeight.length; i < newWeight.length; i++) newWeight[i] = 1.0;
   } else {
     for (int i = child.size() - 1; i >= 0; i--) {
       ChildInfo info = child.get(i);
       if (info.x + info.width > columns) remove(i);
     }
     for (int i = 0; i < newWeight.length; i++) newWeight[i] = colWeight[i];
   }
   colWeight = newWeight;
 }
Пример #3
0
 /**
  * Set the number of rows in this FormContainer. If this increases the number of rows, the new
  * rows will have weights of 1.0 by default. If this decreases the number of rows, any child
  * Widgets that extend beyond the last row will be removed.
  */
 public void setRowCount(int rows) {
   double newWeight[] = new double[rows];
   if (rows > rowWeight.length) {
     for (int i = 0; i < rowWeight.length; i++) newWeight[i] = rowWeight[i];
     for (int i = rowWeight.length; i < newWeight.length; i++) newWeight[i] = 1.0;
   } else {
     for (int i = child.size() - 1; i >= 0; i--) {
       ChildInfo info = child.get(i);
       if (info.y + info.height > rows) remove(i);
     }
     for (int i = 0; i < newWeight.length; i++) newWeight[i] = rowWeight[i];
   }
   rowWeight = newWeight;
 }
Пример #4
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();
   }
 }
Пример #5
0
 /** Get a Collection containing all child Widgets of this container. */
 public Collection<Widget> getChildren() {
   ArrayList<Widget> list = new ArrayList<Widget>(child.size());
   for (int i = 0; i < child.size(); i++) list.add(child.get(i).widget);
   return list;
 }
Пример #6
0
 /** Get the number of children in this container. */
 public int getChildCount() {
   return child.size();
 }
Пример #7
0
 /**
  * Get the index of a particular Widget.
  *
  * @param widget the Widget to locate
  * @return the position of the Widget within this container
  */
 public int getWidgetIndex(Widget widget) {
   for (int i = 0; i < child.size(); i++) if (child.get(i).widget == widget) return i;
   return -1;
 }
Пример #8
0
 /** Remove all child Widgets from this container. */
 public void removeAll() {
   getComponent().removeAll();
   for (int i = 0; i < child.size(); i++) removeAsParent(child.get(i).widget);
   child.clear();
   invalidateSize();
 }