gov.nasa.gsfc.drl.rtstps.library.layout
Class ListLayout

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.library.layout.ListLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

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

This class is a layout manager. It arranges components in a vertical list similar to a vertical Box. Unlike boxes and BoxLayout however, you may specify vertical gaps and indentations. It also grows and shrinks differently.

You may set a vertical gap, which is a mandatory spacing between components. The default is 0 pixels.

You may add an indentation as a constraint (Integer(pixels)) when you add a component to a container. ListLayout will then indent the component from the left margin. ListLayout contains a static TAB=20 pixels and TABTAB=40 for your convenience.

If you do not add glue to the container, then each component is given a cell that is proportional to its preferred size. It grows to fill its cell unless the cell is larger than the component's maximum size. In that case, the manager uses its own x and y alignments (not the component's) to place the component within the cell. By default, components are vertically centered and left-justified. (x-alignment = 0f, y-alignment = 0.5f)

You may add Box's filler components. If you add glue, then the glue grabs all extra space, and components grow no bigger than their preferred sizes.

 Integer tab = new Integer(10); //10 pixels indentation
 Integer tab1 = new Integer(25); //25 pixels indentation
 int gap = 5;
 JPanel jp = new JPanel(new ListLayout(gap));
 jp.add(comp1);  //no indentation
 jp.add(comp2, tab);
 jp.add(comp2, tab2);
 jp.add(comp2, ListLayout.TAB);
 jp.add(Box.createGlue());
 

See Also:
Serialized Form

Field Summary
private  float _alignX
           
private  float _alignY
           
private  java.util.Vector<java.awt.Component> _comp
           
private  int _gap
           
private  int _glues
           
private  java.util.Vector<java.lang.Integer> _indentation
           
private  java.awt.Insets _insets
           
private  int _maxLayoutHeight
           
private  int _maxLayoutWidth
           
private  int _minLayoutHeight
           
private  int _minLayoutWidth
          These layout values do not include gaps and insets.
private  int _prefLayoutHeight
           
private  int _prefLayoutWidth
           
private  boolean _valid
           
private static java.lang.Integer GLUE
           
private static long serialVersionUID
           
static java.lang.Integer TAB
          A default indentation.
static java.lang.Integer TABTAB
          A default indentation.
private static java.lang.Integer ZERO
           
 
Constructor Summary
ListLayout()
          Create a ListLayout object.
ListLayout(int vgap)
          Create a ListLayout object.
 
Method Summary
private  int addHorizontalBaggage(int width, java.awt.Insets insets)
           
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraint)
          Add a component to the layout.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Add a component to the layout.
private  int addVerticalBaggage(int height, java.awt.Insets insets)
           
 float getLayoutAlignmentX(java.awt.Container parent)
          Get the X alignment.
 float getLayoutAlignmentY(java.awt.Container parent)
          Get the Y alignment.
 void invalidateLayout(java.awt.Container parent)
          Invalidate the layout.
 void layoutContainer(java.awt.Container parent)
          Lay out the components in the container.
private  void locateInCell(java.awt.Component comp, java.awt.Rectangle r)
           
 java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
          Get the maximum layout size.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Get the minimum layout size.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Get the preferred layout size.
 void removeLayoutComponent(java.awt.Component comp)
          Remove a component from the layout.
 void setGap(int gap)
          Set a gap between components.
 void setInsets(java.awt.Insets in)
          Set a blank border.
 void setLayoutAlignmentX(float a)
          Set the X alignment.
 void setLayoutAlignmentY(float a)
          Set the Y alignment.
private  void validate(java.awt.Container parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAB

public static final java.lang.Integer TAB
A default indentation. Use it as a constraint argument.


TABTAB

public static final java.lang.Integer TABTAB
A default indentation. Use it as a constraint argument.


ZERO

private static final java.lang.Integer ZERO

GLUE

private static final java.lang.Integer GLUE

_indentation

private java.util.Vector<java.lang.Integer> _indentation

_comp

private java.util.Vector<java.awt.Component> _comp

_insets

private java.awt.Insets _insets

_glues

private int _glues

_gap

private int _gap

_alignX

private float _alignX

_alignY

private float _alignY

_valid

private boolean _valid

_minLayoutWidth

private int _minLayoutWidth
These layout values do not include gaps and insets.


_maxLayoutWidth

private int _maxLayoutWidth

_prefLayoutWidth

private int _prefLayoutWidth

_minLayoutHeight

private int _minLayoutHeight

_maxLayoutHeight

private int _maxLayoutHeight

_prefLayoutHeight

private int _prefLayoutHeight

serialVersionUID

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

ListLayout

public ListLayout(int vgap)
Create a ListLayout object.

Parameters:
vgap - Gap in pixels between components. The gap does not affect the border. The default is 0 pixels.

ListLayout

public ListLayout()
Create a ListLayout object. There are no gaps between components.

Method Detail

setGap

public final void setGap(int gap)
Set a gap between components. The gap does not affect the border.


setInsets

public final void setInsets(java.awt.Insets in)
Set a blank border.


setLayoutAlignmentX

public final void setLayoutAlignmentX(float a)
Set the X alignment. The default value is 0.0, which causes the components to left justified.


setLayoutAlignmentY

public final void setLayoutAlignmentY(float a)
Set the Y alignment. The default value is 0.5, which causes the components to centered.


getLayoutAlignmentX

public final float getLayoutAlignmentX(java.awt.Container parent)
Get the X alignment.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public final float getLayoutAlignmentY(java.awt.Container parent)
Get the Y alignment.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

invalidateLayout

public final void invalidateLayout(java.awt.Container parent)
Invalidate the layout.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Add a component to the layout. ListLayout does not support this method.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Remove a component from the layout. ListLayout ignores this method.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraint)
Add a component to the layout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - The component to be added to the layout.
constraint - This object identifies the indentation. It may be null, in which case there is no indentation. Otherwise, it must be of type Integer, and it is the indentation in pixels. If the component is a Box filler type (glue, for example), the constraint is ignored.

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lay out the components in the container.

Specified by:
layoutContainer in interface java.awt.LayoutManager

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Get the minimum layout size.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Get the preferred layout size.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

maximumLayoutSize

public final java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
Get the maximum layout size.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2

validate

private void validate(java.awt.Container parent)

addHorizontalBaggage

private int addHorizontalBaggage(int width,
                                 java.awt.Insets insets)

addVerticalBaggage

private int addVerticalBaggage(int height,
                               java.awt.Insets insets)

locateInCell

private void locateInCell(java.awt.Component comp,
                          java.awt.Rectangle r)