bb.gui
Class CenterLayout

java.lang.Object
  extended by bb.gui.CenterLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class CenterLayout
extends Object
implements LayoutManager, LayoutManager2, Serializable

This LayoutManager always draws each Component centered inside the target Container, and at its preferred size. Here, "centered" means that the Component's bounding rectangle's center is the same as the center of the Container.

Typically, this LayoutManager will be used for Containers which have only a single Component inside, because multiple Components will get drawn over each other. But if overdrawing is satisfactory or desired, then this LayoutManager is also suitable for Containers with multiple Components inside.

Like typical java gui code, this class is not multithread safe: it expects to only be called by EventQueue's dispatch thread.

Author:
Brent Boyer
See Also:
Serialized Form

Nested Class Summary
static class CenterLayout.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private static long serialVersionUID
           
 
Constructor Summary
CenterLayout()
          Creates a new CenterLayout instance.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Not used by this class (is implemented as an empty method).
 void addLayoutComponent(String name, Component comp)
          Not used by this class (is implemented as an empty method).
 float getLayoutAlignmentX(Container target)
          Returns the alignment along the X axis for the Container.
 float getLayoutAlignmentY(Container target)
          Returns the alignment along the Y axis for the Container.
 void invalidateLayout(Container target)
          Not used by this class (is implemented as an empty method).
 void layoutContainer(Container target)
          Called by the AWT when the specified Container needs to be laid out.
 Dimension maximumLayoutSize(Container target)
          Returns target.getMaximumSize().
 Dimension minimumLayoutSize(Container target)
          Returns the minimum dimensions needed to lay out the components contained in target.
 Dimension preferredLayoutSize(Container target)
          Returns the preferred dimensions needed to lay out the components contained in target.
 void removeLayoutComponent(Component comp)
          Not used by this class (is implemented as an empty method).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

CenterLayout

public CenterLayout()
Creates a new CenterLayout instance.

Method Detail

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Returns the alignment along the X axis for the Container.

Specified by:
getLayoutAlignmentX in interface LayoutManager2
Parameters:
target - a Container
Returns:
the alignment (a value >= 0.0f && <= 1.0f)

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Returns the alignment along the Y axis for the Container.

Specified by:
getLayoutAlignmentY in interface LayoutManager2
Parameters:
target - a Container
Returns:
the alignment (a value >= 0.0f && <= 1.0f)

minimumLayoutSize

public Dimension minimumLayoutSize(Container target)
Returns the minimum dimensions needed to lay out the components contained in target. Invisible child Components are ignored in the calculation. The result includes the effects of the target container's insets.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
target - the Container that needs to be laid out
Returns:
a new Dimension instance (both the height and width are >= 0 && <= Integer.MAX_VALUE)
See Also:
preferredLayoutSize(java.awt.Container), maximumLayoutSize(java.awt.Container)

preferredLayoutSize

public Dimension preferredLayoutSize(Container target)
Returns the preferred dimensions needed to lay out the components contained in target. Invisible child Components are ignored in the calculation. The result includes the effects of the target container's insets.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
target - the Container that needs to be laid out
Returns:
a new Dimension instance (both the height and width are >= 0 && <= Integer.MAX_VALUE)
See Also:
minimumLayoutSize(java.awt.Container), maximumLayoutSize(java.awt.Container)

maximumLayoutSize

public Dimension maximumLayoutSize(Container target)
Returns target.getMaximumSize().

Specified by:
maximumLayoutSize in interface LayoutManager2
Parameters:
target - the Container that needs to be laid out
Returns:
a new Dimension instance (both the height and width are >= 0 && <= Integer.MAX_VALUE)
See Also:
minimumLayoutSize(java.awt.Container), preferredLayoutSize(java.awt.Container)

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Not used by this class (is implemented as an empty method).

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - the name of the component
comp - the component

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Not used by this class (is implemented as an empty method).

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
comp - the component
constraints - constraints

invalidateLayout

public void invalidateLayout(Container target)
Not used by this class (is implemented as an empty method).

Specified by:
invalidateLayout in interface LayoutManager2
Parameters:
target - the affected container

layoutContainer

public void layoutContainer(Container target)
Called by the AWT when the specified Container needs to be laid out.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
target - the container to lay out

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Not used by this class (is implemented as an empty method).

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
comp - the component