Jadex 0.96-beta1

jadex.util.jtable
Class VisibilityTableColumnModel

java.lang.Object
  extended by javax.swing.table.DefaultTableColumnModel
      extended by jadex.util.jtable.VisibilityTableColumnModel
All Implemented Interfaces:
IVisibilityTableColumnModel, PropertyChangeListener, Serializable, EventListener, ListSelectionListener, TableColumnModel

public class VisibilityTableColumnModel
extends DefaultTableColumnModel
implements IVisibilityTableColumnModel

VisibilityTableColumnModel extends the DefaultTableColumnModel . It provides a comfortable way to hide/show columns. Columns keep their positions when hidden and shown again. In order to work with JTable it cannot add any events to TableColumnModelListener. Therefore hiding a column will result in columnRemoved event and showing it again will notify listeners of a columnAdded, and possibly a columnMoved event. For the same reason the following methods still deal with visible columns only: getColumnCount(), getColumns(), getColumnIndex(), getColumn() If you want to take invisible column into account use: getAllColumnCount(), getAllColumns(), getAllColumnIndex(), getAllColumn()

See Also:
DefaultTableColumnModel, Serialized Form

Constructor Summary
VisibilityTableColumnModel()
          Creates an extended table column model.
 
Method Summary
 void addColumn(TableColumn column)
          Appends aColumn to the end of the tableColumns array.
 void addMouseListener(JTable table)
          Helper method that adds a mouselistener to the header of a given JTable.
 TableColumn getAllColumn(int columnIndex)
          Returns the TableColumn object for the column at columnIndex.
 int getAllColumnCount()
          Returns the number of columns in the model.
 int getAllColumnIndex(Object identifier)
          Returns the index of the first column in the table whose identifier is equal to identifier, when compared using equals.
 Enumeration getAllColumns()
          Returns an Enumeration of all the columns in the model.
 boolean isColumnChangeable(TableColumn column)
          Checks whether the specified column can change visibility.
 boolean isColumnVisible(TableColumn aColumn)
          Checks whether the specified column is currently visible.
 void moveColumn(int columnIndex, int newIndex)
          Moves the column and its header at columnIndex to newIndex.
 void removeColumn(TableColumn column)
          Deletes the TableColumn column from the tableColumns array.
 void setAllColumnsVisible()
          Makes all columns in this model visible
 void setColumnChangeable(TableColumn column, boolean changeable)
          Sets whether this column can change visibility.
 void setColumnVisible(TableColumn column, boolean visible)
          Sets the visibility of the specified TableColumn.
 
Methods inherited from class javax.swing.table.DefaultTableColumnModel
addColumnModelListener, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, propertyChange, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VisibilityTableColumnModel

public VisibilityTableColumnModel()
Creates an extended table column model.

Method Detail

addColumn

public void addColumn(TableColumn column)
Appends aColumn to the end of the tableColumns array. This method posts a columnAdded event to its listeners.

Specified by:
addColumn in interface TableColumnModel
Overrides:
addColumn in class DefaultTableColumnModel
Parameters:
column - the TableColumn to be added
See Also:
DefaultTableColumnModel.addColumn(javax.swing.table.TableColumn)

removeColumn

public void removeColumn(TableColumn column)
Deletes the TableColumn column from the tableColumns array. This method will do nothing if column is not in the table's column list. This method posts a columnRemoved event to its listeners.

Specified by:
removeColumn in interface TableColumnModel
Overrides:
removeColumn in class DefaultTableColumnModel
Parameters:
column - the TableColumn to be removed
See Also:
DefaultTableColumnModel.removeColumn(javax.swing.table.TableColumn)

moveColumn

public void moveColumn(int columnIndex,
                       int newIndex)
Moves the column and its header at columnIndex to newIndex. The old column at columnIndex will now be found at newIndex. The column that used to be at newIndex is shifted left or right to make room. This will not move any columns if columnIndex equals newIndex. This method posts a columnMoved event to its listeners.

Specified by:
moveColumn in interface TableColumnModel
Overrides:
moveColumn in class DefaultTableColumnModel
Parameters:
columnIndex - the index of column to be moved
newIndex - index of the column's new location
Throws:
IllegalArgumentException - if columnIndex or newIndex are not in the valid range
See Also:
DefaultTableColumnModel.moveColumn(int, int)

getAllColumnCount

public int getAllColumnCount()
Returns the number of columns in the model.
All columns whether visible or not are taken into account !!!

Specified by:
getAllColumnCount in interface IVisibilityTableColumnModel
Returns:
the number of columns in the model

getAllColumns

public Enumeration getAllColumns()
Returns an Enumeration of all the columns in the model.
All columns whether visible or not are taken into account !!!

Specified by:
getAllColumns in interface IVisibilityTableColumnModel
Returns:
an Enumeration of all the columns in the model

getAllColumnIndex

public int getAllColumnIndex(Object identifier)
Returns the index of the first column in the table whose identifier is equal to identifier, when compared using equals.
All columns whether visible or not are taken into account !!!

Specified by:
getAllColumnIndex in interface IVisibilityTableColumnModel
Parameters:
identifier - the identifier object
Returns:
the index of the first table column whose identifier is equal to identifier
Throws:
IllegalArgumentException - if identifier is null, or no TableColumn has this identifier
See Also:
getAllColumn(int)

getAllColumn

public TableColumn getAllColumn(int columnIndex)
Returns the TableColumn object for the column at columnIndex.
All columns whether visible or not are taken into account !!!

Specified by:
getAllColumn in interface IVisibilityTableColumnModel
Parameters:
columnIndex - the index of the desired column
Returns:
the TableColumn object for the column at columnIndex

setColumnVisible

public void setColumnVisible(TableColumn column,
                             boolean visible)
Sets the visibility of the specified TableColumn. The call is ignored if the TableColumn is not found in this column model or its visibility status did not change. This method posts a columnAdded or columnRemoved event to its listeners.

Specified by:
setColumnVisible in interface IVisibilityTableColumnModel
Parameters:
column - the TableColumn
visible - its new visibility status

setAllColumnsVisible

public void setAllColumnsVisible()
Makes all columns in this model visible

Specified by:
setAllColumnsVisible in interface IVisibilityTableColumnModel
See Also:
isColumnVisible(javax.swing.table.TableColumn), setColumnVisible(javax.swing.table.TableColumn, boolean)

isColumnVisible

public boolean isColumnVisible(TableColumn aColumn)
Checks whether the specified column is currently visible.

Specified by:
isColumnVisible in interface IVisibilityTableColumnModel
Parameters:
aColumn - column to check
Returns:
visibility of specified column. false if there is no such column at all.
See Also:
setAllColumnsVisible(), setColumnVisible(javax.swing.table.TableColumn, boolean)

setColumnChangeable

public void setColumnChangeable(TableColumn column,
                                boolean changeable)
Sets whether this column can change visibility.

Specified by:
setColumnChangeable in interface IVisibilityTableColumnModel
Parameters:
column - the TableColumn
changeable - if true, changing visibility is allowed; otherwise false

isColumnChangeable

public boolean isColumnChangeable(TableColumn column)
Checks whether the specified column can change visibility.

Specified by:
isColumnChangeable in interface IVisibilityTableColumnModel
Parameters:
column - column to check
Returns:
true if the column can change visibility; otherwise false

addMouseListener

public void addMouseListener(JTable table)
Helper method that adds a mouselistener to the header of a given JTable. On right click a popup menu will appear to change the visibility of the columns in the jtable

Parameters:
table - the JTable to add the mouselistener to its header

Jadex 0.96-beta1

Submit a bug or feature
For further API reference and developer documentation, see the Jadex User Guide and the Jadex Tutorial. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, and working code examples.

Copyright (C) 2002-2007 Lars Braubach, Alexander Pokahr - University of Hamburg. Use is subject to license terms.