de.tkuhn.swing.table
Class ColumnStateTableColumnModel

java.lang.Object
  extended by javax.swing.table.DefaultTableColumnModel
      extended by de.tkuhn.swing.table.ColumnStateTableColumnModel
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.ListSelectionListener, javax.swing.table.TableColumnModel

public class ColumnStateTableColumnModel
extends javax.swing.table.DefaultTableColumnModel

This implementation of TableColumnModel provides the ability of hiding and unhiding table columns from display using a contextual menu of the table header. It also offers support for preserving column state such as size, position and hiding state over changes of TableModel in a JTable by providing objects that represent a distinct state that can be reset lateron. If you use JUserFriendlyTable you should not need to use this class.

Version:
0.9.3
Author:
Tilmann Kuhn
See Also:
JUserFriendlyTable, TableColumnModel, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
 
Constructor Summary
ColumnStateTableColumnModel()
          Creates a new instance of RememberingTableColumnModel
 
Method Summary
 void addColumn(javax.swing.table.TableColumn aColumn)
          This should not be called by a user directly!
protected  ColumnState getColumnState(java.lang.Object colId)
          Get the state for a single column in this model
 java.lang.Object getState()
          Creates a Memento of the state of this column model.
 void hideColumn(java.lang.Object colId)
          Hide a column and set the state of the popup menu
 void installPopup(javax.swing.JTable table)
          Install the popup menu used by this column model for column hiding on a JTable
 void removeColumn(javax.swing.table.TableColumn aColumn)
          This should not be called by a user directly!
protected  void setColumnState(ColumnState colState)
          Resets the state of a single column in this model
 boolean setState(java.lang.Object aState)
          Resets this column model to the given state if the column structure is similar to the one present while getState() was called.
 void showAllColumns()
          Show all hidden columns
 void showColumn(java.lang.Object colId)
          Show a previously hidden column and set the state of the popup menu
 void uninstallPopup(javax.swing.JTable table)
          Remove the popup menu installed by this instance from the table
 
Methods inherited from class javax.swing.table.DefaultTableColumnModel
addColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColumnStateTableColumnModel

public ColumnStateTableColumnModel()
Creates a new instance of RememberingTableColumnModel

Method Detail

getState

public java.lang.Object getState()
Creates a Memento of the state of this column model. This can be used for a restoration of the State.

Returns:
an Object that represents the state of the table columns and implements the Serializable interface. It can also be saved using the XMLEncoder
See Also:
Serializable, XMLEncoder

setState

public boolean setState(java.lang.Object aState)
Resets this column model to the given state if the column structure is similar to the one present while getState() was called. This method must be called with a state object obtained by getState().

Parameters:
aState - the state to set.
Returns:
true if column structure was similar and state has been reseted
See Also:
getState()

getColumnState

protected ColumnState getColumnState(java.lang.Object colId)
Get the state for a single column in this model

Parameters:
colId - the identifier of the column
Returns:
the memento object

setColumnState

protected void setColumnState(ColumnState colState)
Resets the state of a single column in this model

Parameters:
colState - the state to be established

installPopup

public void installPopup(javax.swing.JTable table)
Install the popup menu used by this column model for column hiding on a JTable

Parameters:
table - the table to install the popup on

uninstallPopup

public void uninstallPopup(javax.swing.JTable table)
Remove the popup menu installed by this instance from the table

Parameters:
table - the table to remove the popup from

hideColumn

public void hideColumn(java.lang.Object colId)
Hide a column and set the state of the popup menu

Parameters:
colId - the column identifier

showColumn

public void showColumn(java.lang.Object colId)
Show a previously hidden column and set the state of the popup menu

Parameters:
colId - the column identifier

showAllColumns

public void showAllColumns()
Show all hidden columns


addColumn

public void addColumn(javax.swing.table.TableColumn aColumn)
This should not be called by a user directly! Implementation of addColumn(column) in the TableColumnModel interface. Adds a column to this column model and creates an item in the popup menu for hiding

Specified by:
addColumn in interface javax.swing.table.TableColumnModel
Overrides:
addColumn in class javax.swing.table.DefaultTableColumnModel
Parameters:
aColumn - the column to be added

removeColumn

public void removeColumn(javax.swing.table.TableColumn aColumn)
This should not be called by a user directly! Implementation of removeColumn(column) in the TableColumnModel interface. Removes a column from this column model and its corresponding item in the popup menu

Specified by:
removeColumn in interface javax.swing.table.TableColumnModel
Overrides:
removeColumn in class javax.swing.table.DefaultTableColumnModel
Parameters:
aColumn - the column to be removed


Copyright © Tilmann Kuhn