ColumnLayoutpublic class ColumnLayout extends Object implements LayoutManager
ColumnLayout, a Columnar Layout Manager for AWT/Swing.
Sort of a cross between BoxLayout and GridLayout(0, x).
Displays components in a single row or column based on the
alignment given to the constructor, with optional padding.
There is a utility method for adding space between the previous
and next components, which (like Menu.addSeparator()) adds a
fixed-size non-visible component between two added components.
Note: The current version of ColumnLayout doesn't resize. |
Fields Summary |
---|
public static final int | X_AXISConstant for X AXIS (horizontal column) alignment | public static final int | Y_AXISConstant for Y AXIS (vertical column) alignment | protected final int | alignmentThe alignment for this ColumnLayout | protected final int | hPaddingThe X padding for this ColumnLayout | protected final int | vPaddingThe Y padding for this ColumnLayout | protected int | minwThe minimum width of each component | protected int | minhThe minimum height of each component | Component[] | curCompsThe list of components |
Constructors Summary |
---|
public ColumnLayout(int dirn)Construct a ColumnLayout given only an alignment.
this(dirn, 0, 0);
| public ColumnLayout(int dirn, int pad)Construct a ColumnLayout given an alignment and a padding amount.
this(dirn, pad, pad);
| public ColumnLayout(int dirn, int hpad, int vpad)Construct a ColumnLayout given an alignment and h,v padding amounts.
alignment = dirn;
hPadding = hpad;
vPadding = vpad;
|
Methods Summary |
---|
public void | addLayoutComponent(java.lang.String name, java.awt.Component c)Called by AWT when the user uses the form add(name, Component).
Adds the specified component with the specified name to the layout.
Not necessary to use this form.
System.err.println("don't use add(component,name) with ColumnLayout");
| public void | addSpacer(java.awt.Container target)Utility method to add a "spacer"
target.add(new Spacer());
| protected java.awt.Dimension | doLayout(java.awt.Container target)Used internally: compute the layout and the maximal preferred
width & height
TODO XXX NEED TO SCALE BY TARGSIZE?
Dimension targSize = target.getSize();
Insets ins = target.getInsets();
// Pass 1 - get preferred sizes
minw = minh = 0;
curComps = target.getComponents();
for (int i = 0; i<curComps.length; i++) {
Component tc = curComps[i];
Dimension d = tc.getPreferredSize();
minw = Math.max(minw, d.width);
minh = Math.max(minh, d.height);
}
int x = hPadding, y = vPadding;
// Pass 2 - move & resize components
for (int i = 0; i<curComps.length; i++) {
Component tc = curComps[i];
Dimension d = tc.getPreferredSize();
int cx, cy, cw, ch;
switch (alignment) {
case X_AXIS:
if (tc instanceof Spacer)
cw = d.width;
else
cw = minw;
ch = minh; // d.height;
cx = x;
x += cw+hPadding;
cy = vPadding;
y = ch;
break;
case Y_AXIS:
cw = minw; // d.width;
if (tc instanceof Spacer)
ch = d.height;
else
ch = minh;
cx = hPadding;
x = cw;
cy = y;
y += ch+vPadding;
break;
default:
throw new IllegalArgumentException("Invalid alignment");
}
tc.setBounds(cx, cy, cw, ch);
}
switch (alignment) {
case X_AXIS:
return new Dimension(x, y+2*vPadding);
case Y_AXIS:
return new Dimension(x+2*hPadding, y);
default:
throw new IllegalArgumentException("Invalid alignment");
}
| public void | layoutContainer(java.awt.Container target)Called by AWT to lay out the components
in the target Container at its current size.
//System.out.println("ColumnLayout.layoutContainer() called.");
doLayout(target);
| public java.awt.Dimension | minimumLayoutSize(java.awt.Container target)Called from AWT to calculate the minimum size dimensions
for the target panel given the components in it.
But we use our own list of named insertions, not the
list of Components that the container keeps.
// XXX should return doLayout(target, 0, 0); - add vpad, hpad args
return doLayout(target);
| public java.awt.Dimension | preferredLayoutSize(java.awt.Container target)Called by AWT to compute the preferred size for the target panel
given our list of the components that it contains.
System.out.println("preferredLayoutSize() called");
return doLayout(target);
| public void | removeLayoutComponent(java.awt.Component c)Called by AWT to remove a given component from the layout.
// nothing to do! user will (hopefully) invalidate() the target.
|
|