|
MDateSelector | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectmseries.utils.FormLayout
public class FormLayout
The FormLayout class is a flexible layout
manager that aligns components vertically and horizontally,
without requiring that the components be of the same size.
Each FormLayout object maintains a dynamic
rectangular grid of cells, with each component occupying
one cell, called its display area.
Each component managed by a form layout is associated
with an instance of
FormConstraints
that specifies how the component is laid out within its display area.
How a FormLayout object places a set of components
depends on the FormConstraints object associated
with each component, and on the minimum size
and the preferred size of the components' containers.
To use a form layout effectively, you must customize one or more
of the FormConstraints objects that are associated
with its components. You customize a FormConstraints
object by setting one or more of its instance variables:
FormConstraints.gridx,
FormConstraints.gridy
gridx = 0,
gridy = 0.
Use FormConstraints.RELATIVE (the default value)
to specify that the component be just placed
just to the right of (for gridx)
or just below (for gridy)
the component that was added to the container
just before this component was added.
FormConstraints.insets
FormConstraints.anchor
FormConstraints.CENTER (the default),
FormConstraints.NORTH,
FormConstraints.NORTHEAST,
FormConstraints.EAST,
FormConstraints.SOUTHEAST,
FormConstraints.SOUTH,
FormConstraints.SOUTHWEST,
FormConstraints.WEST, and
FormConstraints.NORTHWEST.
FormConstraints.spansColumns
The following figure shows 16 components managed by a form layout:
Here is the code that implements the example shown above, the creation of the components and setting of the border have been omitted.
JPanel pnlWeight = new JPanel();
pnlWeight.setLayout(new FormLayout());
FormConstraints constraints = new FormConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
// Gross Weight
constraints.anchor = FormConstraints.EAST;
pnlWeight.add(lblGrossWeightMand,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(tfGrossWeight,constraints);
// UOM2
constraints.anchor = FormConstraints.EAST;
constraints.gridx++;
pnlWeight.add(lblUOM2,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(cmbUOM2,constraints);
// Net Weight
constraints.anchor = FormConstraints.EAST;
constraints.gridx = 0;
constraints.gridy++;
pnlWeight.add(lblNetWeightMand,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(tfNetWeight,constraints);
// UOM 3
constraints.anchor = FormConstraints.EAST;
constraints.gridx++;
pnlWeight.add(lblUOM3,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(cmbUOM3,constraints);
// Tare Weight
constraints.anchor = FormConstraints.EAST;
constraints.gridx = 0;
constraints.gridy++;
pnlWeight.add(lblTareWeight,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(tfTareWeight,constraints);
// UOM 4
constraints.anchor = FormConstraints.EAST;
constraints.gridx++;
pnlWeight.add(lblUOM4,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(cmbUOM4,constraints);
// Average Weight
constraints.anchor = FormConstraints.EAST;
constraints.gridx = 0;
constraints.gridy++;
pnlWeight.add(lblAverageWeight,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(tfAverageWeight,constraints);
// UOM 5
constraints.anchor = FormConstraints.EAST;
constraints.gridx++;
pnlWeight.add(lblUOM5,constraints);
constraints.anchor = FormConstraints.WEST;
constraints.gridx++;
pnlWeight.add(cmbUOM5,constraints);
FormConstraints,
Serialized Form| Field Summary | |
|---|---|
protected Hashtable<Component,FormConstraints> |
comptable
This hashtable maintains the association between a component and its gridbox constraints. |
protected FormConstraints |
defaultConstraints
This field holds a gridbox constraints instance containing the default values, so if a component does not have gridbox constraints associated with it, then the component will be assigned a copy of the defaultConstraints. |
protected mseries.utils.FormLayoutInfo |
info
One FormLayoutInfo object is maintained for the layout manager that contains the working attributes for the whole layout. |
protected static int |
MAXGRIDSIZE
The maximum number of grid positions (both horizontally and vertically) that can be laid out by the form layout. |
protected static int |
MINHEIGHT
The smallest size (height) to make a component in each cell |
protected static int |
MINWIDTH
The smallest size (width) to make a component in each cell |
| Constructor Summary | |
|---|---|
FormLayout()
Creates a form layout manager. |
|
| Method Summary | |
|---|---|
void |
addLayoutComponent(Component comp,
Object constraints)
Adds the specified component to the layout, using the specified constraint object. |
void |
addLayoutComponent(String name,
Component comp)
Adds the specified component with the specified name to the layout. |
protected void |
applyGravity(FormConstraints constraints,
Rectangle r)
Relocates the component inside its cell according to the anchor constraint |
protected void |
calculateGridSize(Container parent,
Dimension size)
Calculates the location and size of each component in the container, according to the in built rules and the constraints of each component this is the job of the layout manager. |
FormConstraints |
getConstraints(Component comp)
Gets the constraints for the specified component. |
mseries.utils.FormLayoutInfo |
getInfo()
|
float |
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. |
void |
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
void |
layoutContainer(Container parent)
Lays out the specified container using this form layout. |
protected FormConstraints |
lookupConstraints(Component comp)
Retrieves the constraints for the specified component. |
Dimension |
maximumLayoutSize(Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. |
Dimension |
minimumLayoutSize(Container parent)
Determines the minimum size of the target container
using this form layout. |
Dimension |
preferredLayoutSize(Container parent)
Determines the preferred size of the target
container using this form layout. |
void |
removeLayoutComponent(Component comp)
Removes the specified component from this layout. |
protected void |
setComponentBounds(Container parent)
Set the bounds on the components based on the values calculated in the calculateGridSize method |
void |
setConstraints(Component comp,
FormConstraints constraints)
Sets the constraints for the specified component in this layout. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int MAXGRIDSIZE
protected static final int MINWIDTH
protected static final int MINHEIGHT
protected Hashtable<Component,FormConstraints> comptable
FormConstraintsprotected FormConstraints defaultConstraints
defaultConstraints.
getConstraints(Component),
setConstraints(Component, FormConstraints),
lookupConstraints(Component)protected mseries.utils.FormLayoutInfo info
| Constructor Detail |
|---|
public FormLayout()
| Method Detail |
|---|
public mseries.utils.FormLayoutInfo getInfo()
public void addLayoutComponent(String name,
Component comp)
addLayoutComponent in interface LayoutManagername - the name of the component.comp - the component to be added.
public void addLayoutComponent(Component comp,
Object constraints)
addLayoutComponent in interface LayoutManager2comp - the component to be added.constraints - an object that determines how
the component is added to the layout.public void removeLayoutComponent(Component comp)
Most applications do not call this method directly.
removeLayoutComponent in interface LayoutManagercomp - the component to be removed.Container.remove(java.awt.Component),
Container.removeAll()
public void setConstraints(Component comp,
FormConstraints constraints)
comp - the component to be modified.constraints - the constraints to be applied.public FormConstraints getConstraints(Component comp)
FormConstraints object is returned.
comp - the component to be queried.
protected FormConstraints lookupConstraints(Component comp)
FormConstraints object used by the layout mechanism.
comp - the component to be queried
public void layoutContainer(Container parent)
FormLayout
object.
Most applications do not call this method directly.
layoutContainer in interface LayoutManagerparent - the container in which to do the layout.Container,
Container.doLayout()
protected void calculateGridSize(Container parent,
Dimension size)
protected void setComponentBounds(Container parent)
protected void applyGravity(FormConstraints constraints,
Rectangle r)
constraints - the FormConstraints for the cellr - the rectangle speifying the bounds of the cellpublic Dimension preferredLayoutSize(Container parent)
target
container using this form layout.
Most applications do not call this method directly.
preferredLayoutSize in interface LayoutManagerparent - the container in which to do the layout.Container.getPreferredSize()public Dimension minimumLayoutSize(Container parent)
target container
using this form layout.
Most applications do not call this method directly.
minimumLayoutSize in interface LayoutManagerparent - the container in which to do the layout.Container.doLayout()public Dimension maximumLayoutSize(Container target)
maximumLayoutSize in interface LayoutManager2target - the component which needs to be laid outContainer,
minimumLayoutSize(Container),
preferredLayoutSize(Container)public float getLayoutAlignmentX(Container parent)
getLayoutAlignmentX in interface LayoutManager2public float getLayoutAlignmentY(Container parent)
getLayoutAlignmentY in interface LayoutManager2public void invalidateLayout(Container target)
invalidateLayout in interface LayoutManager2
|
MDateSelector | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||