at.spardat.xma.mdl.table
Class TableLayoutManager

java.lang.Object
  extended byat.spardat.xma.mdl.table.TableLayoutManager
All Implemented Interfaces:
org.eclipse.swt.events.ControlListener, java.util.EventListener, org.eclipse.swt.internal.SWTEventListener

public class TableLayoutManager
extends java.lang.Object
implements org.eclipse.swt.events.ControlListener

TableLayoutManager implements a more sophisticated Layout for Table columns than just column widths.
For each column the follwing can be defined:

Only the absolut width or a percentage may be specified for each individual column.
Everytime, the table is resized, this information is used to calculate new widths of the columns. If the end user resizes a comlumn header via the GUI, the absolute width or percentage is ajusted automatically. If the end user violates the minimum or maximum, the respective limit is ajusted, too. Only the minLimit is enforced to prevent the user from completly removing a column.

A default width for columns without absolut width or percentage definition may be defined. Default minimum and maximun width for columns without individal limits may be defined, too.
One column may be specified to strech over the rest of the table width. Its absolute width or percentage is ignored. Only its limits are respected.


Field Summary
static int ABSOLUT
          Use the currend width of the table as it's absolut width.
static int MAX
          Use the currend width of the table as it's maximum width.
static int MIN
          Use the currend width of the table as it's minimum width.
static int NONE
          Use no information from the table.
static int PERCENT
          Calculate the percentage of the column based on its current width and the current width of the table.
 
Constructor Summary
TableLayoutManager()
           
 
Method Summary
 void addColumn(int column)
          Adds a column to the TableLayoutManager.
 void columnResized(org.eclipse.swt.widgets.TableColumn column)
          Listener method called by SWT every time a column is resized via the GUI.
 void controlMoved(org.eclipse.swt.events.ControlEvent e)
          Listener method called by SWT every time the table is moved.
 void controlResized(org.eclipse.swt.events.ControlEvent e)
          Listener method called by SWT every time the table or a column is resized.
 int getAbsolutWidth(int column)
          Get the absolute width of the given column in pixel.
 int getDefaultAbsolutWidth()
          Get the default absolute width.
 int getDefaultMaxWidth()
          Get the default maximum width.
 int getDefaultMinWidth()
          Get the default minimum width.
 int getMaxWidth(int column)
          Get the maximum width of the given column in pixel.
 int getMinLimit()
          Return the lower limit for all column widths.
 int getMinWidth(int column)
          Get the minimum width of the given column in pixel.
 float getPercent(int column)
          Get the percentage of the given column.
static int getTableClientWidth(org.eclipse.swt.widgets.Table table)
          Get the width of the client area of the given table.
 void layout()
          Recalculate the width of all columns according to the layout information of this TableLayoutManager.
 void layout(boolean force)
          Recalculate the width of all columns according to the layout information of this TableLayoutManager.
 void manageTable(org.eclipse.swt.widgets.Table table, int take)
          Attaches the TableLayoutManager to an SWT-Table.
 void recalcLayoutInfoFromTable(int take)
          Recalculates all layout informations from the current width of the columns of the attached table.
 void removeColumn(int column)
          Removes a column to the TableLayoutManager.
 void scaleAllPercents(float factor)
          Scale the percentages of all columns by the given factor
 void setAbsolutWidth(int column, int width)
          Set the absolute width of the given column in pixel.
 void setDefaultAbsolutWidth(int defaultAbsolutWidth)
          Set the default absolute width.
 void setDefaultMaxWidth(int defaultMaxWidth)
          Set the default maximum width, used for all columns without individual maximum width.
 void setDefaultMinWidth(int defaultMinWidth)
          Set the default minimum width, used for all columns without individual maximum width.
 void setMaxWidth(int column, int max)
          Set the maximum width of the given column in pixel.
 void setMinLimit(int minLimit)
          Set the lower limit for all column widths.
 void setMinWidth(int column, int min)
          Set the minimum width of the given column in pixel.
 void setPercent(int column, float percent)
          Set the width of the given column in percent of the table width.
 void setStrechColumn(int column)
          Set the column, which should take the whole space of the table which remains after calculating the width of all other columns.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Use no information from the table.

See Also:
Constant Field Values

PERCENT

public static final int PERCENT
Calculate the percentage of the column based on its current width and the current width of the table.

See Also:
Constant Field Values

MIN

public static final int MIN
Use the currend width of the table as it's minimum width.

See Also:
Constant Field Values

MAX

public static final int MAX
Use the currend width of the table as it's maximum width.

See Also:
Constant Field Values

ABSOLUT

public static final int ABSOLUT
Use the currend width of the table as it's absolut width.

See Also:
Constant Field Values
Constructor Detail

TableLayoutManager

public TableLayoutManager()
Method Detail

manageTable

public void manageTable(org.eclipse.swt.widgets.Table table,
                        int take)
Attaches the TableLayoutManager to an SWT-Table. From this time on, the column widths are controled by the TableLayoutManager.

Parameters:
table - to manage
take - defines which layout information should be calculated from the current width of the columns. possible values: PERCENT, MIN, MAX, ABSOLUT. These value may be ored together to take more information.

recalcLayoutInfoFromTable

public void recalcLayoutInfoFromTable(int take)
Recalculates all layout informations from the current width of the columns of the attached table. This method can be used to change from absolute widths to percentages or the other way round. This method is used internally from manageTable(Table, int).

