Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

org.bounce
Class CenterLayout

java.lang.Object
  extended by org.bounce.CenterLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2

public class CenterLayout
extends java.lang.Object
implements java.awt.LayoutManager2

A Layout manager that can be used to layout 3 components, one component in the center that does not resize, and a component on either side that take up the rest of the available space. The orientation can be Vertical or Horizontal.

Version:
$Revision: 1.5 $, $Date: 2008/01/28 21:28:37 $
Author:
Edwin Dankert

Field Summary
static java.lang.String BOTTOM
          A constraint that adds the component to the right/bottom.
static java.lang.String CENTER
          A constraint that adds the component to the center.
static int HORIZONTAL
          Sets the layout orientation to horizontal.
static java.lang.String LEFT
          A constraint that adds the component to the left/top.
static java.lang.String RIGHT
          A constraint that adds the component to the right/bottom.
static java.lang.String TOP
          A constraint that adds the component to the left/top.
static int VERTICAL
          Sets the layout orientation to vertical.
 
Constructor Summary
CenterLayout()
          Constructs a default CenterLayout without a gap and with a horizontal orientation.
CenterLayout(int orientation)
          Constructs a CenterLayout with the orientation supplied and with no gap between the components.
CenterLayout(int orientation, int gap)
          Constructs a CenterLayout with the gap and orientation supplied.
 
Method Summary
 void addLayoutComponent(java.awt.Component component, java.lang.Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Not used, components cannot be added without a constraint.
 int getGap()
          Returns the gap between the components.
 float getLayoutAlignmentX(java.awt.Container target)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(java.awt.Container target)
          Returns the alignment along the y axis.
 int getOrientation()
          Returns the orientation of the layout manager.
 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 parent)
          Lays out the components on the specified container.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum size of this component.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Calculates the preferred size dimensions for the specified container given the components in the specified parent container.
 void removeLayoutComponent(java.awt.Component component)
          Removes the specified component and constraints from the layout.
 void setConstraints(java.awt.Component component, java.lang.Object constraint)
          Adds the specified component to the layout, using the specified constraint object.
 void setGap(int gap)
          Sets the gap between the components.
 void setOrientation(int orientation)
          Sets the orientation of the layout manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final java.lang.String CENTER
A constraint that adds the component to the center.

See Also:
Constant Field Values

TOP

public static final java.lang.String TOP
A constraint that adds the component to the left/top.

See Also:
Constant Field Values

LEFT

public static final java.lang.String LEFT
A constraint that adds the component to the left/top.

See Also:
Constant Field Values

BOTTOM

public static final java.lang.String BOTTOM
A constraint that adds the component to the right/bottom.

See Also:
Constant Field Values

RIGHT

public static final java.lang.String RIGHT
A constraint that adds the component to the right/bottom.

See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
Sets the layout orientation to horizontal.

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
Sets the layout orientation to vertical.

See Also:
Constant Field Values
Constructor Detail

CenterLayout

public CenterLayout()
Constructs a default CenterLayout without a gap and with a horizontal orientation.


CenterLayout

public CenterLayout(int orientation)
Constructs a CenterLayout with the orientation supplied and with no gap between the components.

Parameters:
orientation - the orientation of the components.

CenterLayout

public CenterLayout(int orientation,
                    int gap)
Constructs a CenterLayout with the gap and orientation supplied.

Parameters:
orientation - the orientation of the components.
gap - the space between the components.
Method Detail

getGap

public int getGap()
Returns the gap between the components.

Returns:
the gap.

setGap

public void setGap(int gap)
Sets the gap between the components.

Parameters:
gap - the gap.

getOrientation

public int getOrientation()
Returns the orientation of the layout manager.

Returns:
the orientation.

setOrientation

public void setOrientation(int orientation)
Sets the orientation of the layout manager.

Parameters:
orientation - the orientation.

setConstraints

public void setConstraints(java.awt.Component component,
                           java.lang.Object constraint)
Adds the specified component to the layout, using the specified constraint object. For a Center layout, the constraint must be an instance of a String.

Parameters:
component - the component added to the parent container.
constraint - the constraint for the added component.

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component component)
Removes the specified component and constraints from the layout.

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

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Calculates the preferred size dimensions for the specified container given the components in the specified parent container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the component to be laid out.
Returns:
the preferred size of the layout.

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Calculates the minimum size dimensions for the specified panel given the components in the specified parent container.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the component to be laid out
Returns:
the minimum size of the layout.

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the components on the specified container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - the component which needs to be laid out

addLayoutComponent

public void addLayoutComponent(java.awt.Component component,
                               java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
component - the component to be added
constraints - where/how the component is added to the layout.

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum size of this component.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - the container to calculate the maximum size for.
Returns:
the maximum size.
See Also:
Component.getMinimumSize(), Component.getPreferredSize()

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container target)
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:
target - the container to calculate X alignment for.
Returns:
the X alignment.

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container target)
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:
target - the container to calculate Y alignment for.
Returns:
the Y 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 - the container.

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Not used, components cannot be added without a constraint.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - the component name.
comp - the component.

Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

Copyright 2002-2002-2009 Edwin Dankert. All Rights Reserved.