edu.neu.ccs.gui
Class AlignedLayout

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

public class AlignedLayout
extends Object
implements LayoutManager2, JPTConstants

Layout that maintains a single component in a justified position within the parent container. This class is a more general replacement for the CenterLayout class introduced in JPT v1.0.1.

Since:
1.1
Version:
2.2
See Also:
CenterLayout

Field Summary
protected  int alignment
          Alignment for this layout.
protected  Component c
          Component to be maintained by this layout.
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
AlignedLayout()
          Constructs a layout using southwest alignment.
AlignedLayout(int alignment)
          Constructs a layout using the given alignment.
 
Method Summary
 void addLayoutComponent(Component component, Object constraints)
          Adds the given component to the layout by replacing the currently maintained component with the given component.
 void addLayoutComponent(String name, Component component)
          Adds the given component to the layout.
protected  Point applyAlignment(Dimension cSize, Dimension pSize, Point origin)
          Returns the point at which a component of the given size should be located within its parent of the given size, translated by the given origin point.
 int getAlignment()
          Returns the alignment for this 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 this 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.
 void setAlignment(int align)
          Sets the alignment for this layout to the alignment represented by the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c

protected Component c
Component to be maintained by this layout.


alignment

protected int alignment
Alignment for this layout.

Constructor Detail

AlignedLayout

public AlignedLayout()
Constructs a layout using southwest alignment.

See Also:
AlignedLayout(int)

AlignedLayout

public AlignedLayout(int alignment)
Constructs a layout using the given alignment.

Parameters:
alignment - the alignment for this layout
See Also:
AlignedLayout(), JPTConstants.DEFAULT
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 maintained component with the given component. If the given component is null, the currently maintained component is removed.

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
See Also:
maximumLayoutSize(Container), preferredLayoutSize(Container)

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
See Also:
maximumLayoutSize(Container), minimumLayoutSize(Container)

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
See Also:
minimumLayoutSize(Container), preferredLayoutSize(Container)

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
See Also:
getLayoutAlignmentX(Container)

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
See Also:
getLayoutAlignmentY(Container)

invalidateLayout

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

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

setAlignment

public void setAlignment(int align)
Sets the alignment for this layout to the alignment represented by the given value.

Parameters:
align - the alignment for this layout
See Also:
getAlignment(), JPTConstants.DEFAULT

getAlignment

public int getAlignment()
Returns the alignment for this layout.

See Also:
setAlignment(int)

applyAlignment

protected Point applyAlignment(Dimension cSize,
                               Dimension pSize,
                               Point origin)
Returns the point at which a component of the given size should be located within its parent of the given size, translated by the given origin point.

Parameters:
cSize - the size of the component to locate
pSize - the size of the parent component
origin - the point of origin for translation