de.mguennewig.pobjsearch
Class ToggleColumnAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by de.mguennewig.pobjsearch.ToggleColumnAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action

public final class ToggleColumnAction
extends javax.swing.AbstractAction

Action to toggle the visibility of a table column.

The visibility is toggled by removing/adding it from/to the table column model.

This action is enabled by default unless it is associated to the last visible column to prevent the table header to become invisible.

Serializable

Instances of this action are only serializable if the column model and the column name instance are serializable. In most cases this should be the case as the column name object is normally a string and the default column model is serializable.

Author:
Michael Günnewig
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
ToggleColumnAction(int modelIndex, javax.swing.table.TableColumnModel model, java.lang.Object columnName)
          Creates a new toggle column action.
ToggleColumnAction(javax.swing.table.TableModel tableModel, int modelIndex, javax.swing.table.TableColumnModel model)
          Creates a new toggle column action.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
           
static int getColumnIndex(javax.swing.table.TableColumnModel columnModel, java.lang.Object columnName)
          A simple wrapper around TableColumnModel.getColumnIndex(Object) to catch the stupid exception and return -1 instead.
static boolean isColumnVisible(javax.swing.table.TableColumnModel columnModel, java.lang.Object columnName)
          Tests whether a named column exists in the column model.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToggleColumnAction

public ToggleColumnAction(int modelIndex,
                          javax.swing.table.TableColumnModel model,
                          java.lang.Object columnName)
Creates a new toggle column action.

Parameters:
modelIndex - Index of the column within the TableModel used by the table whose column model we modify.
model - The column model which should be manipulated.
columnName - The name of the column whose visibility should be toggled.

ToggleColumnAction

public ToggleColumnAction(javax.swing.table.TableModel tableModel,
                          int modelIndex,
                          javax.swing.table.TableColumnModel model)
Creates a new toggle column action.

Parameters:
tableModel - The table model.
modelIndex - Index of the column within the TableModel used by the table whose column model we modify.
model - The column model which should be manipulated.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)

getColumnIndex

public static int getColumnIndex(javax.swing.table.TableColumnModel columnModel,
                                 java.lang.Object columnName)
A simple wrapper around TableColumnModel.getColumnIndex(Object) to catch the stupid exception and return -1 instead.


isColumnVisible

public static boolean isColumnVisible(javax.swing.table.TableColumnModel columnModel,
                                      java.lang.Object columnName)
Tests whether a named column exists in the column model.

See Also:
getColumnIndex(TableColumnModel,Object)