buoy.widget
Class FormContainer

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.WidgetContainer
              extended by buoy.widget.FormContainer

public class FormContainer
extends WidgetContainer

FormContainer is a WidgetContainer which arranges its children in a grid. The width of each row and the height of each column may be different, and a single Widget may occupy a rectangular block of cells.

The column widths and row heights are chosen based on the minimum and preferred sizes of the widgets contained in them. If a FormContainer is made larger than the preferred size required for its children, the extra space is divided between rows and columns based on their weights. That is, a column with weight 2.0 will have twice as much extra width added to it as a column with weight 1.0. A row or column with weight 0.0 will never be made larger than is required to hold its children.

In addition to the event types generated by all Widgets, FormContainers generate the following event types:

Author:
Peter Eastman

Constructor Summary
FormContainer(double[] colWeight, double[] rowWeight)
          Create a new FormContainer.
FormContainer(int numCols, int numRows)
          Create a new FormContainer.
 
Method Summary
 void add(Widget widget, int col, int row)
          Add a Widget to this container.
 void add(Widget widget, int col, int row, int width, int height)
          Add a Widget to this container.
 void add(Widget widget, int col, int row, int width, int height, LayoutInfo layout)
          Add a Widget to this container.
 void add(Widget widget, int col, int row, LayoutInfo layout)
          Add a Widget to this container.
 Widget getChild(int i)
          Get the i'th child of this container.
 java.awt.Rectangle getChildCells(int index)
          Get the range of cells occupied by a Widget.
 java.awt.Rectangle getChildCells(Widget widget)
          Get the range of cells occupied by a Widget.
 int getChildCount()
          Get the number of children in this container.
 LayoutInfo getChildLayout(int index)
          Get the LayoutInfo for a particular Widget.
 LayoutInfo getChildLayout(Widget widget)
          Get the LayoutInfo for a particular Widget.
 java.util.Collection<Widget> getChildren()
          Get a Collection containing all child Widgets of this container.
 int getColumnCount()
          Get the number of columns in this FormContainer.
 double getColumnWeight(int col)
          Get the weight of a particular column.
 javax.swing.JPanel getComponent()
          Get the java.awt.Component corresponding to this Widget.
 LayoutInfo getDefaultLayout()
          Get the default LayoutInfo.
 java.awt.Dimension getMinimumSize()
          Get the smallest size at which this Widget can reasonably be drawn.
 java.awt.Dimension getPreferredSize()
          Get the preferred size at which this Widget will look best.
 int getRowCount()
          Get the number of rows in this FormContainer.
 double getRowWeight(int row)
          Get the weight of a particular row.
 int getWidgetIndex(Widget widget)
          Get the index of a particular Widget.
 void layoutChildren()
          Layout the child Widgets.
 void remove(int index)
          Remove a child Widget from this container.
 void remove(Widget widget)
          Remove a child Widget from this container.
 void removeAll()
          Remove all child Widgets from this container.
 void setChildCells(int index, java.awt.Rectangle cells)
          Set the range of cells occupied by a Widget.
 void setChildCells(Widget widget, java.awt.Rectangle cells)
          Set the range of cells occupied by a Widget.
 void setChildLayout(int index, LayoutInfo layout)
          Set the LayoutInfo for a particular Widget.
 void setChildLayout(Widget widget, LayoutInfo layout)
          Set the LayoutInfo for a particular Widget.
 void setColumnCount(int columns)
          Set the number of columns in this FormContainer.
 void setColumnWeight(int col, double weight)
          Set the weight of a particular column.
 void setDefaultLayout(LayoutInfo layout)
          Set the default LayoutInfo.
 void setRowCount(int rows)
          Set the number of rows in this FormContainer.
 void setRowWeight(int row, double weight)
          Set the weight of a particular row.
 
Methods inherited from class buoy.widget.WidgetContainer
isOpaque, setOpaque
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getName, getParent, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
Methods inherited from class buoy.event.EventSource
addEventLink, addEventLink, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormContainer

public FormContainer(double[] colWeight,
                     double[] rowWeight)
Create a new FormContainer. The number of columns is equal to colWeight.length, and the number of rows is equal to rowWeight.length.

Parameters:
colWeight - the weights of the columns
rowWeight - the weights of the rows

FormContainer

public FormContainer(int numCols,
                     int numRows)
Create a new FormContainer. All of the row and column weights default to 1.0.

Parameters:
numCols - the number of columns
numRows - the number of rows
Method Detail

getComponent

public javax.swing.JPanel getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getChildCount

public int getChildCount()
Get the number of children in this container.

Specified by:
getChildCount in class WidgetContainer

getChild

public Widget getChild(int i)
Get the i'th child of this container.


getChildren

public java.util.Collection<Widget> getChildren()
Get a Collection containing all child Widgets of this container.

Specified by:
getChildren in class WidgetContainer

getRowCount

public int getRowCount()
Get the number of rows in this FormContainer.


getColumnCount

public int getColumnCount()
Get the number of columns in this FormContainer.


setRowCount

public void setRowCount(int rows)
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.


setColumnCount

public void setColumnCount(int columns)
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.


getRowWeight

public double getRowWeight(int row)
Get the weight of a particular row.

Parameters:
row - the index of the row

getColumnWeight

public double getColumnWeight(int col)
Get the weight of a particular column.

