org.openbp.swing.layout.dock
Class DockLayout

java.lang.Object
  extended by org.openbp.swing.layout.dock.DockLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public class DockLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

The flexible border layout is a layout manager that is similar to the BorderLayout, but allows dynamic resizing of the components and adjusting the main orientation of the components. Is also serves as base class for more advance layout managers like the DockLayout The flexible border layout lays out a container, arranging and resizing its components to fit in five regions: North, south, east, west, and center. Each component is optional, so layouts consisting of i. e. only a east, west and center component are possible. The orientation (property setHorizontalOrder(boolean)) determines how the components will be arranged in the container. horizontalOrder = true:
The north and south components have the same width as the center component. The component arrangement appears rather horizontally ordered.

See Also:
Serialized Form

Field Summary
static java.lang.String STR_BOTTOM
          Alternative shorthand string constraing of south component (bottom of container).
static java.lang.String STR_CENTER
          Shorthand string constraing of center component (middle of container).
static java.lang.String STR_EAST
          Shorthand string constraing of east component (right side of container).
static java.lang.String STR_LEFT
          Alternative shorthand string constraing of west component (left side of container).
static java.lang.String STR_NORTH
          Shorthand string constraing of north component (top of container).
static java.lang.String STR_RIGHT
          Alternative shorthand string constraing of east component (right side of container).
static java.lang.String STR_SOUTH
          Shorthand string constraing of south component (bottom of container).
static java.lang.String STR_TOP
          Alternative shorthand string constraing of north component (top of container).
static java.lang.String STR_WEST
          Shorthand string constraing of west component (left side of container).
 
Constructor Summary
DockLayout()
          Constructs a new dock layout with no gaps between components.
DockLayout(int horizontalGap, int verticalGap)
          Constructs a dock layout with the specified gaps between components.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void addLayoutComponent(java.lang.String constraint, java.awt.Component comp)
          Deprecated. replaced by addLayoutComponent(Component,Object)
