javax.swing.table

Class DefaultTableColumnModel

Implemented Interfaces:
EventListener, ListSelectionListener, PropertyChangeListener, Serializable, TableColumnModel

public class DefaultTableColumnModel
extends Object
implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable

DefaultTableColumnModel
See Also:
Serialized Form

Field Summary

protected ChangeEvent
changeEvent
changeEvent is fired when change occurs in one of the columns properties
protected int
columnMargin
Space between two columns.
protected boolean
columnSelectionAllowed
Indicates whether columns can be selected
protected EventListenerList
listenerList
listenerList keeps track of all listeners registered with this model
protected ListSelectionModel
selectionModel
Selection Model that keeps track of columns selection
protected Vector
tableColumns
Columns that this model keeps track of.
protected int
totalColumnWidth
Total width of all the columns in this model

Constructor Summary

DefaultTableColumnModel()
Constructor DefaultTableColumnModel

Method Summary

void
addColumn(TableColumn col)
addColumn adds column to the model.
void
addColumnModelListener(TableColumnModelListener listener)
addColumnModelListener adds specified listener to the model's listener list
protected ListSelectionModel
createSelectionModel()
createSelectionModel creates selection model that will keep track of currently selected column(s)
protected void
fireColumnAdded(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was added
protected void
fireColumnMarginChanged()
fireColumnMarginChanged fires TableColumnModelEvent to model's registered TableColumnModelListeners to indicate that column margin was changed.
protected void
fireColumnMoved(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was moved
protected void
fireColumnRemoved(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was removed
protected void
fireColumnSelectionChanged(ListSelectionEvent evt)
fireColumnSelectionChanged fires TableColumnModelEvent to model's registered TableColumnModelListeners to indicate that different column was selected.
TableColumn
getColumn(int i)
getColumn returns column at the specified index
int
getColumnCount()
getColumnCount returns number of columns in the model
int
getColumnIndex(Object identifier)
Returns the index of the TableColumn with the given identifier.
int
getColumnIndexAtX(int x)
getColumnIndexAtX returns column that contains specified x-coordinate.
int
getColumnMargin()
getColumnMargin returns column margin
TableColumnModelListener[]
getColumnModelListeners()
boolean
getColumnSelectionAllowed()
getColumnSelectionAllowed indicates whether column selection is allowed or not.
Enumeration
getColumns()
getColumns
EventListener[]
getListeners(Class listenerType)
getListeners returns currently registered listeners with this model.
int
getSelectedColumnCount()
getSelectedColumnCount returns number of currently selected columns
int[]
getSelectedColumns()
getSelectedColumns returns array containing indexes of currently selected columns
ListSelectionModel
getSelectionModel()
getSelectionModel returns selection model
int
getTotalColumnWidth()
getTotalColumnWidth returns total width of all the columns including column's margins.
void
moveColumn(int i, int j)
moveColumn moves column at index i to index j.
void
propertyChange(PropertyChangeEvent evt)
propertyChange handles changes occuring in the properties of the model's columns.
protected void
recalcWidthCache()
recalcWidthCache calculates total width of the columns.
void
removeColumn(TableColumn col)
removeColumn removes table column from the model.
void
removeColumnModelListener(TableColumnModelListener listener)
removeColumnModelListener removes specified listener from the model's listener list.
void
setColumnMargin(int m)
setColumnMargin sets margin of the columns.
void
setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed sets whether column selection is allowed or not.
void
setSelectionModel(ListSelectionModel model)
setSelectionModel sets selection model that will be used by this ColumnTableModel to keep track of currently selected columns
void
valueChanged(ListSelectionEvent e)
valueChanged handles changes in the selectionModel.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

changeEvent

protected ChangeEvent changeEvent
changeEvent is fired when change occurs in one of the columns properties

columnMargin

protected int columnMargin
Space between two columns. By default it is set to 1

columnSelectionAllowed

protected boolean columnSelectionAllowed
Indicates whether columns can be selected

listenerList

protected EventListenerList listenerList
listenerList keeps track of all listeners registered with this model

selectionModel

protected ListSelectionModel selectionModel
Selection Model that keeps track of columns selection

tableColumns

protected Vector tableColumns
Columns that this model keeps track of.

totalColumnWidth

protected int totalColumnWidth
Total width of all the columns in this model

Constructor Details

DefaultTableColumnModel

public DefaultTableColumnModel()
Constructor DefaultTableColumnModel

Method Details

addColumn

public void addColumn(TableColumn col)
addColumn adds column to the model. This method fires ColumnAdded event to model's registered TableColumnModelListeners.
Specified by:
addColumn in interface TableColumnModel
Parameters:
col - column to add

addColumnModelListener

public void addColumnModelListener(TableColumnModelListener listener)
addColumnModelListener adds specified listener to the model's listener list
Specified by:
addColumnModelListener in interface TableColumnModel
Parameters:
listener - the listener to add

createSelectionModel

protected ListSelectionModel createSelectionModel()
createSelectionModel creates selection model that will keep track of currently selected column(s)
Returns:
ListSelectionModel selection model of the columns

fireColumnAdded

protected void fireColumnAdded(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was added
Parameters:
e - TableColumnModelEvent

fireColumnMarginChanged

protected void fireColumnMarginChanged()
fireColumnMarginChanged fires TableColumnModelEvent to model's registered TableColumnModelListeners to indicate that column margin was changed.

fireColumnMoved

protected void fireColumnMoved(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was moved
Parameters:
e - TableColumnModelEvent

fireColumnRemoved

protected void fireColumnRemoved(TableColumnModelEvent e)
fireColumnAdded fires TableColumnModelEvent to registered TableColumnModelListeners to indicate that column was removed
Parameters:
e - TableColumnModelEvent

fireColumnSelectionChanged

protected void fireColumnSelectionChanged(ListSelectionEvent evt)
fireColumnSelectionChanged fires TableColumnModelEvent to model's registered TableColumnModelListeners to indicate that different column was selected.
Parameters:
evt - ListSelectionEvent

getColumn

public TableColumn getColumn(int i)
getColumn returns column at the specified index
Specified by:
getColumn in interface TableColumnModel
Parameters:
i - index of the column
Returns:
TableColumn column at the specified index

getColumnCount

public int getColumnCount()
getColumnCount returns number of columns in the model
Specified by:
getColumnCount in interface TableColumnModel
Returns:
int number of columns in the model

getColumnIndex

public int getColumnIndex(Object identifier)
Returns the index of the TableColumn with the given identifier.
Specified by:
getColumnIndex in interface TableColumnModel
Parameters:
identifier - the identifier (null not permitted).
Returns:
The index of the TableColumn with the given identifier.
Throws:
IllegalArgumentException - if identifier is null or there is no column with that identifier.

getColumnIndexAtX

public int getColumnIndexAtX(int x)
getColumnIndexAtX returns column that contains specified x-coordinate.
Specified by:
getColumnIndexAtX in interface TableColumnModel
Parameters:
x - x-coordinate that column should contain
Returns:
int index of the column that contains specified x-coordinate relative to this column model

getColumnMargin

public int getColumnMargin()
getColumnMargin returns column margin
Specified by:
getColumnMargin in interface TableColumnModel
Returns:
int column margin

getColumnModelListeners

public TableColumnModelListener[] getColumnModelListeners()
Since:
1.4

getColumnSelectionAllowed

public boolean getColumnSelectionAllowed()
getColumnSelectionAllowed indicates whether column selection is allowed or not.
Specified by:
getColumnSelectionAllowed in interface TableColumnModel
Returns:
boolean true if column selection is allowed and false otherwise.

getColumns

public Enumeration getColumns()
getColumns
Specified by:
getColumns in interface TableColumnModel
Returns:
Enumeration

getListeners

public EventListener[] getListeners(Class listenerType)
getListeners returns currently registered listeners with this model.
Parameters:
listenerType - type of listeners to return
Returns:
EventListener[] array of model's listeners of the specified type

getSelectedColumnCount

public int getSelectedColumnCount()
getSelectedColumnCount returns number of currently selected columns
Specified by:
getSelectedColumnCount in interface TableColumnModel
Returns:
int number of currently selected columns

getSelectedColumns

public int[] getSelectedColumns()
getSelectedColumns returns array containing indexes of currently selected columns
Specified by:
getSelectedColumns in interface TableColumnModel
Returns:
int[] array containing indexes of currently selected columns

getSelectionModel

public ListSelectionModel getSelectionModel()
getSelectionModel returns selection model
Specified by:
getSelectionModel in interface TableColumnModel
Returns:
ListSelectionModel selection model

getTotalColumnWidth

public int getTotalColumnWidth()
getTotalColumnWidth returns total width of all the columns including column's margins.
Specified by:
getTotalColumnWidth in interface TableColumnModel
Returns:
total width of all the columns

moveColumn

public void moveColumn(int i,
                       int j)
moveColumn moves column at index i to index j. This method fires ColumnMoved event to model's registered TableColumnModelListeners.
Specified by:
moveColumn in interface TableColumnModel
Parameters:
i - index of the column that will be moved
j - index of column's new location

propertyChange

public void propertyChange(PropertyChangeEvent evt)
propertyChange handles changes occuring in the properties of the model's columns.
Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - PropertyChangeEvent

recalcWidthCache

protected void recalcWidthCache()
recalcWidthCache calculates total width of the columns. If the current cache of the total width is in invalidated state, then width is recalculated. Otherwise nothing is done.

removeColumn

public void removeColumn(TableColumn col)
removeColumn removes table column from the model. This method fires ColumnRemoved event to model's registered TableColumnModelListeners.
Specified by:
removeColumn in interface TableColumnModel
Parameters:
col - column to be removed

removeColumnModelListener

public void removeColumnModelListener(TableColumnModelListener listener)
removeColumnModelListener removes specified listener from the model's listener list.
Specified by:
removeColumnModelListener in interface TableColumnModel
Parameters:
listener - the listener to remove

setColumnMargin

public void setColumnMargin(int m)
setColumnMargin sets margin of the columns.
Specified by:
setColumnMargin in interface TableColumnModel
Parameters:
m - new column margin

setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed sets whether column selection is allowed or not.
Specified by:
setColumnSelectionAllowed in interface TableColumnModel
Parameters:
flag - true if column selection is allowed and false otherwise

setSelectionModel

public void setSelectionModel(ListSelectionModel model)
setSelectionModel sets selection model that will be used by this ColumnTableModel to keep track of currently selected columns
Specified by:
setSelectionModel in interface TableColumnModel
Parameters:
model - new selection model
Throws:
IllegalArgumentException - if model is null

valueChanged

public void valueChanged(ListSelectionEvent e)
valueChanged handles changes in the selectionModel.
Specified by:
valueChanged in interface ListSelectionListener
Parameters:
e - ListSelectionEvent

DefaultTableColumnModel.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.