Parameters:
col - the index of the column

setRowWeight

public void setRowWeight(int row,
                         double weight)
Set the weight of a particular row.

Parameters:
row - the index of the row
weight - the new weight

setColumnWeight

public void setColumnWeight(int col,
                            double weight)
Set the weight of a particular column.

Parameters:
col - the index of the column
weight - the new weight

layoutChildren

public void layoutChildren()
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.

Specified by:
layoutChildren in class WidgetContainer

add

public void add(Widget widget,
                int col,
                int row)
Add a Widget to this container. The Widget will occupy a single cell, and be positioned using the default LayoutInfo.

Parameters:
widget - the Widget to add
col - the column in which to place the Widget
row - the row in which to place the Widget

add

public void add(Widget widget,
                int col,
                int row,
                LayoutInfo layout)
Add a Widget to this container. The Widget will occupy a single cell.

Parameters:
widget - the Widget to add
col - the column in which to place the Widget
row - the row in which to place the Widget
layout - the LayoutInfo to use for this Widget. If null, the default LayoutInfo will be used.

add

public void add(Widget widget,
                int col,
                int row,
                int width,
                int height)
Add a Widget to this container. The Widget will occupy a rectangular block of cells, and be positioned using the default LayoutInfo.

Parameters:
widget - the Widget to add
col - the first column the Widget will occupy
row - the first row the Widget will occupy
width - the number of columns the Widget will occupy
height - the number of rows the Widget will occupy

add

public void add(Widget widget,
                int col,
                int row,
                int width,
                int height,
                LayoutInfo layout)
Add a Widget to this container. The Widget will occupy a rectangular block of cells.

Parameters:
widget - the Widget to add
col - the first column the Widget will occupy
row - the first row the Widget will occupy
width - the number of columns the Widget will occupy
height - the number of rows the Widget will occupy
layout - the LayoutInfo to use for this Widget. If null, the default LayoutInfo will be used.

getChildLayout

public LayoutInfo getChildLayout(int index)
Get the LayoutInfo for a particular Widget.

Parameters:
index - the index of the Widget for which to get the LayoutInfo
Returns:
the LayoutInfo being used for that Widget. This may return null, which indicates that the default LayoutInfo is being used.

setChildLayout

public void setChildLayout(int index,
                           LayoutInfo layout)
Set the LayoutInfo for a particular Widget.

Parameters:
index - the index of the Widget for which to set the LayoutInfo
layout - the new LayoutInfo. If null, the default LayoutInfo will be used

getChildLayout

public LayoutInfo getChildLayout(Widget widget)
Get the LayoutInfo for a particular Widget.

Parameters:
widget - the Widget for which to get the LayoutInfo
Returns:
the LayoutInfo being used for that Widget. This may return null, which indicates that the default LayoutInfo is being used. It will also return null if the specified Widget is not a child of this container.

setChildLayout

public void setChildLayout(Widget widget,
                           LayoutInfo layout)
Set the LayoutInfo for a particular Widget.

Parameters:
widget - the Widget for which to set the LayoutInfo
layout - the new LayoutInfo. If null, the default LayoutInfo will be used

getDefaultLayout

public LayoutInfo getDefaultLayout()
Get the default LayoutInfo.


setDefaultLayout

public void setDefaultLayout(LayoutInfo layout)
Set the default LayoutInfo.


getChildCells

public java.awt.Rectangle getChildCells(int index)
Get the range of cells occupied by a Widget.

Parameters:
index - the index of the Widget for which to get the cells
Returns:
a Rectangle specifying the range of rows and columns occupied by the Widget

setChildCells

public void setChildCells(int index,
                          java.awt.Rectangle cells)
Set the range of cells occupied by a Widget.

Parameters:
index - the index of the Widget for which to set the cells
cells - a Rectangle specifying the range of rows and columns to be occupied by the Widget

getChildCells

public java.awt.Rectangle getChildCells(Widget widget)
Get the range of cells occupied by a Widget.

Parameters:
widget - the Widget for which to get the cells
Returns:
a Rectangle specifying the range of rows and columns occupied by the Widget, or null if the Widget is not a child of this container

setChildCells

public void setChildCells(Widget widget,
                          java.awt.Rectangle cells)
Set the range of cells occupied by a Widget.

Parameters:
widget - the Widget for which to get the cells
cells - a Rectangle specifying the range of rows and columns to be occupied by the Widget

remove

public void remove(Widget widget)
Remove a child Widget from this container.

Specified by:
remove in class WidgetContainer
Parameters:
widget - the Widget to remove

remove

public void remove(int index)
Remove a child Widget from this container.

Parameters:
index - the index of the Widget to remove

removeAll

public void removeAll()
Remove all child Widgets from this container.

Specified by:
removeAll in class WidgetContainer

getWidgetIndex

public int getWidgetIndex(Widget widget)
Get the index of a particular Widget.

Parameters:
widget - the Widget to locate
Returns:
the position of the Widget within this container

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the smallest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out its contents, it will attempt never to make this Widget smaller than its minimum size.

Overrides:
getMinimumSize in class Widget

getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size at which this Widget will look best. When a WidgetContainer lays out its contents, it will attempt to make this Widget as close as possible to its preferred size.

Overrides:
getPreferredSize in class Widget


Written by Peter Eastman.