protected  java.awt.Component getComponent(int index)
          Gets the component that corresponds to the given index if it is visible.
 int getHgap()
          Returns the horizontal gap between components.
 boolean getHorizontalOrder()
          Gets the main order of the components.
 float getLayoutAlignmentX(java.awt.Container parent)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(java.awt.Container parent)
          Returns the alignment along the y axis.
 int getVgap()
          Returns the vertical gap between components.
 void invalidateLayout(java.awt.Container target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void layoutContainer(java.awt.Container target)
          Lays out the container argument using this dock layout.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum dimensions for this layout given the components in the specified target container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Determines the minimum size of the target container using this layout manager.
 java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Determines the preferred size of the target container using this layout manager, based on the components in the container.
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from this dock layout.
 void setHgap(int horizontalGap)
          Sets the horizontal gap between components.
 void setHorizontalOrder(boolean horizontalOrder)
          Sets the main order of the components.
 void setVgap(int verticalGap)
          Sets the vertical gap between components.
protected  int stringConstraintToIndex(java.lang.String constraint)
          Gets the component array index that corresponds to a given constraint shortcut.
 java.lang.String toString()
          Returns a string representation of the state of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STR_CENTER

public static final java.lang.String STR_CENTER
Shorthand string constraing of center component (middle of container).

See Also:
Constant Field Values

STR_NORTH

public static final java.lang.String STR_NORTH
Shorthand string constraing of north component (top of container).

See Also:
Constant Field Values

STR_SOUTH

public static final java.lang.String STR_SOUTH
Shorthand string constraing of south component (bottom of container).

See Also:
Constant Field Values

STR_EAST

public static final java.lang.String STR_EAST
Shorthand string constraing of east component (right side of container).

See Also:
Constant Field Values

STR_WEST

public static final java.lang.String STR_WEST
Shorthand string constraing of west component (left side of container).

See Also:
Constant Field Values

STR_TOP

public static final java.lang.String STR_TOP
Alternative shorthand string constraing of north component (top of container).

See Also:
Constant Field Values

STR_BOTTOM

public static final java.lang.String STR_BOTTOM
Alternative shorthand string constraing of south component (bottom of container).

See Also:
Constant Field Values

STR_RIGHT

public static final java.lang.String STR_RIGHT
Alternative shorthand string constraing of east component (right side of container).

See Also:
Constant Field Values

STR_LEFT

public static final java.lang.String STR_LEFT
Alternative shorthand string constraing of west component (left side of container).

See Also:
Constant Field Values
Constructor Detail

DockLayout

public DockLayout()
Constructs a new dock layout with no gaps between components.


DockLayout

public DockLayout(int horizontalGap,
                  int verticalGap)
Constructs a dock layout with the specified gaps between components. The horizontal gap is specified by hgap and the vertical gap is specified by vgap.

Parameters:
horizontalGap - the horizontal gap
verticalGap - the vertical gap
Method Detail

getHorizontalOrder

public boolean getHorizontalOrder()
Gets the main order of the components.

Returns:
true The components appear horizontally ordered.
false The components appear vertically ordered.

setHorizontalOrder

public void setHorizontalOrder(boolean horizontalOrder)
Sets the main order of the components.

Parameters:
horizontalOrder - true The components appear horizontally ordered.
false The components appear vertically ordered.

getHgap

public int getHgap()
Returns the horizontal gap between components.


setHgap

public void setHgap(int horizontalGap)
Sets the horizontal gap between components.


getVgap

public int getVgap()
Returns the vertical gap between components.


setVgap

public void setVgap(int verticalGap)
Sets the vertical gap between components.


addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object. Most applications do not call this method directly. This method is called when a component is added to a container using the Container.add method with the same argument types.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - Component to be added
constraints - Object that specifies how and where the component is added to the layout.
Throws:
java.lang.IllegalArgumentException - if the constraint object is not a string, or if it is not one of the five specified constants.

addLayoutComponent

public void addLayoutComponent(java.lang.String constraint,
                               java.awt.Component comp)
Deprecated. replaced by addLayoutComponent(Component,Object)

Adds the specified component with the specified constraint to the layout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
constraint - Component constraint
comp - Component to be added

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from this dock layout. This method is called when a container calls its remove or removeAll methods. Most applications do not call this method directly.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
comp - Component to be removed

layoutContainer

public void layoutContainer(java.awt.Container target)
Lays out the container argument using this dock layout. This method actually reshapes the components in the specified container in order to satisfy the constraints of this DockLayout object. The NORTH and SOUTH components, if any, are placed at the top and bottom of the container, respectively. The WEST and EAST components are then placed on the left and right, respectively. Finally, the CENTER object is placed in any remaining space in the middle. Most applications do not call this method directly. This method is called when a container calls its doLayout method.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
target - Container in which to do the layout

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Determines the preferred size of the target container using this layout manager, based on the components in the container. Most applications do not call this method directly. This method is called when a container calls its getPreferredSize method.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
target - Container in which to do the layout
Returns:
Preferred dimensions to lay out the subcomponents of the specified container

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Determines the minimum size of the target container using this layout manager. This method is called when a container calls its getMinimumSize method. Most applications do not call this method directly.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
target - Container in which to do the layout
Returns:
Minimum dimensions needed to lay out the subcomponents of the specified container

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. This method is called when a container calls its getMaximumSize method. Most applications do not call this method directly.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - Component which needs to be laid out
Returns:
Maximum dimensions needed to lay out the subcomponents of the specified container

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Parameters:
parent - Container the layout has been applied to
Returns:
This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Parameters:
parent - Container the layout has been applied to
Returns:
This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2
Parameters:
target - Container the layout has been applied to

getComponent

protected java.awt.Component getComponent(int index)
Gets the component that corresponds to the given index if it is visible.

Parameters:
index - Index into component child array or null
Returns:
The component or null if the component is not visible

stringConstraintToIndex

protected int stringConstraintToIndex(java.lang.String constraint)
Gets the component array index that corresponds to a given constraint shortcut.

Parameters:
constraint - String constraing ("North", "Bottom", "Center" etc.)
Returns:
Index value (INDEX_CENTER/INDEX_NORTH/INDEX_SOUTH/INDEX_EAST/INDEX_WEST)

toString

public java.lang.String toString()
Returns a string representation of the state of this object.

Overrides:
toString in class java.lang.Object


Copyright © 2011. All Rights Reserved.