|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jgoodies.forms.layout.FormLayout
public final class FormLayout
FormLayout is a powerful, flexible and precise general purpose layout manager. It aligns components vertically and horizontally in a dynamic rectangular grid of cells, with each component occupying one or more cells. A whitepaper about the FormLayout ships with the product documentation and is available online.
To use FormLayout you first define the grid by specifying the
columns and rows. In a second step you add components to the grid. You can
specify columns and rows via human-readable String descriptions or via
arrays of ColumnSpec
and RowSpec
instances.
Each component managed by a FormLayout is associated with an instance of
CellConstraints
. The constraints object specifies where a component
should be located on the form's grid and how the component should be
positioned. In addition to its constraints object the
FormLayout
also considers each component's minimum and
preferred sizes in order to determine a component's size.
FormLayout has been designed to work with non-visual builders that help you
specify the layout and fill the grid. For example, the
ButtonBarBuilder
assists you in building button
bars; it creates a standardized FormLayout and provides a minimal API that
specializes in adding buttons. Other builders can create frequently used
panel design, for example a form that consists of rows of label-component
pairs.
FormLayout has been prepared to work with different types of sizes as
defined by the Size
interface.
Example 1 (Plain FormLayout):
The following example creates a panel with 3 data columns and 3 data rows;
the columns and rows are specified before components are added
to the form.
FormLayout layout = new FormLayout( "right:pref, 6dlu, 50dlu, 4dlu, default", // columns "pref, 3dlu, pref, 3dlu, pref"); // rows CellConstraints cc = new CellConstraints(); JPanel panel = new JPanel(layout); panel.add(new JLabel("Label1"), cc.xy (1, 1)); panel.add(new JTextField(), cc.xywh(3, 1, 3, 1)); panel.add(new JLabel("Label2"), cc.xy (1, 3)); panel.add(new JTextField(), cc.xy (3, 3)); panel.add(new JLabel("Label3"), cc.xy (1, 5)); panel.add(new JTextField(), cc.xy (3, 5)); panel.add(new JButton("/u2026"), cc.xy (5, 5)); return panel;
Example 2 (Using PanelBuilder):
This example creates the same panel as above using the
PanelBuilder
to add components to the form.
FormLayout layout = new FormLayout( "right:pref, 6dlu, 50dlu, 4dlu, default", // columns "pref, 3dlu, pref, 3dlu, pref"); // rows PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addLabel("Label1", cc.xy (1, 1)); builder.add(new JTextField(), cc.xywh(3, 1, 3, 1)); builder.addLabel("Label2", cc.xy (1, 3)); builder.add(new JTextField(), cc.xy (3, 3)); builder.addLabel("Label3", cc.xy (1, 5)); builder.add(new JTextField(), cc.xy (3, 5)); builder.add(new JButton("/u2026"), cc.xy (5, 5)); return builder.getPanel();
Example 3 (Using DefaultFormBuilder):
This example utilizes the
DefaultFormBuilder
that
ships with the source distribution.
FormLayout layout = new FormLayout( "right:pref, 6dlu, 50dlu, 4dlu, default"); // 5 columns; add rows later DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.append("Label1", new JTextField(), 3); builder.append("Label2", new JTextField()); builder.append("Label3", new JTextField()); builder.append(new JButton("/u2026")); return builder.getPanel();
TODO: In the Forms 1.0.x invisible components are not taken into account when the FormLayout lays out the container. Add an optional setting for this on both the container-level and component-level. So one can specify that invisible components shall be taken into account, but may exclude individual components. Or the other way round, exclude invisible components, and include individual components. The API of both the FormLayout and CellConstraints classes shall be extended to support this option. This feature is planned for the Forms version 1.1 and is described in issue #28 of the Forms' issue tracker where you can track the progress.
ColumnSpec
,
RowSpec
,
CellConstraints
,
AbstractFormBuilder
,
ButtonBarBuilder
,
DefaultFormBuilder
,
FormFactory
,
Size
,
Sizes
,
Serialized FormNested Class Summary | |
---|---|
private static class |
FormLayout.CachingMeasure
An abstract implementation of the Measure interface
that caches component sizes. |
private static class |
FormLayout.ComponentSizeCache
A cache for component minimum and preferred sizes. |
static class |
FormLayout.LayoutInfo
Stores column and row origins. |
(package private) static interface |
FormLayout.Measure
An interface that describes how to measure a Component . |
private static class |
FormLayout.MinimumHeightMeasure
Measures a component by computing its minimum height. |
private static class |
FormLayout.MinimumWidthMeasure
Measures a component by computing its minimum width. |
private static class |
FormLayout.PreferredHeightMeasure
Measures a component by computing its preferred height. |
private static class |
FormLayout.PreferredWidthMeasure
Measures a component by computing its preferred width. |
Field Summary | |
---|---|
private java.util.List[] |
colComponents
Holds the components that occupy exactly one column. |
private int[][] |
colGroupIndices
Holds the column groups as an array of arrays of column indices. |
private java.util.List |
colSpecs
Holds the column specifications. |
private FormLayout.ComponentSizeCache |
componentSizeCache
Caches component minimum and preferred sizes. |
private java.util.Map |
constraintMap
Maps components to their associated CellConstraints . |
private FormLayout.Measure |
minimumHeightMeasure
|
private FormLayout.Measure |
minimumWidthMeasure
These functional objects are used to measure component sizes. |
private FormLayout.Measure |
preferredHeightMeasure
|
private FormLayout.Measure |
preferredWidthMeasure
|
private java.util.List[] |
rowComponents
Holds the components that occupy exactly one row. |
private int[][] |
rowGroupIndices
Holds the row groups as an array of arrays of row indices. |
private java.util.List |
rowSpecs
Holds the row specifications. |
Constructor Summary | |
---|---|
FormLayout()
Constructs an empty FormLayout. |
|
FormLayout(ColumnSpec[] colSpecs,
RowSpec[] rowSpecs)
Constructs a FormLayout using the given column and row specifications. |
|
FormLayout(java.lang.String encodedColumnSpecs)
Constructs a FormLayout using the given encoded column specifications. |
|
FormLayout(java.lang.String encodedColumnSpecs,
java.lang.String encodedRowSpecs)
Constructs a FormLayout using the given encoded column and row specifications. |
Method Summary | |
---|---|
void |
addGroupedColumn(int columnIndex)
Adds the specified column index to the last column group. |
void |
addGroupedRow(int rowIndex)
Adds the specified row index to the last row group. |
void |
addLayoutComponent(java.awt.Component comp,
java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraints object. |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
Throws an UnsupportedOperationException . |
private void |
adjustGroupIndices(int[][] allGroupIndices,
int modifiedIndex,
boolean remove)
Adjusts group indices. |
void |
appendColumn(ColumnSpec columnSpec)
Appends the given column specification to the right hand side of all columns. |
void |
appendRow(RowSpec rowSpec)
Appends the given row specification to the bottom of all rows. |
private int[] |
compressedSizes(java.util.List formSpecs,
int totalSize,
int totalMinSize,
int totalPrefSize,
int[] minSizes,
int[] prefSizes)
Computes and returns the compressed sizes. |
private int[] |
computeGridOrigins(java.awt.Container container,
int totalSize,
int offset,
java.util.List formSpecs,
java.util.List[] componentLists,
int[][] groupIndices,
FormLayout.Measure minMeasure,
FormLayout.Measure prefMeasure)
Computes and returns the grid's origins. |
private java.awt.Dimension |
computeLayoutSize(java.awt.Container parent,
FormLayout.Measure defaultWidthMeasure,
FormLayout.Measure defaultHeightMeasure)
Computes and returns the layout size of the given parent
container using the specified measures. |
private int[] |
computeMaximumFixedSpanTable(java.util.List formSpecs)
Computes and returns a table that maps a column/row index to the maximum number of columns/rows that a component can span without spanning a growing column. |
private int[] |
computeOrigins(int[] sizes,
int offset)
Computes origins from sizes taking the specified offset into account. |
private int[][] |
deepClone(int[][] array)
Creates and returns a deep copy of the given array. |
private int[] |
distributedSizes(java.util.List formSpecs,
int totalSize,
int totalPrefSize,
int[] inputSizes)
Distributes free space over columns and rows and returns the sizes after this distribution process. |
int |
getColumnCount()
Returns the number of columns in this layout. |
int[][] |
getColumnGroups()
Returns a deep copy of the column groups. |
ColumnSpec |
getColumnSpec(int columnIndex)
Returns the ColumnSpec at the specified column index. |
CellConstraints |
getConstraints(java.awt.Component component)
Looks up and returns the constraints for the specified component. |
float |
getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. |
FormLayout.LayoutInfo |
getLayoutInfo(java.awt.Container parent)
Computes and returns the horizontal and vertical grid origins. |
int |
getRowCount()
Returns the number of rows in this layout. |
int[][] |
getRowGroups()
Returns a deep copy of the row groups. |
RowSpec |
getRowSpec(int rowIndex)
Returns the RowSpec at the specified row index. |
private int[] |
groupedSizes(int[][] groups,
int[] rawSizes)
Computes and returns the grouped sizes. |
private void |
initializeColAndRowComponentLists()
Initializes two lists for columns and rows that hold a column's or row's components that span only this column or row. |
void |
insertColumn(int columnIndex,
ColumnSpec columnSpec)
Inserts the specified column at the specified position. |
void |
insertRow(int rowIndex,
RowSpec rowSpec)
Inserts the specified column at the specified position. |
private void |
invalidateCaches()
Invalidates the component size caches. |
void |
invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
private void |
layoutComponents(int[] x,
int[] y)
Lays out the components using the given x and y origins, the column and row specifications, and the component constraints. |
void |
layoutContainer(java.awt.Container parent)
Lays out the specified container using this form layout. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. |
private int[] |
maximumSizes(java.awt.Container container,
java.util.List formSpecs,
java.util.List[] componentLists,
FormLayout.Measure minMeasure,
FormLayout.Measure prefMeasure,
FormLayout.Measure defaultMeasure)
Computes and returns the sizes for the given form specs, component lists and measures fot minimum, preferred, and default size. |
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Determines the minimum size of the parent container
using this form layout. |
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the parent
container using this form layout. |
void |
removeColumn(int columnIndex)
Removes the column with the given column index from the layout. |
private void |
removeConstraints(java.awt.Component component)
Removes the constraints for the specified component in this layout. |
void |
removeLayoutComponent(java.awt.Component comp)
Removes the specified component from this layout. |
void |
removeRow(int rowIndex)
Removes the row with the given row index from the layout. |
void |
setColumnGroups(int[][] colGroupIndices)
Sets the column groups, where each column in a group gets the same group wide width. |
void |
setColumnSpec(int columnIndex,
ColumnSpec columnSpec)
Sets the ColumnSpec at the specified column index. |
void |
setConstraints(java.awt.Component component,
CellConstraints constraints)
Sets the constraints for the specified component in this layout. |
void |
setRowGroups(int[][] rowGroupIndices)
Sets the row groups, where each row in such a group gets the same group wide height. |
void |
setRowSpec(int rowIndex,
RowSpec rowSpec)
Sets the RowSpec at the specified row index. |
private void |
shiftComponentsHorizontally(int columnIndex,
boolean remove)
Shifts components horizontally, either to the right if a column has been inserted or to the left if a column has been removed. |
private void |
shiftComponentsVertically(int rowIndex,
boolean remove)
Shifts components vertically, either to the bottom if a row has been inserted or to the top if a row has been removed. |
private int |
sum(int[] sizes)
Computes and returns the sum of integers in the given array of ints. |
private void |
writeObject(java.io.ObjectOutputStream out)
In addition to the default serialization mechanism this class invalidates the component size cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.util.List colSpecs
ColumnSpec
,
getColumnCount()
,
getColumnSpec(int)
,
appendColumn(ColumnSpec)
,
insertColumn(int, ColumnSpec)
,
removeColumn(int)
private final java.util.List rowSpecs
RowSpec
,
getRowCount()
,
getRowSpec(int)
,
appendRow(RowSpec)
,
insertRow(int, RowSpec)
,
removeRow(int)
private int[][] colGroupIndices
getColumnGroups()
,
setColumnGroups(int[][])
,
addGroupedColumn(int)
private int[][] rowGroupIndices
getRowGroups()
,
setRowGroups(int[][])
,
addGroupedRow(int)
private final java.util.Map constraintMap
CellConstraints
.
CellConstraints
,
getConstraints(Component)
,
setConstraints(Component, CellConstraints)
private transient java.util.List[] colComponents
private transient java.util.List[] rowComponents
private final FormLayout.ComponentSizeCache componentSizeCache
private final FormLayout.Measure minimumWidthMeasure
private final FormLayout.Measure minimumHeightMeasure
private final FormLayout.Measure preferredWidthMeasure
private final FormLayout.Measure preferredHeightMeasure
Constructor Detail |
---|
public FormLayout()
This constructor is intended to be used in environments that add columns and rows dynamically.
public FormLayout(java.lang.String encodedColumnSpecs)
This constructor is primarily intended to be used with builder classes
that add rows dynamically, such as the DefaultFormBuilder
.
Examples:
// Label, gap, component FormLayout layout = new FormLayout( "pref, 4dlu, pref"); // Right-aligned label, gap, component, gap, component FormLayout layout = new FormLayout( "right:pref, 4dlu, 50dlu, 4dlu, 50dlu"); // Left-aligned labels, gap, components, gap, components FormLayout layout = new FormLayout( "left:pref, 4dlu, pref, 4dlu, pref");See the class comment for more examples.
encodedColumnSpecs
- comma separated encoded column specifications
java.lang.NullPointerException
- if encodedColumnSpecs is null
public FormLayout(java.lang.String encodedColumnSpecs, java.lang.String encodedRowSpecs)
This constructor is recommended for most hand-coded layouts.
Examples:
FormLayout layout = new FormLayout( "pref, 4dlu, pref", // columns "p, 3dlu, p"); // rows FormLayout layout = new FormLayout( "right:pref, 4dlu, pref", // columns "p, 3dlu, p, 3dlu, fill:p:grow"); // rows FormLayout layout = new FormLayout( "left:pref, 4dlu, 50dlu", // columns "p, 2px, p, 3dlu, p, 9dlu, p"); // rows FormLayout layout = new FormLayout( "max(75dlu;pref), 4dlu, default", // columns "p, 3dlu, p, 3dlu, p, 3dlu, p"); // rowsSee the class comment for more examples.
encodedColumnSpecs
- comma separated encoded column specificationsencodedRowSpecs
- comma separated encoded row specifications
java.lang.NullPointerException
- if encodedColumnSpecs or encodedRowSpecs
is null
public FormLayout(ColumnSpec[] colSpecs, RowSpec[] rowSpecs)
colSpecs
- an array of column specifications.rowSpecs
- an array of row specifications.
java.lang.NullPointerException
- if colSpecs or rowSpecs is nullMethod Detail |
---|
public int getColumnCount()
public int getRowCount()
public ColumnSpec getColumnSpec(int columnIndex)
ColumnSpec
at the specified column index.
columnIndex
- the column index of the requested ColumnSpec
ColumnSpec
at the specified column
java.lang.IndexOutOfBoundsException
- if the column index is out of rangepublic void setColumnSpec(int columnIndex, ColumnSpec columnSpec)
ColumnSpec
at the specified column index.
columnIndex
- the index of the column to be changedcolumnSpec
- the ColumnSpec
to be set
java.lang.NullPointerException
- if the column specification is null
java.lang.IndexOutOfBoundsException
- if the column index is out of rangepublic RowSpec getRowSpec(int rowIndex)
RowSpec
at the specified row index.
rowIndex
- the row index of the requested RowSpec
RowSpec
at the specified row
java.lang.IndexOutOfBoundsException
- if the row index is out of rangepublic void setRowSpec(int rowIndex, RowSpec rowSpec)
RowSpec
at the specified row index.
rowIndex
- the index of the row to be changedrowSpec
- the RowSpec
to be set
java.lang.NullPointerException
- if the row specification is null
java.lang.IndexOutOfBoundsException
- if the row index is out of rangepublic void appendColumn(ColumnSpec columnSpec)
columnSpec
- the column specification to be added
java.lang.NullPointerException
- if the column specification is nullpublic void insertColumn(int columnIndex, ColumnSpec columnSpec)
The component shift works as follows: components that were located on the right hand side of the inserted column are shifted one column to the right; component column span is increased by one if it intersects the new column.
Column group indices that are greater or equal than the given column index will be increased by one.
columnIndex
- index of the column to be insertedcolumnSpec
- specification of the column to be inserted
java.lang.IndexOutOfBoundsException
- if the column index is out of rangepublic void removeColumn(int columnIndex)
The component shift works as follows: components that were located on the right hand side of the removed column are moved one column to the left; component column span is decreased by one if it intersects the removed column.
Column group indices that are greater than the column index will be decreased by one.
Note: If one of the constraints mentioned above
is violated, this layout's state becomes illegal and it is unsafe
to work with this layout.
A typical layout implementation can ensure that these constraints are
not violated. However, in some cases you may need to check these
conditions before you invoke this method. The Forms extras contain
source code for class FormLayoutUtils
that provides
the required test methods:
#columnContainsComponents(Container, int)
and
#isGroupedColumn(FormLayout, int)
.
columnIndex
- index of the column to remove
java.lang.IndexOutOfBoundsException
- if the column index is out of range
java.lang.IllegalStateException
- if the column contains components
or if the column is already groupedpublic void appendRow(RowSpec rowSpec)
rowSpec
- the row specification to be added to the form layout
java.lang.NullPointerException
- if the rowSpec is nullpublic void insertRow(int rowIndex, RowSpec rowSpec)
The component shift works as follows: components that were located on the right hand side of the inserted column are shifted one column to the right; component column span is increased by one if it intersects the new column.
Column group indices that are greater or equal than the given column index will be increased by one.
rowIndex
- index of the row to be insertedrowSpec
- specification of the row to be inserted
java.lang.IndexOutOfBoundsException
- if the row index is out of rangepublic void removeRow(int rowIndex)
The component shift works as follows: components that were located below the removed row are moved up one row; component row span is decreased by one if it intersects the removed row.
Row group indices that are greater than the row index will be decreased by one.
Note: If one of the constraints mentioned above
is violated, this layout's state becomes illegal and it is unsafe
to work with this layout.
A typical layout implementation can ensure that these constraints are
not violated. However, in some cases you may need to check these
conditions before you invoke this method. The Forms extras contain
source code for class FormLayoutUtils
that provides
the required test methods:
#rowContainsComponents(Container, int)
and
#isGroupedRow(FormLayout, int)
.
rowIndex
- index of the row to remove
java.lang.IndexOutOfBoundsException
- if the row index is out of range
java.lang.IllegalStateException
- if the row contains components
or if the row is already groupedprivate void shiftComponentsHorizontally(int columnIndex, boolean remove)
columnIndex
- index of the column to removeremove
- true for remove, false for insert
java.lang.IllegalStateException
- if a removed column contains componentsprivate void shiftComponentsVertically(int rowIndex, boolean remove)
rowIndex
- index of the row to removeremove
- true for remove, false for insert
java.lang.IllegalStateException
- if a removed column contains componentsprivate void adjustGroupIndices(int[][] allGroupIndices, int modifiedIndex, boolean remove)
allGroupIndices
- the groups to be adjustedmodifiedIndex
- the modified column or row indexremove
- true for remove, false for add
java.lang.IllegalStateException
- if we remove and the index is groupedpublic CellConstraints getConstraints(java.awt.Component component)
CellConstraints
object is returned.
component
- the component to be queried
CellConstraints
for the specified component
java.lang.NullPointerException
- if component is null
or
has not been added to the containerpublic void setConstraints(java.awt.Component component, CellConstraints constraints)
component
- the component to be modifiedconstraints
- the constraints to be applied
java.lang.NullPointerException
- if the component or constraints object
is null
private void removeConstraints(java.awt.Component component)
component
- the component to be modifiedpublic int[][] getColumnGroups()
public void setColumnGroups(int[][] colGroupIndices)
Examples:
// Group columns 1, 3 and 4. setColumnGroups(new int[][]{ {1, 3, 4}}); // Group columns 1, 3, 4, and group columns 7 and 9 setColumnGroups(new int[][]{ {1, 3, 4}, {7, 9}});
colGroupIndices
- a two-dimensional array of column groups indices
java.lang.IndexOutOfBoundsException
- if an index is outside the grid
java.lang.IllegalArgumentException
- if a column index is used twicepublic void addGroupedColumn(int columnIndex)
columnIndex
- the column index to be set groupedpublic int[][] getRowGroups()
public void setRowGroups(int[][] rowGroupIndices)
Examples:
// Group rows 1 and 2. setRowGroups(new int[][]{ {1, 2}}); // Group rows 1 and 2, and group rows 5, 7, and 9. setRowGroups(new int[][]{ {1, 2}, {5, 7, 9}});
rowGroupIndices
- a two-dimensional array of row group indices.
java.lang.IndexOutOfBoundsException
- if an index is outside the gridpublic void addGroupedRow(int rowIndex)
rowIndex
- the index of the row that should be groupedpublic void addLayoutComponent(java.lang.String name, java.awt.Component component)
UnsupportedOperationException
. Does not add
the specified component with the specified name to the layout.
addLayoutComponent
in interface java.awt.LayoutManager
name
- indicates entry's position and anchorcomponent
- component to add
java.lang.UnsupportedOperationException
- alwayspublic void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
constraints
object. Note that constraints are mutable and
are, therefore, cloned when cached.
addLayoutComponent
in interface java.awt.LayoutManager2
comp
- the component to be addedconstraints
- the component's cell constraints
java.lang.NullPointerException
- if constraints
is null
java.lang.IllegalArgumentException
- if constraints
is not a
CellConstraints
or a String that cannot be used to construct
a CellConstraints
public void removeLayoutComponent(java.awt.Component comp)
Most applications do not call this method directly.
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- the component to be removed.Container.remove(java.awt.Component)
,
Container.removeAll()
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
parent
container
using this form layout.Most applications do not call this method directly.
minimumLayoutSize
in interface java.awt.LayoutManager
parent
- the container in which to do the layout
parent
containerContainer.doLayout()
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
parent
container using this form layout.Most applications do not call this method directly.
preferredLayoutSize
in interface java.awt.LayoutManager
parent
- the container in which to do the layout
parent
containerContainer.getPreferredSize()
public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
maximumLayoutSize
in interface java.awt.LayoutManager2
target
- the container which needs to be laid out
Container
,
minimumLayoutSize(Container)
,
preferredLayoutSize(Container)
public float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
parent
- the parent container
0.5f
to indicate center alignmentpublic float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
parent
- the parent container
0.5f
to indicate center alignmentpublic void invalidateLayout(java.awt.Container target)
invalidateLayout
in interface java.awt.LayoutManager2
target
- the container that holds the layout to be invalidatedpublic void layoutContainer(java.awt.Container parent)
FormLayout
object.Most applications do not call this method directly.
The form layout performs the following steps:
layoutContainer
in interface java.awt.LayoutManager
parent
- the container in which to do the layoutContainer
,
Container.doLayout()
private void initializeColAndRowComponentLists()
Iterates over all components and their associated constraints; every component that has a column span or row span of 1 is put into the column's or row's component list.
As of the Forms version 1.0.x invisible components are not taken into account when the container is layed out. See the TODO in the JavaDoc class commment for details on this issue.
private java.awt.Dimension computeLayoutSize(java.awt.Container parent, FormLayout.Measure defaultWidthMeasure, FormLayout.Measure defaultHeightMeasure)
parent
container using the specified measures.
parent
- the container in which to do the layoutdefaultWidthMeasure
- the measure used to compute the default widthdefaultHeightMeasure
- the measure used to compute the default height
parent
containerprivate int[] computeGridOrigins(java.awt.Container container, int totalSize, int offset, java.util.List formSpecs, java.util.List[] componentLists, int[][] groupIndices, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure)
container
- the layout containertotalSize
- the total size to assignoffset
- the offset from left or top marginformSpecs
- the column or row specs, resp.componentLists
- the components list for each col/rowminMeasure
- the measure used to determin min sizesprefMeasure
- the measure used to determin pre sizesgroupIndices
- the group specification
private int[] computeOrigins(int[] sizes, int offset)
sizes
- the array of sizesoffset
- an offset for the first origin
private void layoutComponents(int[] x, int[] y)
The actual computation is done by each component's form constraint
object. We just compute the cell, the cell bounds and then hand over
the component, cell bounds, and measure to the form constraints.
This will allow potential subclasses of CellConstraints
to do special micro-layout corrections. For example, such a subclass
could map JComponent classes to visual layout bounds that may
lead to a slightly different bounds.
x
- an int array of the horizontal originsy
- an int array of the vertical originsprivate void invalidateCaches()
private int[] maximumSizes(java.awt.Container container, java.util.List formSpecs, java.util.List[] componentLists, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)
container
- the layout containerformSpecs
- the column or row specs, resp.componentLists
- the components list for each col/rowminMeasure
- the measure used to determin min sizesprefMeasure
- the measure used to determin pre sizesdefaultMeasure
- the measure used to determin default sizes
private int[] compressedSizes(java.util.List formSpecs, int totalSize, int totalMinSize, int totalPrefSize, int[] minSizes, int[] prefSizes)
Only columns and row that are specified to be compressable will be affected. You can specify a column and row as compressable by giving it the component size default.
formSpecs
- the column or row specs to usetotalSize
- the total available sizetotalMinSize
- the sum of all minimum sizestotalPrefSize
- the sum of all preferred sizesminSizes
- an int array of column/row minimum sizesprefSizes
- an int array of column/row preferred sizes
private int[] groupedSizes(int[][] groups, int[] rawSizes)
groups
- the group specificationrawSizes
- the raw sizes before the grouping
private int[] distributedSizes(java.util.List formSpecs, int totalSize, int totalPrefSize, int[] inputSizes)
formSpecs
- the column/row specifications to work withtotalSize
- the total available sizetotalPrefSize
- the sum of all preferred sizesinputSizes
- the input sizes
private int sum(int[] sizes)
sizes
- an array of ints to sum up
private int[] computeMaximumFixedSpanTable(java.util.List formSpecs)
Iterates over the specs from right to left/bottom to top, sets the table value to zero if a spec can grow, otherwise increases the span by one.
Examples:
"pref, 4dlu, pref, 2dlu, p:grow, 2dlu, pref" -> [4, 3, 2, 1, 0, MAX_VALUE, MAX_VALUE] "p:grow, 4dlu, p:grow, 9dlu, pref" -> [0, 1, 0, MAX_VALUE, MAX_VALUE] "p, 4dlu, p, 2dlu, 0:grow" -> [4, 3, 2, 1, 0]
formSpecs
- the column specs or row specs
public FormLayout.LayoutInfo getLayoutInfo(java.awt.Container parent)
#layoutContainer
but does not layout the components.This method has been added only to make it easier to debug the form layout. You must not call this method directly; It may be removed in a future release or the visibility may be reduced.
parent
- the Container
to inspect
private int[][] deepClone(int[][] array)
#clone
that performs a shallow copy,
this method copies both array levels.
array
- the array to clone
Object.clone()
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
colComponents
and
rowComponents
have been marked as transient
to exclude them from the serialization.
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |