buoy.widget
Class GridContainer

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

public class GridContainer
extends WidgetContainer

GridContainer is a WidgetContainer which arranges its child Widgets in a uniform grid. Every column is the same width, and every row is the same height.

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

Author:
Peter Eastman

Constructor Summary
GridContainer(int cols, int rows)
          Create a new GridContainer.
 
Method Summary
 void add(Widget widget, int col, int row)
          Add a Widget to this container, using the default LayoutInfo to position it.
 void add(Widget widget, int col, int row, LayoutInfo layout)
          Add a Widget to this container.
 Widget getChild(int col, int row)
          Get the child in a particular cell.
 java.awt.Point getChildCell(Widget widget)
          Get the cell containing the specified Widget.
 int getChildCount()
          Get the number of children in this container.
 LayoutInfo getChildLayout(int col, int row)
          Get the LayoutInfo for the Widget in a particular cell.
 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 the grid.
 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 the grid.
 void layoutChildren()
          Layout the child Widgets.
 void remove(int col, int row)
          Remove the Widget in a particular cell from this container.
 void remove(Widget widget)
          Remove a child Widget from this container.
 void removeAll()
          Remove all child Widgets from this container.
 void setChildLayout(int col, int row, LayoutInfo layout)
          Set the LayoutInfo for the Widget in a particular cell.
 void setChildLayout(Widget widget, LayoutInfo layout)
          Set the LayoutInfo for a particular Widget.
 void setColumnCount(int cols)
          Set the number of columns in the grid.
 void setDefaultLayout(LayoutInfo layout)
          Set the default LayoutInfo.
 void setRowCount(int rows)
          Set the number of rows in the grid.
 
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

GridContainer

public GridContainer(int cols,
                     int rows)
Create a new GridContainer.

Parameters:
cols - the number of columns in the grid
rows - the number of rows in the grid
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

getChildren

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

Specified by:
getChildren in class WidgetContainer

getChild

public Widget getChild(int col,
                       int row)
Get the child in a particular cell.

Parameters:
col - the column for which to get the Widget
row - the row for which to get the Widget
Returns:
the Widget in the specified cell

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, using the default LayoutInfo to position it. If there is already a Widget in the specified cell, that one will be removed before the new one is added.

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. If there is already a Widget in the specified cell, that one will be removed before the new one is added.

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.

getChildLayout

public LayoutInfo getChildLayout(int col,
                                 int row)
Get the LayoutInfo for the Widget in a particular cell.

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

setChildLayout

public void setChildLayout(int col,
                           int row,
                           LayoutInfo layout)
Set the LayoutInfo for the Widget in a particular cell.

Parameters:
col - the column of the Widget for which to set the LayoutInfo
row - the row 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.


getRowCount

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


setRowCount

public void setRowCount(int rows)
Set the number of rows in the grid. If this causes the grid to shrink, all Widgets which do not fit into the new grid will be removed.


getColumnCount

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


setColumnCount

public void setColumnCount(int cols)
Set the number of columns in the grid. If this causes the grid to shrink, all Widgets which do not fit into the new grid will be removed.


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 col,
                   int row)
Remove the Widget in a particular cell from this container.

Parameters:
col - the column from which to remove the Widget
row - the row from which to remove the Widget

removeAll

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

Specified by:
removeAll in class WidgetContainer

getChildCell

public java.awt.Point getChildCell(Widget widget)
Get the cell containing the specified Widget.

Parameters:
widget - the Widget to locate
Returns:
a Point containing the row and column where the Widget is located, or null if the Widget is not a child of the 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.