org.openbp.swing.layout
Class UnitLayout

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

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

Layout manager for a container that contains a single object. The object may be vertically and/or horizontally aligned/centered.

Author:
Heiko Erhardt
See Also:
Serialized Form

Field Summary
static int BOTTOM
          Align with bottom of container
static int CENTER
          Center in container
static int LEFT
          Align with left edge of container
static int RIGHT
          Align with right edge of container
static int TOP
          Align with top of container
protected  int xpos
          Horizontal alignment
protected  int ypos
          Vertical alignment
 
Constructor Summary
UnitLayout()
          Default constructor.
UnitLayout(int xpos, int ypos)
          Default constructor.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Add the specified component from the layout.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Deprecated. replaced by addLayoutComponent(Component, Object)
 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.
 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 container)
          Lays out the specified container using this layout.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum dimensions for this layout given the component in the specified target container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container container)
          Calculates the minimum size for the specified page.
 java.awt.Dimension preferredLayoutSize(java.awt.Container container)
          Calculates the preferred size for the specified container.
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from the layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP

public static final int TOP
Align with top of container

See Also:
Constant Field Values

LEFT

public static final int LEFT
Align with left edge of container

See Also:
Constant Field Values

CENTER

public static final int CENTER
Center in container

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Align with right edge of container

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Align with bottom of container

See Also:
Constant Field Values

xpos

protected int xpos
Horizontal alignment


ypos

protected int ypos
Vertical alignment

Constructor Detail

UnitLayout

public UnitLayout()
Default constructor. Centers the component vertically and horizontally.


UnitLayout

public UnitLayout(int xpos,
                  int ypos)
Default constructor.

Parameters:
xpos - Horizontal alignment of the component (LEFT/CENTER/RIGHT)
ypos - Vertical alignment of the component (TOP/CENTER/BOTTOM)
Method Detail

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraints)
Add the specified component from the layout. By default, we let the Container handle this directly.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - The component to be added
constraints - The constraints to apply when laying out

addLayoutComponent

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

Not used.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout. By default, we let the Container handle this directly.

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

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container container)
Calculates the minimum size for the specified page.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
container - The name of the parent container
Returns:
minimum dimensions required to lay out the components

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the component in the specified target container.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - The component which needs to be laid out

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container container)
Calculates the preferred size for the specified container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
container - The name of the parent container
Returns:
minimum dimensions required to lay out the components

layoutContainer

public void layoutContainer(java.awt.Container container)
Lays out the specified container using this layout.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
container - Container that owns the layout

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. 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.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Parameters:
parent - Container that owns the layout
Returns:
The alignment

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. 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.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Parameters:
parent - Container that owns the layout
Returns:
The alignment

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 that owns the layout


Copyright © 2011. All Rights Reserved.