Poseidon for UMLTM
  UMLdoc
 PREV  CLASSIFIER    NEXT  CLASSIFIER     FRAMES    NO FRAMES      
SUMMARY:   INNER | ATTR | ASSOC | CONSTR | METHOD     DETAIL:   INNER | ATTR | ASSOC | CONSTR | METHOD     DIAGRAMS:   COLLAB | SEQ | STATE | ACTIV

com.gentleware.services.swingx

Class XTableLayout

com.gentleware.services.swingx.XTableLayout

public class XTableLayout


A very flexible layout manager that assigns each component to one or more cells of a grid of columns and rows. Column widths and row heights depend on specified weights.
So XTableLayout's features are very similar to GridBagLayout, but it is easier to use and avoids some of the oddities of GridBagLayout:

Each component has associated constraints that describe its position and resizing behaviour. Constraints are specified when the component is added to its container and cannot be changed later. An instance of XTableConstraints can be used, but it is much more convenient to use a string to specify the constraints:
"x y width height xAlign yAlign xWeight yWeight"

x, y
Integer values that specify the component's start position in the grid. The cell at the top-left cell has position x = 0, y = 0.
The special value "." means the same x (resp. y) position as the last component added. "+" specifies the next x (resp. y) position after the last component added. (So if "+" is used to specify the x position of a new component and the last component was added to x = 3 and had a width = 2, the new component will get x = 5.) When no component has been added so far then both "+" and "." result in 0.


width, height
The component will span width columns and height rows. The default for both width and height is 1.


xAlign
One of "left", "center", "right" or "fill". If the component's column is wider than the component, then this value is used to position the component within the column.
If "fill" is specified, but the column is wider than the component's maximum width, then the component is positioned according to its horizontal alignment as returned from java.awt.Component#getAlignmentX. (On the other hand the column will never get smaller than the component's minimum width.)
The default value is "left".


yAlign
One of "top", "center", "bottom" or "fill". If the component's row is higher than the component, then this value is used to position the component within the row.
If "fill" is specified, but the row is higher than the component's maximum height, then the component is positioned according to its vertical alignment as returned from java.awt.Component#getAlignmentY. (On the other hand the row will never get smaller than the component's minimum height.)
The default value is "top" (but if xAlign is specified then yAlign must be specified explicitly, too).


xWeight, yWeight
Double values that specify the column's (resp. row's) weight.
When the container is wider than it's preferred width the extra width is distributed to each column proportionally to the column's weight divided by the total weight.
The same algorithm is used if the container is smaller than it's preferred width to substract from each column's preferred width.

