org.apache.jorphan.gui.layout
public class: VerticalLayout [javadoc |
source]
java.lang.Object
org.apache.jorphan.gui.layout.VerticalLayout
All Implemented Interfaces:
LayoutManager, Serializable
A vertical layout manager similar to java.awt.FlowLayout. Like FlowLayout
components do not expand to fill available space except when the horizontal
alignment is
BOTH
in which case components are stretched
horizontally. Unlike FlowLayout, components will not wrap to form another
column if there isn't enough space vertically. VerticalLayout can optionally
anchor components to the top or bottom of the display area or center them
between the top and bottom. Revision date 04 April 1999
- version:
$
- Revision: 674365 $
Field Summary |
---|
public static final int | CENTER | The horizontal alignment constant that designates centering. Also used to
designate center anchoring. |
public static final int | RIGHT | The horizontal alignment constant that designates right justification. |
public static final int | LEFT | The horizontal alignment constant that designates left justification. |
public static final int | BOTH | The horizontal alignment constant that designates stretching the
component horizontally. |
public static final int | TOP | The anchoring constant that designates anchoring to the top of the
display area. |
public static final int | BOTTOM | The anchoring constant that designates anchoring to the bottom of the
display area. |
Constructor: |
public VerticalLayout() {
this(5, CENTER, TOP);
}
Constructs an instance of VerticalLayout with a vertical vgap of 5
pixels, horizontal centering and anchored to the top of the display area. |
public VerticalLayout(int vgap) {
this(vgap, CENTER, TOP);
}
Constructs a VerticalLayout instance with horizontal centering, anchored
to the top with the specified vgap. Parameters:
vgap -
an int value indicating the vertical seperation of the
components
|
public VerticalLayout(int vgap,
int alignment) {
this(vgap, alignment, TOP);
}
Constructs a VerticalLayout instance anchored to the top with the
specified vgap and horizontal alignment. Parameters:
vgap -
an int value indicating the vertical seperation of the
components
alignment -
an int value which is one of RIGHT, LEFT,
CENTER, BOTH
for the horizontal alignment.
|
public VerticalLayout(int vgap,
int alignment,
int anchor) {
this.vgap = vgap;
this.alignment = alignment;
this.anchor = anchor;
}
Constructs a VerticalLayout instance with the specified vgap, horizontal
alignment and anchoring Parameters:
vgap -
an int value indicating the vertical seperation of the
components
alignment -
an int value which is one of RIGHT, LEFT, CENTER,
BOTH
for the horizontal alignment.
anchor -
an int value which is one of TOP, BOTTOM,
CENTER
indicating where the components are to appear if the display
area exceeds the minimum necessary.
|
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.jorphan.gui.layout.VerticalLayout Detail: |
public void addLayoutComponent(String name,
Component comp) {
}
|
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
// NOTUSED Dimension dim = layoutSize(parent, false);
synchronized (parent.getTreeLock()) {
int n = parent.getComponentCount();
Dimension pd = parent.getSize();
int y = 0;
// work out the total size
for (int i = 0; i < n; i++) {
Component c = parent.getComponent(i);
Dimension d = c.getPreferredSize();
y += d.height + vgap;
}
y -= vgap; // otherwise there's a vgap too many
// Work out the anchor paint
if (anchor == TOP) {
y = insets.top;
} else if (anchor == CENTER) {
y = (pd.height - y) / 2;
} else {
y = pd.height - y - insets.bottom;
}
// do layout
for (int i = 0; i < n; i++) {
Component c = parent.getComponent(i);
Dimension d = c.getPreferredSize();
int x = insets.left;
int wid = d.width;
if (alignment == CENTER) {
x = (pd.width - d.width) / 2;
} else if (alignment == RIGHT) {
x = pd.width - d.width - insets.right;
} else if (alignment == BOTH) {
wid = pd.width - insets.left - insets.right;
}
c.setBounds(x, y, wid, d.height);
y += d.height + vgap;
}
}
}
|
public Dimension minimumLayoutSize(Container parent) {
return layoutSize(parent, true);
}
|
public Dimension preferredLayoutSize(Container parent) {
return layoutSize(parent, false);
}
|
public void removeLayoutComponent(Component comp) {
}
|
public String toString() {
return getClass().getName() + "[vgap=" + vgap + " align=" + alignment + " anchor=" + anchor + "]";
}
|