Class TableColumnWidthController
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.components.tags.table.TableColumnWidthController
-
- All Implemented Interfaces:
TableColumnRecalibrator
,TableColumnWidthCalculator
public final class TableColumnWidthController extends Object implements TableColumnRecalibrator, TableColumnWidthCalculator
A helper class that provides functionality for managing the widths of the columns of a table.
An instance of this class is created and initialized by
TableTag
. It can be used by platform-specific table implementations. It helps storing the column widths of a table and provides some helper methods for calculating widths if columns with a relative width are involved. Because this functionality is not platform-specific it is collected in this helper class.Implementation note: This class is not thread-safe.
- Version:
- $Id: TableColumnWidthController.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
calculateWidths(int totalSize)
Calculates the current widths of all columns managed by this controller.int
getColumnCount()
Returns the number of columns managed by this instance.int
getFixedWidth(int index)
Returns the fixed width (in pixels) of the column with the specified index.int
getNumberOfColumnWithPercentWidth()
Returns the number of columns managed by this controller whose width is specified as a percent value.NumberWithUnit
getOriginalFixedWidth(int index)
Returns the original fixed width of the specified column.int
getPercentValue(int index)
Returns the relative width (in percent) of the column with the specified index.boolean
isPercentWidth(int index)
Tests whether the column with the specified index has a relative width.static TableColumnWidthController
newInstance(TableTag tt)
Creates a new instance ofTableColumnWidthController
and initializes it with the information provided by the givenTableTag
.void
recalibrate(int[] columnSizes)
Recalibrates the internally stored column sizes.void
setFixedWidth(int index, int width)
Sets the fixed width of the column with the specified index (in pixels).
-
-
-
Method Detail
-
newInstance
public static TableColumnWidthController newInstance(TableTag tt) throws FormBuilderException
Creates a new instance ofTableColumnWidthController
and initializes it with the information provided by the givenTableTag
. This factory method first checks whether the widths of the columns managed by the table tag are valid; if not, an exception is thrown. Then an instance is created and initialized with the column widths.- Parameters:
tt
- theTableTag
(must not be null)- Returns:
- a new instance of this class
- Throws:
FormBuilderException
- if the widths of the table's columns are invalidIllegalArgumentException
- if the tag is null
-
getColumnCount
public int getColumnCount()
Returns the number of columns managed by this instance.- Returns:
- the number of columns
-
isPercentWidth
public boolean isPercentWidth(int index)
Tests whether the column with the specified index has a relative width. This means that the width is specified as a percent value.- Parameters:
index
- the index of the column (0-based)- Returns:
- a flag whether this column has a percent width
-
getOriginalFixedWidth
public NumberWithUnit getOriginalFixedWidth(int index)
Returns the original fixed width of the specified column. This is the value defined by thewidth
attribute of the table column tag. If the column in question does not have a fixed width, this method returns null.- Parameters:
index
- the index of the column (0-based)- Returns:
- the original width of this column or null
-
getFixedWidth
public int getFixedWidth(int index)
Returns the fixed width (in pixels) of the column with the specified index. Here the width of the column transformed into pixels is returned. If this column does not have a fixed width, this method returns 0.- Parameters:
index
- the index of the column (0-based)- Returns:
- the fixed width of this column in pixels
-
setFixedWidth
public void setFixedWidth(int index, int width)
Sets the fixed width of the column with the specified index (in pixels). This method is intended to be called by a platform-specific table implementation. When the table is created theNumberWithUnit
values for column widths have to be transformed to pixel values. If later the width of the column changes, this value has to be updated.- Parameters:
index
- the index of the column (0-based)width
- the new fixed width of the column
-
getPercentValue
public int getPercentValue(int index)
Returns the relative width (in percent) of the column with the specified index. If the column in question does not have a percent width, this method returns 0.- Parameters:
index
- the index of the column (0-based)- Returns:
- the width of this column in percent
-
getNumberOfColumnWithPercentWidth
public int getNumberOfColumnWithPercentWidth()
Returns the number of columns managed by this controller whose width is specified as a percent value.- Returns:
- the number of columns with a percent value as width
-
calculateWidths
public int[] calculateWidths(int totalSize)
Calculates the current widths of all columns managed by this controller. The currently available size of the table is specified. This method mainly calculates the widths of columns with a relative width. It sums up the fixed widths and subtracts them from the given total size. The remaining space is used to calculate the absolute widths for columns whose width is specified as a percent value. This implementation evaluates the current widths of columns with fixed or percent widths.- Specified by:
calculateWidths
in interfaceTableColumnWidthCalculator
- Parameters:
totalSize
- the total size available- Returns:
- an array with the widths of all columns
-
recalibrate
public void recalibrate(int[] columnSizes)
Recalibrates the internally stored column sizes. This method is intended to be called if there is an external change in the sizes of the columns managed by this object, for instance if the user manually changed a column width. In this case all current column widths have to be passed to this method. The method then adjusts the sizes of the columns with fixed widths and re-calculates the percent values of the other columns. This implementation adjusts the current width values for columns with a fixed width and recalculates the percent values for the other columns.- Specified by:
recalibrate
in interfaceTableColumnRecalibrator
- Parameters:
columnSizes
- an array with the new sizes of the managed columns
-
-