Basically a column's weight is the maximum of all xWeights specified for components in that column. (Column weights are first calculated using non-spanning components only. The xWeight of a component that spans multiple columns is then distributed to all of the columns proportionally to each columns weight divided by the total weight of the columns that are spanned.) If a component's xWeight is 0 then the component will always get (at least) its preferred width. If no other component in the column specifies a positiv xWeight then this column will never resize. (If there is another component with a positiv xWeight the column can get larger than the preferred component width and the component is aligned using it's xAlign value.
The default value for both weights is 0.


If a value is not specified (but the default is used), then all following values must not be specified also, i.e. the format is:
"x y [width height [xAlign yAlign [xWeight yWeight]]]"


Example:
The container has three rows and two columns. The first row contains a label that should never resize, but always get its preferred size. It is followed by a text field that should expand horizontally only.
The second row contains a long label that spans both columns and also always gets its preferred size. The third row contains a text area that also spans both columns, but expands both horizontally and vertically:
panel.add(fieldLabel, "0 0");top-left, use defaults for other values (i.e. width, height = 1, align to left and top, weights = 0)
panel.add(textField, "+ . 1 1 fill top 1 0");next x, same y, width and height = 1, fill horizontally, align to top, column weight = 1, row weight = 0
panel.add(areaLabel, "0 + 2 1");x = 0, next y, width = 2, height = 1 (align left and top, weights = 0)
panel.add(textArea, "0 + 2 1 fill fill 1 1");x = 0, next y, weidth = 2, height = 1, fill both horizontally and vertically, weights = 1

Features that are currently not supported:

Copyright: Copyright (c) 2002

See also:
java.awt.GridBagLayout


 Inner Classifier Summary
private static   XTableLayout.ComponentInfo
Stores each component's constraints, minimum, maximum and preferred sizes, to avoid re-query at each layout  
arrow_up
 

 Attribute Summary
private int  _columnCount
number of columns in the layout. 
private boolean[]  _columnHasGap
_columnHasGap[i] means there should be a gap of xGap pixels _after_ column i. 
private boolean  _dirtySizesComponents
flag to indicate that minimum and preferred column widths and row heights have to be recalculated before layout. 
private boolean  _dirtySizesRowsColumns
flag to indicate that every component's minimum, preferred and maximum size has to be re-queried before layout. 
private boolean  _dirtyWeightsAndGaps
flag to indicate that weights and gaps have to be recalculated before layout. 
private Map  _infosByComponent
maps a component to its info object  
private int  _lastHeight
height of the last added component, used when the next component specifies NEXT as its y value  
private int  _lastWidth
width of the last added component, used when the next component specifies NEXT as its x value  
private int  _lastX
x coordinate of the last added component, used when the next component specifies SAME or NEXT as its x value  
private int  _lastY
y coordinate of the last added component, used when the next component specifies SAME or NEXT as its y value  
private int  _minimumColumnWidthTotal
sum of all minimum column widths  
private int[]  _minimumColumnWidths
each column's minimum width, will be the maximum of all minimum widths of components in that column. 
private int  _minimumRowHeightTotal
sum of all minimum row heights  
private int[]  _minimumRowHeights
each row's minimum height, will be the maximum of all minimum heights of components in that row. 
private int  _preferredColumnWidthTotal
sum of all preferred column widths  
private int[]  _preferredColumnWidths
each column's preferred width, will be the maximum of all preferred widths of components in that column. 
private int  _preferredRowHeightTotal
sum of all preferred row heights  
private int[]  _preferredRowHeights
each row's preferred height, will be the maximum of all preferred heights of components in that row. 
private boolean  _reportMinimumSizeAsPreferred
if true the layout manager will report the container's minimum size as its preferred size, useful when the container is in a scoll pane  
private int  _rowCount
number of rows in the layout. 
private boolean[]  _rowHasGap
_rowHasGap[i] means there should be a gap of yGap pixels _after_ row i. 
private List  _rows
list of rows, each row is itself a list of component infos  
private int  _xGap
gap in pixels between columns, will not be applied to the outer sides of the container  
private int  _xGapTotal
total amount of column gap for the current layout. 
private double  _xWeightTotal
the sum of all column weights. 
private double[]  _xWeights
(absolute) weight of each column  
private int  _yGap
gap in pixels between rows, will not be applied to the outer sides of the container  
private int  _yGapTotal
total amount of row gap for the current layout. 
private double  _yWeightTotal
the sum of all row weights. 
private double[]  _yWeights
(absolute) weight of each row  
arrow_up
 

 Association Summary
private Container  _container
the container to be laid out, will be set when the first component is added or the container is laid out. 
arrow_up
 

 Constructor Summary
public   XTableLayout()
Construct a table layout that has no gaps between rows or columns and returns the 'real' preferred size  
public   XTableLayout(boolean reportMinimumSizeAsPreferred)
Construct a table layout that has no gaps between rows or columns. 
public   XTableLayout(int xGap, int yGap)
Construct a table layout that has the given gaps between rows and columns and returns the 'real' preferred size. 
public   XTableLayout(int xGap, int yGap, boolean reportMinimumSizeAsPreferred)
Construct a table layout that has the given gaps between rows and columns. 
arrow_up
 

 Method Summary
public void   addLayoutComponent(String constraintText, Component comp)
Convenience method for adding a component. 
public void   addLayoutComponent(Component component, Object constraintObject)
Adds the specified component to the layout, using the specified constraint object. 
private void   checkContainer(Container target)
Ensures that a single XTableLayout instance is used with a single container only: Will throw an IllegaArgumentException if called with another container  
public float   getLayoutAlignmentX(Container target)
Returns the alignment along the x axis. 
public float   getLayoutAlignmentY(Container target)
Returns the alignment along the y axis. 
public void   invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. 
public void   layoutContainer(Container parent)
Lays out the specified container. 
public Dimension   maximumLayoutSize(Container parent)
Calculates the maximum size for the specified container, given the components it contains. 
public Dimension   minimumLayoutSize(Container parent)
Calculates the minimum size for the specified container, given the components it contains. 
public Dimension   preferredLayoutSize(Container parent)
Calculates the preferred size for the specified container, given the components it contains. 
private void   refreshSizes()
Updates minimum and preferred column widths and row heights and total minimum and preferred width and height. 
private void   refreshWeightsAndGaps()
Ensure that the currently cached column and row weights and gaps are up-to-date. 
public void   removeLayoutComponent(Component component)
Removes the specified component from the layout. 
private void   setDirtySizes()
 
private void   setDirtyWeightsAndGaps()
Called whenever a component is added or removed  
arrow_up
 

Tagged Values
static false
gentleware-imported-line-number 89
gentleware-imported-package-statement-line-number 1
 

 Inner Classifier Detail

XTableLayout.ComponentInfo

private static  XTableLayout.ComponentInfo

Stores each component's constraints, minimum, maximum and preferred sizes, to avoid re-query at each layout  
arrow_up
 Attribute Detail

_columnCount

private int _columnCount

number of columns in the layout. Includes empty columns. Will never shrink if components are removed.  
arrow_up


_columnHasGap

private boolean[] _columnHasGap

_columnHasGap[i] means there should be a gap of xGap pixels _after_ column i. There won't be a gap, if no component ends in that column.  
arrow_up


_dirtySizesComponents

private boolean _dirtySizesComponents

flag to indicate that minimum and preferred column widths and row heights have to be recalculated before layout. Set whenever a component is added or removed or when invalidate() is called.  
arrow_up


_dirtySizesRowsColumns

private boolean _dirtySizesRowsColumns

flag to indicate that every component's minimum, preferred and maximum size has to be re-queried before layout. Set whenever invalidate() is called.  
arrow_up


_dirtyWeightsAndGaps

private boolean _dirtyWeightsAndGaps

flag to indicate that weights and gaps have to be recalculated before layout. Set whenever a component is added or removed.  
arrow_up


_infosByComponent

private Map _infosByComponent

maps a component to its info object  
arrow_up


_lastHeight

private int _lastHeight

height of the last added component, used when the next component specifies NEXT as its y value  
arrow_up


_lastWidth

private int _lastWidth

width of the last added component, used when the next component specifies NEXT as its x value  
arrow_up


_lastX

private int _lastX

x coordinate of the last added component, used when the next component specifies SAME or NEXT as its x value  
arrow_up


_lastY

private int _lastY

y coordinate of the last added component, used when the next component specifies SAME or NEXT as its y value  
arrow_up


_minimumColumnWidthTotal

private int _minimumColumnWidthTotal

sum of all minimum column widths  
arrow_up


_minimumColumnWidths

private int[] _minimumColumnWidths

each column's minimum width, will be the maximum of all minimum widths of components in that column. a component that spans multiple columns contributes to each column's minimum width proportionally to the weight of the column in respect to the sum of the weights of all spanned columns.  
arrow_up


_minimumRowHeightTotal

private int _minimumRowHeightTotal

sum of all minimum row heights  
arrow_up


_minimumRowHeights

private int[] _minimumRowHeights

each row's minimum height, will be the maximum of all minimum heights of components in that row. a component that spans multiple rows contributes to each row's minimum height proportionally to the weight of the row in respect to the sum of the weights of all spanned rows.  
arrow_up


_preferredColumnWidthTotal

private int _preferredColumnWidthTotal

sum of all preferred column widths  
arrow_up


_preferredColumnWidths

private int[] _preferredColumnWidths

each column's preferred width, will be the maximum of all preferred widths of components in that column. a component that spans multiple columns contributes to each column's preferred width proportionally to the weight of the column in respect to the sum of the weights of all spanned columns.  
arrow_up


_preferredRowHeightTotal

private int _preferredRowHeightTotal

sum of all preferred row heights  
arrow_up


_preferredRowHeights

private int[] _preferredRowHeights

each row's preferred height, will be the maximum of all preferred heights of components in that row. a component that spans multiple rows contributes to each row's preferred height proportionally to the weight of the row in respect to the sum of the weights of all spanned rows.  
arrow_up


_reportMinimumSizeAsPreferred

private boolean _reportMinimumSizeAsPreferred

if true the layout manager will report the container's minimum size as its preferred size, useful when the container is in a scoll pane  
arrow_up


_rowCount

private int _rowCount

number of rows in the layout. Includes empty rows. Will never shrink if components are removed.  
arrow_up


_rowHasGap

private boolean[] _rowHasGap

_rowHasGap[i] means there should be a gap of yGap pixels _after_ row i. There won't be a gap if no component ends in that row.  
arrow_up


_rows

private List _rows

list of rows, each row is itself a list of component infos  
arrow_up


_xGap

private int _xGap

gap in pixels between columns, will not be applied to the outer sides of the container  
arrow_up


_xGapTotal

private int _xGapTotal

total amount of column gap for the current layout. Can be different from _columnCount * _xGap, because there will be no gap when a column is empty or contains spanning components only.  
arrow_up


_xWeightTotal

private double _xWeightTotal

the sum of all column weights. Used to calculate each column's relative weight  
arrow_up


_xWeights

private double[] _xWeights

(absolute) weight of each column  
arrow_up


_yGap

private int _yGap

gap in pixels between rows, will not be applied to the outer sides of the container  
arrow_up


_yGapTotal

private int _yGapTotal

total amount of row gap for the current layout. Can be different from _rowCount * _yGap, because there will be no gap when a row is empty or contains spanning components only.  
arrow_up


_yWeightTotal

private double _yWeightTotal

the sum of all row weights. Used to calculate each row's relative weight  
arrow_up


_yWeights

private double[] _yWeights

(absolute) weight of each row  
arrow_up
 Association Detail

_container

private Container _container

the container to be laid out, will be set when the first component is added or the container is laid out.  
arrow_up
 Constructor Detail

XTableLayout

public com.gentleware.services.swingx.XTableLayout XTableLayout()


Construct a table layout that has no gaps between rows or columns and returns the 'real' preferred size  
Returns:
arrow_up


XTableLayout

public com.gentleware.services.swingx.XTableLayout XTableLayout(boolean reportMinimumSizeAsPreferred)


Construct a table layout that has no gaps between rows or columns.  
Parameters:
reportMinimumSizeAsPreferred - Should the layout use components' minimum sizes to compute its containers preferred size. This can make sense if the container is embedded in a scroll pane.
Returns:
arrow_up


XTableLayout

public com.gentleware.services.swingx.XTableLayout XTableLayout(int xGap, int yGap)


Construct a table layout that has the given gaps between rows and columns and returns the 'real' preferred size.  
Parameters:
xGap - pixels between columns, is not applied to the left and right outer sides
yGap - pixels between rows, is not applied to the top and bottom outer sides
Returns:
arrow_up


XTableLayout

public com.gentleware.services.swingx.XTableLayout XTableLayout(int xGap, int yGap, boolean reportMinimumSizeAsPreferred)


Construct a table layout that has the given gaps between rows and columns.  
Parameters:
xGap - pixels between columns, is not applied to the left and right outer sides
yGap - pixels between rows, is not applied to the top and bottom outer sides
reportMinimumSizeAsPreferred - Should the layout use components' minimum sizes to compute its containers preferred size. This can make sense if the container is embedded in a scroll pane.
Returns:
arrow_up
 Method Detail

addLayoutComponent

public void addLayoutComponent(String constraintText, Component comp)


Convenience method for adding a component. The XTableConstraints(String) constructor is called with the given text and the component is added to the layout with the resulting constraints object.  
Parameters:
constraintText - the string that describes the constraints to be associated with the component
comp - the component to be added
See also:
XTableConstraints#XTableConstraints(String)
arrow_up


addLayoutComponent

public void addLayoutComponent(Component component, Object constraintObject)


Adds the specified component to the layout, using the specified constraint object.  
Parameters:
component - the component to be added
constraintObject - where/how the component is added to the layout.
arrow_up


checkContainer

private void checkContainer(Container target)


Ensures that a single XTableLayout instance is used with a single container only: Will throw an IllegaArgumentException if called with another container  
Parameters:
target -
arrow_up


getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)


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:
target -
Returns:
arrow_up


getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)


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:
target -
Returns:
arrow_up


invalidateLayout

public void invalidateLayout(Container target)


Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.  
Parameters:
target -
arrow_up


layoutContainer

public void layoutContainer(Container parent)


Lays out the specified container.  
Parameters:
parent - the container to be laid out, must always be the same container
arrow_up


maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)


Calculates the maximum size for the specified container, given the components it contains.  
Parameters:
parent - the container to be laid out, must always be the same container
Returns:
arrow_up


minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)


Calculates the minimum size for the specified container, given the components it contains.  
Parameters:
parent - the container to be laid out, must always be the same container
Returns:
arrow_up


preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)


Calculates the preferred size for the specified container, given the components it contains.  
Parameters:
parent - the container to be laid out, must always be the same container
Returns:
arrow_up


refreshSizes

private void refreshSizes()


Updates minimum and preferred column widths and row heights and total minimum and preferred width and height.  
arrow_up


refreshWeightsAndGaps

private void refreshWeightsAndGaps()


Ensure that the currently cached column and row weights and gaps are up-to-date.  
arrow_up


removeLayoutComponent

public void removeLayoutComponent(Component component)


Removes the specified component from the layout.  
Parameters:
component - the component to be removed
arrow_up


setDirtySizes

private void setDirtySizes()

arrow_up


setDirtyWeightsAndGaps

private void setDirtyWeightsAndGaps()


Called whenever a component is added or removed  
arrow_up
Created  2004 - 12 - 1

    Poseidon for UMLTM
  UMLdoc
 PREV  CLASSIFIER    NEXT  CLASSIFIER     FRAMES    NO FRAMES      
SUMMARY:   INNER | ATTR | ASSOC | CONSTR | METHOD     DETAIL:   INNER | ATTR | ASSOC | CONSTR | METHOD     DIAGRAMS:   COLLAB | SEQ | STATE | ACTIV

Generated with Poseidon for UMLTM.
Poseidon is a registered trademark of Gentleware AG in Germany, USA and other countries. Copyright 2003-2004 Gentleware AG, Schanzenstr. 70, 20357 Hamburg, Germany. All Rights Reserved.

UML is a trademark or registered trademark of Object Management Group, Inc. in the U.S. and other countries.