edu.neu.ccs.gui
Class CenterLayout

java.lang.Object
  extended byedu.neu.ccs.gui.CenterLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class CenterLayout
extends Object
implements LayoutManager2

Layout that maintains a single component in the absolute center of the parent container.

This class is based on code posted by sapex to a Java Developer Connection forum on 21 June 2000. The JDC forums are available by following the link below.

Since:
1.0
Version:
2.2
See Also:
JDC forums


Field Summary
private  Component c
          The component to be maintained by this layout.
 
Constructor Summary
CenterLayout()
          Constructs a new center layout.
 
Method Summary
 void addLayoutComponent(Component component, Object constraints)
          Adds the given component to the layout by replacing the currently contained component with the given component.
 void addLayoutComponent(String name, Component component)
          Adds the given component to the layout.
 float getLayoutAlignmentX(Container target)
          Returns the layout alignment along the x-axis.
 float getLayoutAlignmentY(Container target)
          Returns the layout alignment along the y-axis.
 void invalidateLayout(Container target)
          Invalidates the layout.
 void layoutContainer(Container parent)
          Lays out the parent container by setting the bounds of the component it contains.
 Dimension maximumLayoutSize(Container parent)
          Returns the maximum size for the parent container given the maximum size of the contained component.
 Dimension minimumLayoutSize(Container parent)
          Returns the minimum size for the parent container given the minimum size of the contained component.
 Dimension preferredLayoutSize(Container parent)
          Returns the preferred size for the parent container given the preferred size of the contained component.
 void removeLayoutComponent(Component component)
          Removes the given component from the layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c

private Component c
The component to be maintained by this layout.

Constructor Detail

CenterLayout

public CenterLayout()
Constructs a new center layout.

Method Detail

addLayoutComponent

public void addLayoutComponent(String name,
                               Component component)
Adds the given component to the layout.

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - the name for this component (ignored)
component - the component to be maintained by this layout.
See Also:
addLayoutComponent(Component, Object)

addLayoutComponent

public void addLayoutComponent(Component component,
                               Object constraints)
Adds the given component to the layout by replacing the currently contained component with the given component.

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
component - the component to be maintained by this layout.
constraints - the constraints affecting this component in the layout (ignored)
See Also:
addLayoutComponent(String, Component)

removeLayoutComponent

public void removeLayoutComponent(Component component)
Removes the given component from the layout. If the given component is not the one currently maintained by this layout, no change is made.

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
component - the component to remove from this layout

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Returns the minimum size for the parent container given the minimum size of the contained component. If the layout does not contain a component, the minimum size is a Dimension with zero width and height.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - the parent container using this layout

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Returns the preferred size for the parent container given the preferred size of the contained component. If the layout does not contain a component, the preferred size is a Dimension with zero width and height.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - the parent container using this layout

maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)
Returns the maximum size for the parent container given the maximum size of the contained component. If the layout does not contain a component, the maximum size is a Dimension with the maximum possible width and height.

Specified by:
maximumLayoutSize in interface LayoutManager2
Parameters:
parent - the parent container using this layout

layoutContainer

public void layoutContainer(Container parent)
Lays out the parent container by setting the bounds of the component it contains.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent - the parent container using this layout

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Returns the layout alignment along the y-axis.

Specified by:
getLayoutAlignmentY in interface LayoutManager2
Parameters:
target - the target container for this layout

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Returns the layout alignment along the x-axis.

Specified by:
getLayoutAlignmentX in interface LayoutManager2
Parameters:
target - the target container for this layout

invalidateLayout

public void invalidateLayout(Container target)
Invalidates the layout. This implementation does nothing.

Specified by:
invalidateLayout in interface LayoutManager2
Parameters:
target - the target container for this layout