Package megamek.client.ui.models
Class XTableColumnModel
java.lang.Object
javax.swing.table.DefaultTableColumnModel
megamek.client.ui.models.XTableColumnModel
- All Implemented Interfaces:
PropertyChangeListener,Serializable,EventListener,ListSelectionListener,TableColumnModel
XTableColumnModel 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() There are overloaded versions of these methods that take a parameter
onlyVisible which lets
you specify whether you want invisible columns taken into account.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Vector<TableColumn> Array of TableColumn objects in this model.Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColumn(TableColumn column) Appendcolumnto the right of existing columns.getColumn(int columnIndex, boolean onlyVisible) Returns theTableColumnobject for the column atcolumnIndex.getColumnByModelIndex(int modelColumnIndex) Maps the index of the column in the table model atmodelColumnIndexto the TableColumn object.intgetColumnCount(boolean onlyVisible) Returns the total number of columns in this model.intgetColumnIndex(Object identifier, boolean onlyVisible) Deprecated, for removal: This API element is subject to removal in a future version.Enumeration<?> getColumns(boolean onlyVisible) Deprecated, for removal: This API element is subject to removal in a future version.booleanisColumnVisible(TableColumn aColumn) Checks whether the specified column is currently visible.voidmoveColumn(int oldIndex, int newIndex) Moves the column fromoldIndextonewIndex.voidremoveColumn(TableColumn column) Removescolumnfrom this column model.voidMakes all columns in this model visiblevoidsetColumnVisible(TableColumn column, boolean visible) Sets the visibility of the specified TableColumn.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, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
-
Field Details
-
allTableColumns
Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility
-
-
Constructor Details
-
XTableColumnModel
public XTableColumnModel()Creates an extended table column model.
-
-
Method Details
-
getAllTableColumns
-
setColumnVisible
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- Parameters:
column- the column to show/hidevisible- its new visibility status
-
setAllColumnsVisible
public void setAllColumnsVisible()Makes all columns in this model visible -
getColumnByModelIndex
Maps the index of the column in the table model atmodelColumnIndexto the TableColumn object. There may be multiple TableColumn objects showing the same model column, though this is uncommon. This method will always return the first visible or else the first invisible column with the specified index.- Parameters:
modelColumnIndex- index of column in table model- Returns:
- table column object or null if no such column in this column model
-
isColumnVisible
Checks whether the specified column is currently visible.- Parameters:
aColumn- column to check- Returns:
- visibility of specified column (false if there is no such column at all. [It's not visible, right?])
-
addColumn
Appendcolumnto the right of existing columns. PostscolumnAddedevent.- Specified by:
addColumnin interfaceTableColumnModel- Overrides:
addColumnin classDefaultTableColumnModel- Parameters:
column- The column to be added- Throws:
IllegalArgumentException- ifcolumnisnull- See Also:
-
removeColumn
Removescolumnfrom this column model. PostscolumnRemovedevent. Will do nothing if the column is not in this model.- Specified by:
removeColumnin interfaceTableColumnModel- Overrides:
removeColumnin classDefaultTableColumnModel- Parameters:
column- the column to be added- See Also:
-
moveColumn
public void moveColumn(int oldIndex, int newIndex) Moves the column fromoldIndextonewIndex. PostscolumnMovedevent. Will not move any columns ifoldIndexequalsnewIndex.- Specified by:
moveColumnin interfaceTableColumnModel- Overrides:
moveColumnin classDefaultTableColumnModel- Parameters:
oldIndex- index of column to be movednewIndex- new index of the column- Throws:
IllegalArgumentException- if eitheroldIndexornewIndexare not in [0, getColumnCount() - 1]
-
getColumnCount
public int getColumnCount(boolean onlyVisible) Returns the total number of columns in this model.- Parameters:
onlyVisible- if set only visible columns will be counted- Returns:
- the number of columns in the
tableColumnsarray - See Also:
-
getColumns
Deprecated, for removal: This API element is subject to removal in a future version.Returns anEnumerationof all the columns in the model.- Parameters:
onlyVisible- if set all invisible columns will be missing from the enumeration.- Returns:
- an
Enumerationof the columns in the model
-
getColumnIndex
@Deprecated(since="0.51.0", forRemoval=true) public int getColumnIndex(Object identifier, boolean onlyVisible) Deprecated, for removal: This API element is subject to removal in a future version.Returns the position of the first column whose identifier equalsidentifier. Position is the index in all visible columns ifonlyVisibleis true or else the index in all columns.- Parameters:
identifier- the identifier object to search foronlyVisible- if set searches only visible columns- Returns:
- the index of the first column whose identifier equals
identifier - Throws:
IllegalArgumentException- ifidentifierisnull, or if noTableColumnhas thisidentifier- See Also:
-
getColumn
Returns theTableColumnobject for the column atcolumnIndex.- Parameters:
columnIndex- the index of the column desiredonlyVisible- if set columnIndex is meant to be relative to all visible columns only else it is the index in all columns- Returns:
- the
TableColumnobject for the column atcolumnIndex
-