buoy.widget
Class BorderContainer

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

public class BorderContainer
extends WidgetContainer

BorderContainer is a WidgetContainer which may have up to five children: one along each edge, and a fifth one in the center. When this container is resized, the center component grows to take up as much space as possible.

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

Author:
Peter Eastman

Nested Class Summary
static class BorderContainer.Position
          This inner class represents a position within the container.
 
Field Summary
static BorderContainer.Position CENTER
           
static BorderContainer.Position EAST
           
static BorderContainer.Position NORTH
           
static BorderContainer.Position SOUTH
           
static BorderContainer.Position WEST
           
 
Constructor Summary
BorderContainer()
          Create a new BorderContainer.
 
Method Summary
 void add(Widget widget, BorderContainer.Position where)
          Add a Widget to this container, using the default LayoutInfo to position it.
 void add(Widget widget, BorderContainer.Position where, LayoutInfo layout)
          Add a Widget to this container.
 Widget getChild(BorderContainer.Position where)
          Get the child in a particular location.
 int getChildCount()
          Get the number of children in this container.
 LayoutInfo getChildLayout(BorderContainer.Position where)
          Get the LayoutInfo for the Widget in a particular location.
 LayoutInfo getChildLayout(Widget widget)
          Get the LayoutInfo for a particular Widget.
 BorderContainer.Position getChildPosition(Widget widget)
          Get the Position of a particular Widget.
 java.util.Collection<Widget> getChildren()
          Get a Collection containing all child Widgets of this container.
 javax.swing.JPanel getComponent()
          Get the java.awt.Component corresponding to this Widget.
 boolean getCornersAreVertical()
          Get whether the vertical Widgets (EAST and WEST) or the horizontal Widgets (NORTH and SOUTH) extend all the way to the corners.
 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.
 void layoutChildren()
          Layout the child Widgets.
 void remove(BorderContainer.Position where)
          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 setChildLayout(BorderContainer.Position where, LayoutInfo layout)
          Set the LayoutInfo for the Widget in a particular location.
 void setChildLayout(Widget widget, LayoutInfo layout)
          Set the LayoutInfo for a particular Widget.
 void setCornersAreVertical(boolean vertical)
          Set whether the vertical Widgets (EAST and WEST) or the horizontal Widgets (NORTH and SOUTH) extend all the way to the corners.
 void setDefaultLayout(LayoutInfo layout)
          Set the default LayoutInfo.
 
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
 

Field Detail

CENTER

public static final BorderContainer.Position CENTER

NORTH

public static final BorderContainer.Position NORTH

EAST

public static final BorderContainer.Position EAST

SOUTH

public static final BorderContainer.Position SOUTH

WEST

public static final BorderContainer.Position WEST
Constructor Detail

BorderContainer

public BorderContainer()
Create a new BorderContainer.

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(BorderContainer.Position where)
Get the child in a particular location.

Parameters:
where - the location of the Widget to get (CENTER, NORTH, EAST, SOUTH, or WEST)

getChildPosition

public BorderContainer.Position getChildPosition(Widget widget)
Get the Position of a particular Widget.

Parameters:
widget - the Widget for which to get the Position
Returns:
the Position at which that Widget is located, or null if the specified Widget is not a child of this container.

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,
                BorderContainer.Position where)
Add a Widget to this container, using the default LayoutInfo to position it.

Parameters:
widget - the Widget to add
where - the location to add it (CENTER, NORTH, EAST, SOUTH, or WEST)

add

public void add(Widget widget,
                BorderContainer.Position where,
                LayoutInfo layout)
Add a Widget to this container.

Parameters:
widget - the Widget to add
where - the location to add it (CENTER, NORTH, EAST, SOUTH, or WEST)
layout - the LayoutInfo to use for this Widget. If null, the default LayoutInfo will be used.

getChildLayout

public LayoutInfo getChildLayout(BorderContainer.Position where)
Get the LayoutInfo for the Widget in a particular location.

Parameters:
where - the location of the Widget (CENTER, NORTH, EAST, SOUTH, or WEST)
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(BorderContainer.Position where,
                           LayoutInfo layout)
Set the LayoutInfo for the Widget in a particular location.

Parameters:
where - the location of the Widget (CENTER, NORTH, EAST, SOUTH, or WEST)
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.


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(BorderContainer.Position where)
Remove a child Widget from this container.

Parameters:
where - the location of the Widget to remove (CENTER, NORTH, EAST, SOUTH, or WEST)

removeAll

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

Specified by:
removeAll in class WidgetContainer

getCornersAreVertical

public boolean getCornersAreVertical()
Get whether the vertical Widgets (EAST and WEST) or the horizontal Widgets (NORTH and SOUTH) extend all the way to the corners.


setCornersAreVertical

public void setCornersAreVertical(boolean vertical)
Set whether the vertical Widgets (EAST and WEST) or the horizontal Widgets (NORTH and SOUTH) extend all the way to the corners.


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.