| java.lang.Object com.izforge.izpack.gui.TwoColumnLayout
TwoColumnLayout | public class TwoColumnLayout implements LayoutManager2(Code) | | This class implements a layout manager that generally lays out components in two columns.
The design goal for this layout manager was to lay out forms for data entry, where there are
several rows of entry fields with associated labels. The goal was to have the beginning off all
labels line up, as well as the left edge of all the data entry fields. This leads to a situation
where all components are essentially laid out in two columns. The columns adjust to accommodate
components of various sizes. This means that components that are added are laid out top to
bottom, either in the left column, in the right column or straddling both columns. In addition to
this general behavior, the following additional layout capabilities are supported:
- Resizable margins are provided on the left and right side.
- A special region is provided at the top that is only affected by the side margins but not by
any other layout behavior.
- It is possible to specify the vertical positioning of the cluster of laid out components for
the case that they do not occupy the entire available real estate.
- Individual components can be indented.
The Layout Behavior
The left and right margin are absolute. This means that they can not be penetrated by components.
All layout happens between the limits established by these margins. The purpose of these margins
is to ensure that components are not laid out all the way to the edge of their container, without
the need to set matching borders for each component.
The title margin at the top factors only into the layout behavior if there is a component set to
be laid out in that region, otherwise it is ignored.
The vertical space available to each row of components depends on the space requirements of the
tallest component in that row. Both components are placed vertically centered in their row.
All horizontal layout is based on the position of three vertical rules, the left rule, the right
rule and the center rule.
The actual position of each rule depends on the alignment strategy, margin settings and component
sizes. Regardless of these factors, components placed in the left column are always
positioned with their left edge aligned with the left rule. Components placed in the right column
are always positioned with their left edge aligned with the center rule. If a component
straddles both columns, it is always positioned with the left edge aligned with the left
rule, but is allowed to extend all the way to the right rule. The only exception is a component
that is specified with an indent. In this case the component is moved to the right of the
respective rule by the indent amount.
The location of the rules is determined based on the alignment strategy as follows:
- The right rule is always located at the edge of the right margin.
- Left Alignment: The left rule is located the edge of the left margin. The center
rule is located far enough to the right to clear the widest component in the left column.
- Center Alignment: The center rule is located at the center of the panel. The left
rule is located far enough to the left to make the widest component in the left column fit.
- Right Alignment The center rule is located far enough to the left of the right rule
to make the widest component in the right column fit. The left rule is located far enough to the
left to make the widest component in the left column fit.
All components clump together vertically and are positioned right beneath the title margin. This
is of course not a very appealing presentation. By setting how the remaining vertical space is
distributed above and below the cluster of components the cluster can be positioned more
favorably (see the shaded area in the illustration).
See Also: com.izforge.izpack.gui.TwoColumnConstraints version: 0.0.1 / 11/14/02 author: Elmar Grom |
Field Summary | |
final public static int | CENTER | final public static int | LEFT | final public static int | RIGHT |
Constructor Summary | |
public | TwoColumnLayout(int margin, int gap, int indent, int topBuffer, int alignment) Constructs a TwoColumnLayout layout manager. |
CENTER | final public static int CENTER(Code) | | |
LEFT | final public static int LEFT(Code) | | |
RIGHT | final public static int RIGHT(Code) | | |
TwoColumnLayout | public TwoColumnLayout(int margin, int gap, int indent, int topBuffer, int alignment)(Code) | | Constructs a TwoColumnLayout layout manager. To add components use the
container's add(comp, constraints) method with a TwoColumnConstraints object.
Parameters: margin - the margin width to use on the left and right side in % of the total containerwidth. Values less than 0% and greater than 50% are not accepted. Parameters: gap - the gap between the two columns. Parameters: indent - the indent to use for components that have that constraint set. This is a valuein pixels. Parameters: topBuffer - the percentage of left over vertical space to place on top of the componentcluster. Values between 0% and 100% are accepted. Parameters: alignment - how to align the overall layout. Legal values are LEFT, CENTER, RIGHT. |
addLayoutComponent | public void addLayoutComponent(Component comp, Object constraints)(Code) | | Sets the constraints for the specified component in this layout. null is a
legal value for a component, but not for a constraints object.
Parameters: comp - the component to be modified. Parameters: constraints - the constraints to be applied. |
addLayoutComponent | public void addLayoutComponent(String name, Component comp)(Code) | | Adds the specified component with the specified name to the layout. This version is not
supported, use addLayoutComponent with layout contsraints.
Parameters: name - the component name Parameters: comp - the component to be added |
getLayoutAlignmentX | public float getLayoutAlignmentX(Container parent)(Code) | | Returns the alignment along the x axis. This specifies how the component would like to be
aligned relative to other components. The value should be a number between 0 and 1 where 0
represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is
centered, etc.
Parameters: parent - the component to be laid out |
getLayoutAlignmentY | public float getLayoutAlignmentY(Container parent)(Code) | | Returns the alignment along the y axis. This specifies how the component would like to be
aligned relative to other components. The value should be a number between 0 and 1 where 0
represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is
centered, etc.
Parameters: parent - the component to be laid out |
invalidateLayout | public void invalidateLayout(Container parent)(Code) | | Invalidates the layout, indicating that if the layout manager has cached information it
should be discarded.
Parameters: parent - the component to be laid out |
layoutContainer | public void layoutContainer(Container parent)(Code) | | Lays out the container in the specified panel.
Parameters: parent - the component which needs to be laid out. |
maximumLayoutSize | public Dimension maximumLayoutSize(Container parent)(Code) | | Calculates the maximum size dimensions for the specified panel given the components in the
specified parent container.
Parameters: parent - the component to be laid out |
minimumLayoutSize | public Dimension minimumLayoutSize(Container parent)(Code) | | Calculates the minimum size dimensions for the specified panel given the components in the
specified parent container.
Parameters: parent - the component to be laid out |
preferredLayoutSize | public Dimension preferredLayoutSize(Container parent)(Code) | | Calculates the preferred size dimensions for the specified panel given the components in the
specified parent container.
Parameters: parent - the component to be laid out |
removeLayoutComponent | public void removeLayoutComponent(Component comp)(Code) | | This functionality removes the TwoColumnConstraints from Vectors
so that alignment of components on UserInputPanel doesn't get
dirty
Parameters: comp - the component to be removed |
showRules | public void showRules(Graphics2D graphics, Color color)(Code) | | This method is provided for conveninence of debugging layout problems. It renders the three
rules and the limit of the title marign visible after these positions have been computed. In
addition, the indent locations are shown as dashed lines. To use this functionality do the
following:
- in the container using this layout manager override the
paint() method.
- in that method, first call
super.paint()
- then call this method
Note: cast the graphics object received in the paint() method to
Graphics2D when making the call.
Parameters: graphics - the graphics context used for drawing. Parameters: color - the color to use for rendering the layout grid |
|
|