Parameters:
take - defines which layout information should be calculated from the current width of the columns. possible values: PERCENT, MIN, MAX, ABSOLUT. These value may be ored together to take more information.

addColumn

public void addColumn(int column)
Adds a column to the TableLayoutManager. If you add a column to a managed table after calling manageTable(org.eclipse.swt.widgets.Table, int), you have to call this method to inform the TableLayoutManager about the new column.

Parameters:
column - index of the new column in the SWT-Table.

removeColumn

public void removeColumn(int column)
Removes a column to the TableLayoutManager. If you remove a column from a managed table after calling manageTable(org.eclipse.swt.widgets.Table, int), you have to call this method to inform the TableLayoutManager about the removal of the column.

Parameters:
column - index of the column in the SWT-Table.

getPercent

public float getPercent(int column)
Get the percentage of the given column. If no percentage is defined -1 is returned.

Parameters:
column - index of the column in the SWT-Table.

setPercent

public void setPercent(int column,
                       float percent)
Set the width of the given column in percent of the table width. The actual width of the column is ajusted by the TableLayoutManager everytime the table is resized.

Parameters:
column - index of the column in the SWT-Table.
percent - column width/table width * 100
-1 means remove the percentage information.

getMinWidth

public int getMinWidth(int column)
Get the minimum width of the given column in pixel.

Parameters:
column - index of the column in the SWT-Table.

setMinWidth

public void setMinWidth(int column,
                        int min)
Set the minimum width of the given column in pixel.

Parameters:
column - index of the column in the SWT-Table.

getMaxWidth

public int getMaxWidth(int column)
Get the maximum width of the given column in pixel.

Parameters:
column - index of the column in the SWT-Table.

setMaxWidth

public void setMaxWidth(int column,
                        int max)
Set the maximum width of the given column in pixel.

Parameters:
column - index of the column in the SWT-Table.

getAbsolutWidth

public int getAbsolutWidth(int column)
Get the absolute width of the given column in pixel. If no absolute width is defined in the TableLayoutManager, -1 is returned.

Parameters:
column - index of the column in the SWT-Table.

setAbsolutWidth

public void setAbsolutWidth(int column,
                            int width)
Set the absolute width of the given column in pixel. Setting a absolute width of a column, tells the TableLayoutManager to leave the width of the given column unchanged, whenever the table is resized.

Parameters:
column - index of the column in the SWT-Table.
width - fixed witdh of the given column. -1 removes the fixed width information.

setStrechColumn

public void setStrechColumn(int column)
Set the column, which should take the whole space of the table which remains after calculating the width of all other columns.

Parameters:
column - index of the column to strech over the remaining space. -1 means strech no column.

scaleAllPercents

public void scaleAllPercents(float factor)
Scale the percentages of all columns by the given factor

Parameters:
factor - to multiply to all percentages

getMinLimit

public int getMinLimit()
Return the lower limit for all column widths. If the end user ties to resize any column to a smaler width, this column width will be set to minLimit.


setMinLimit

public void setMinLimit(int minLimit)
Set the lower limit for all column widths. If the end user ties to resize any column to a smaler width, this column width will be set to minLimit.


getDefaultAbsolutWidth

public int getDefaultAbsolutWidth()
Get the default absolute width.


setDefaultAbsolutWidth

public void setDefaultAbsolutWidth(int defaultAbsolutWidth)
Set the default absolute width. If set, all columns without absolut width or percentage information get this width. They are not resized if the table is resized.


getDefaultMaxWidth

public int getDefaultMaxWidth()
Get the default maximum width.


setDefaultMaxWidth

public void setDefaultMaxWidth(int defaultMaxWidth)
Set the default maximum width, used for all columns without individual maximum width.


getDefaultMinWidth

public int getDefaultMinWidth()
Get the default minimum width.


setDefaultMinWidth

public void setDefaultMinWidth(int defaultMinWidth)
Set the default minimum width, used for all columns without individual maximum width.


getTableClientWidth

public static int getTableClientWidth(org.eclipse.swt.widgets.Table table)
Get the width of the client area of the given table. This means the width of the table without borders and scrollbars.


layout

public void layout()
Recalculate the width of all columns according to the layout information of this TableLayoutManager. The SWT-columns are resized to the new widths. Same as layout(true).


layout

public void layout(boolean force)
Recalculate the width of all columns according to the layout information of this TableLayoutManager. The SWT-columns are resized to the new widths.

Parameters:
force - if false recalculate the column widths if the table width changed since the last calculation. if true recalculate in any case.

columnResized

public void columnResized(org.eclipse.swt.widgets.TableColumn column)
Listener method called by SWT every time a column is resized via the GUI. The changes made by the end user are reflected in the layout information.

Parameters:
column - which was resized by the GUI

controlMoved

public void controlMoved(org.eclipse.swt.events.ControlEvent e)
Listener method called by SWT every time the table is moved. Does nothing.

Specified by:
controlMoved in interface org.eclipse.swt.events.ControlListener

controlResized

public void controlResized(org.eclipse.swt.events.ControlEvent e)
Listener method called by SWT every time the table or a column is resized. If the table is resized calls {#link #layout(boolean)}. If a column is resized calls {#link #columnResized}.

Specified by:
controlResized in interface org.eclipse.swt.events.ControlListener