Class DefaultTableColumnModelExt
- All Implemented Interfaces:
PropertyChangeListener
,Serializable
,EventListener
,ListSelectionListener
,TableColumnModel
,TableColumnModelExt
TableColumnModelExt
.
TODO: explain sub-optimal notification on showing/hiding columns. (hot fixed issues #156, #157. To really do it need enhanced TableColumnModelEvent and -Listeners that are aware of the event.)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
TODO JW: move into propertyChanged! No need for a dedicated listener. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List
<TableColumn> contains a list of all column, in the order they would appear if all were visible.private List
<TableColumn> contains a list of all columns, in the order in which were added to the model.private boolean
flag to distinguish a shown/hidden column from really added/removed columns during notification.Listener attached to TableColumnExt instances to listen for changes to their visibility status, and to hide/show the column as oppropriateFields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addColumn
(TableColumn aColumn) void
Adds a listener for table column model events.protected void
NotifiesTableColumnModelExtListener
s about property changes of contained columns.int
getColumnCount
(boolean includeHidden) Returns the number of contained columns.getColumnExt
(int columnIndex) Returns theTableColumnExt
at view positioncolumnIndex
.getColumnExt
(Object identifier) Returns the firstTableColumnExt
with the givenidentifier
.getColumns
(boolean includeHidden) Returns aList
of containedTableColumn
s.protected EventListenerList
Exposed for testing only - don't use! Will be removed again!boolean
isAddedFromInvisibleEvent
(int newIndex) hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnAdded originated from moving a column from invisible to visible.boolean
isRemovedToInvisibleEvent
(int oldIndex) hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnRemoved originated from moving a column from visible to invisible.void
moveColumn
(int columnIndex, int newIndex) protected void
Update internal state after the visibility of the column was changed to invisible.protected void
Update internal state after the visibility of the column was changed to visible.void
void
removeColumn
(TableColumn column) void
private void
updateCurrentColumns
(int oldIndex, int newIndex) Adjusts the current column sequence when a visible column is moved.Methods inherited from class javax.swing.table.DefaultTableColumnModel
createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, recalcWidthCache, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.swing.table.TableColumnModel
getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumns, getColumnSelectionAllowed, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, setColumnMargin, setColumnSelectionAllowed, setSelectionModel
-
Field Details
-
isVisibilityChange
private boolean isVisibilityChangeflag to distinguish a shown/hidden column from really added/removed columns during notification. This is brittle! -
initialColumns
contains a list of all columns, in the order in which were added to the model. -
currentColumns
contains a list of all column, in the order they would appear if all were visible. -
visibilityListener
Listener attached to TableColumnExt instances to listen for changes to their visibility status, and to hide/show the column as oppropriate
-
-
Constructor Details
-
DefaultTableColumnModelExt
public DefaultTableColumnModelExt()Creates a an empty DefaultTableColumnModelExt.
-
-
Method Details
-
getColumns
Returns aList
of containedTableColumn
s. Includes or excludes invisible columns, depending on whether theincludeHidden
is true or false, respectively. If false, anIterator
over the List is equivalent to theEnumeration
returned bygetColumns()
.NOTE: the order of columns in the List depends on whether or not the invisible columns are included, in the former case it's the insertion order in the latter it's the current order of the visible columns.
- Specified by:
getColumns
in interfaceTableColumnModelExt
- Parameters:
includeHidden
- a boolean to indicate whether invisible columns should be included- Returns:
- a
List
of contained columns.
-
getColumnCount
public int getColumnCount(boolean includeHidden) Returns the number of contained columns. The count includes or excludes invisible columns, depending on whether theincludeHidden
is true or false, respectively. If false, this method returns the same count asgetColumnCount()
.- Specified by:
getColumnCount
in interfaceTableColumnModelExt
- Parameters:
includeHidden
- a boolean to indicate whether invisible columns should be included- Returns:
- the number of contained columns, including or excluding the invisible as specified.
-
getColumnExt
Returns the firstTableColumnExt
with the givenidentifier
. The return value is null if there is no contained column with identifier or if the column withidentifier
is not of typeTableColumnExt
. The returned column may be visible or hidden.- Specified by:
getColumnExt
in interfaceTableColumnModelExt
- Parameters:
identifier
- the object used as column identifier- Returns:
- first
TableColumnExt
with the given identifier or null if none is found
-
getColumnExt
Returns theTableColumnExt
at view positioncolumnIndex
. The return value is null, if the column at positioncolumnIndex
is not of typeTableColumnExt
. The returned column is visible.- Specified by:
getColumnExt
in interfaceTableColumnModelExt
- Parameters:
columnIndex
- the index of the column desired- Returns:
- the
TableColumnExt
object that matches the column index
-
isRemovedToInvisibleEvent
public boolean isRemovedToInvisibleEvent(int oldIndex) hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnRemoved originated from moving a column from visible to invisible.- Parameters:
oldIndex
- the fromIndex of the columnEvent- Returns:
- true if the column was moved to invisible
-
isAddedFromInvisibleEvent
public boolean isAddedFromInvisibleEvent(int newIndex) hot fix for #157: listeners that are aware of the possible existence of invisible columns should check if the received columnAdded originated from moving a column from invisible to visible.- Parameters:
newIndex
- the toIndex of the columnEvent- Returns:
- true if the column was moved to visible
-
removeColumn
Overridden to update internals related to column visibility.
- Specified by:
removeColumn
in interfaceTableColumnModel
- Overrides:
removeColumn
in classDefaultTableColumnModel
-
addColumn
Overridden to update internals related to column visibility.
- Specified by:
addColumn
in interfaceTableColumnModel
- Overrides:
addColumn
in classDefaultTableColumnModel
-
moveColumn
public void moveColumn(int columnIndex, int newIndex) Overridden to update internals related to column visibility.
- Specified by:
moveColumn
in interfaceTableColumnModel
- Overrides:
moveColumn
in classDefaultTableColumnModel
-
updateCurrentColumns
private void updateCurrentColumns(int oldIndex, int newIndex) Adjusts the current column sequence when a visible column is moved.- Parameters:
oldIndex
- the old visible position.newIndex
- the new visible position.
-
moveToInvisible
Update internal state after the visibility of the column was changed to invisible. The given column is assumed to be contained in this model.- Parameters:
col
- the column which was hidden.
-
moveToVisible
Update internal state after the visibility of the column was changed to visible. The given column is assumed to be contained in this model.- Parameters:
col
- the column which was made visible.
-
getEventListenerList
Exposed for testing only - don't use! Will be removed again!- Returns:
- super's listener list
-
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
- Overrides:
propertyChange
in classDefaultTableColumnModel
-
fireColumnPropertyChange
NotifiesTableColumnModelExtListener
s about property changes of contained columns. The event instance is the original as fired by theTableColumn
.- Parameters:
evt
- the event received- See Also:
-
addColumnModelListener
Adds a listener for table column model events. This enhances super's behaviour in that it guarantees to notify listeners of type TableColumnModelListenerExt about property changes of contained columns.Overridden to install enhanced notification of listeners of type. TableColumnModelListenerExt about property changes of contained columns.
- Specified by:
addColumnModelListener
in interfaceTableColumnModel
- Specified by:
addColumnModelListener
in interfaceTableColumnModelExt
- Overrides:
addColumnModelListener
in classDefaultTableColumnModel
- Parameters:
x
- aTableColumnModelListener
object
-
removeColumnModelListener
Overridden to uninstall enhanced notification of listeners of type. TableColumnModelListenerExt about property changes of contained columns.
- Specified by:
removeColumnModelListener
in interfaceTableColumnModel
- Overrides:
removeColumnModelListener
in classDefaultTableColumnModel
-
getTableColumnModelExtListeners
- Returns:
- array of all registered listeners
-