Class TableColumnExt
- java.lang.Object
-
- javax.swing.table.TableColumn
-
- org.jdesktop.swingx.table.TableColumnExt
-
- All Implemented Interfaces:
java.io.Serializable
,UIDependent
public class TableColumnExt extends javax.swing.table.TableColumn implements UIDependent
TableColumn
extension for enhanced view column configuration. The general drift is to strengthen the TableColumn abstraction as the place to configure and dynamically update view column properties, covering a broad range of customization requirements. Using collaborators are expected to listen to property changes and update themselves accordingly.A functionality enhancement is the notion of column visibility:
TableColumnModelExt
manages sets of visible/hiddenTableColumnExt
s controlled by the columns'visible
property. Typically, users can toggle column visibility at runtime, f.i. through a dedicated control in the upper trailing corner of aJScrollPane
.A prominent group of properties allows fine-grained, per-column control of corresponding Table/-Header features.
- Sorting:
sortable
controls whether this column should be sortable by user's sort gestures;Comparator
can hold a column specific type. - Editing:
editable
controls whether cells of this column should be accessible to in-table editing. - Tooltip:
toolTipText
holds the column tooltip which is shown when hovering over the column's header. - Highlighter:
highlighters
holds the column highlighters; these are applied to the renderer after the table highlighters. Any modification of the list of containedHighlighter
s (setting them, adding one or removing one) will result in aPropertyChangeEvent
being fired for "highlighters". State changes on containedHighlighter
s will result in a PropertyChangeEvent for "highlighterStateChanged".
JComponent
, this class supports per-instance "client" properties. They are meant as a small-scale extension mechanism. They are similar to regular bean properties in that registeredPropertyChangeListener
s are notified about changes. TODO: example?A
TableColumnExt
implements UIDependent, that is it takes over responsibility to update LAF dependent properties of contained elements when messaged with updateUI. This implementation updates itsHighlighter
s, Cell-/HeaderRenderer and CellEditor.TODO: explain prototype (sizing, collaborator-used-by ColumnFactory (?))
- Author:
- Ramesh Gupta, Amy Fowler, Jeanette Winzenburg, Karl Schaefer
- See Also:
TableColumnModelExt
,ColumnFactory
,UIDependent
,JComponent.putClientProperty(java.lang.Object, java.lang.Object)
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Hashtable<java.lang.Object,java.lang.Object>
clientProperties
storage for client properties.protected java.util.Comparator<?>
comparator
per-column comparatorprotected CompoundHighlighter
compoundHighlighter
The compound highlighter for the column.protected boolean
editable
per-column editable property.protected java.lang.Object
prototypeValue
prototype property.protected boolean
sortable
per-column sortable property.protected boolean
visible
visible property.
-
Constructor Summary
Constructors Constructor Description TableColumnExt()
Creates new table view column with a model index = 0.TableColumnExt(int modelIndex)
Creates new table view column with the specified model index.TableColumnExt(int modelIndex, int width)
Creates new table view column with the specified model index and column width.TableColumnExt(int modelIndex, int width, javax.swing.table.TableCellRenderer cellRenderer, javax.swing.table.TableCellEditor cellEditor)
Creates new table view column with the specified model index, column width, cell renderer and cell editor.TableColumnExt(TableColumnExt columnExt)
Instantiates a new table view column with all properties copied from the given original.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHighlighter(Highlighter highlighter)
Appends aHighlighter
to the end of the list of usedHighlighter
s.protected void
copyClientPropertiesFrom(TableColumnExt original)
Copies all clientProperties of thisTableColumnExt
to the target column.protected void
copyFrom(TableColumnExt original)
Copies properties from original.protected javax.swing.event.ChangeListener
createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters.protected void
firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
Notifies registeredPropertyChangeListener
s about property changes.java.lang.Object
getClientProperty(java.lang.Object key)
Returns the value of the property with the specified key.java.util.Comparator<?>
getComparator()
Returns the comparator to use for the column.protected CompoundHighlighter
getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none.protected javax.swing.event.ChangeListener
getHighlighterChangeListener()
Returns theChangeListener
to use with highlighters.Highlighter[]
getHighlighters()
Returns theHighlighter
s used by this table.java.lang.Object
getPrototypeValue()
Returns the prototypeValue property.boolean
getResizable()
Returns true if the user can resize the TableColumn's width, false otherwise.java.lang.String
getTitle()
Convenience method which returns the headerValue property after converting it to a string.java.lang.String
getToolTipText()
Returns the text of to display in the column's tool tip.boolean
isEditable()
Returns the per-column editable property.boolean
isSortable()
Returns the sortable property.boolean
isVisible()
Returns the visible property.void
putClientProperty(java.lang.Object key, java.lang.Object value)
Sets the client property "key" tovalue
.void
removeHighlighter(Highlighter highlighter)
Removes the given Highlighter.void
setComparator(java.util.Comparator<?> comparator)
Sets the comparator to use for this column.void
setEditable(boolean editable)
Sets the editable property.void
setHighlighters(Highlighter... highlighters)
Sets theHighlighter
s to the table, replacing any old settings.void
setPrototypeValue(java.lang.Object value)
Sets the prototypeValue property.void
setSortable(boolean sortable)
Sets the sortable property.void
setTitle(java.lang.String title)
Sets the title of this view column.void
setToolTipText(java.lang.String toolTipText)
Registers the text to display in the column's tool tip.void
setVisible(boolean visible)
Sets the visible property.void
updateUI()
Update ui of owned ui-dependent parts.-
Methods inherited from class javax.swing.table.TableColumn
addPropertyChangeListener, createDefaultHeaderRenderer, disableResizedPosting, enableResizedPosting, getCellEditor, getCellRenderer, getHeaderRenderer, getHeaderValue, getIdentifier, getMaxWidth, getMinWidth, getModelIndex, getPreferredWidth, getPropertyChangeListeners, getWidth, removePropertyChangeListener, setCellEditor, setCellRenderer, setHeaderRenderer, setHeaderValue, setIdentifier, setMaxWidth, setMinWidth, setModelIndex, setPreferredWidth, setResizable, setWidth, sizeWidthToFit
-
-
-
-
Field Detail
-
visible
protected boolean visible
visible property. Initialized totrue
.
-
prototypeValue
protected java.lang.Object prototypeValue
prototype property.
-
comparator
protected java.util.Comparator<?> comparator
per-column comparator
-
sortable
protected boolean sortable
per-column sortable property. Initialized totrue
.
-
editable
protected boolean editable
per-column editable property. Initialized totrue
.
-
clientProperties
protected java.util.Hashtable<java.lang.Object,java.lang.Object> clientProperties
storage for client properties.
-
compoundHighlighter
protected CompoundHighlighter compoundHighlighter
The compound highlighter for the column.
-
-
Constructor Detail
-
TableColumnExt
public TableColumnExt()
Creates new table view column with a model index = 0.
-
TableColumnExt
public TableColumnExt(int modelIndex)
Creates new table view column with the specified model index.- Parameters:
modelIndex
- index of table model column to which this view column is bound.
-
TableColumnExt
public TableColumnExt(int modelIndex, int width)
Creates new table view column with the specified model index and column width.- Parameters:
modelIndex
- index of table model column to which this view column is bound.width
- pixel width of view column
-
TableColumnExt
public TableColumnExt(int modelIndex, int width, javax.swing.table.TableCellRenderer cellRenderer, javax.swing.table.TableCellEditor cellEditor)
Creates new table view column with the specified model index, column width, cell renderer and cell editor.- Parameters:
modelIndex
- index of table model column to which this view column is bound.width
- pixel width of view columncellRenderer
- the cell renderer which will render all cells in this view columncellEditor
- the cell editor which will edit cells in this view column
-
TableColumnExt
public TableColumnExt(TableColumnExt columnExt)
Instantiates a new table view column with all properties copied from the given original.- Parameters:
columnExt
- the column to copy properties from- See Also:
copyFrom(TableColumnExt)
-
-
Method Detail
-
setHighlighters
public void setHighlighters(Highlighter... highlighters)
Sets theHighlighter
s to the table, replacing any old settings. None of the given Highlighters must be null.This is a bound property.
Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.
- Parameters:
highlighters
- zero or more not null highlighters to use for renderer decoration.- Throws:
java.lang.NullPointerException
- if array is null or array contains null values.- See Also:
getHighlighters()
,addHighlighter(Highlighter)
,removeHighlighter(Highlighter)
-
getHighlighters
public Highlighter[] getHighlighters()
Returns theHighlighter
s used by this table. Maybe empty, but guarantees to be never null.- Returns:
- the Highlighters used by this table, guaranteed to never null.
- See Also:
setHighlighters(Highlighter[])
-
addHighlighter
public void addHighlighter(Highlighter highlighter)
Appends aHighlighter
to the end of the list of usedHighlighter
s. The argument must not be null.- Parameters:
highlighter
- theHighlighter
to add, must not be null.- Throws:
java.lang.NullPointerException
- ifHighlighter
is null.- See Also:
removeHighlighter(Highlighter)
,setHighlighters(Highlighter[])
-
removeHighlighter
public void removeHighlighter(Highlighter highlighter)
Removes the given Highlighter.Does nothing if the Highlighter is not contained.
- Parameters:
highlighter
- the Highlighter to remove.- See Also:
addHighlighter(Highlighter)
,setHighlighters(Highlighter...)
-
getCompoundHighlighter
protected CompoundHighlighter getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none. PENDING: open up for subclasses again?.- Returns:
- the CompoundHighlighter assigned to the table.
-
getHighlighterChangeListener
protected javax.swing.event.ChangeListener getHighlighterChangeListener()
Returns theChangeListener
to use with highlighters. Lazily creates the listener.- Returns:
- the ChangeListener for observing changes of highlighters,
guaranteed to be
not-null
-
createHighlighterChangeListener
protected javax.swing.event.ChangeListener createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters.Here: repaints the table on receiving a stateChanged.
- Returns:
- the ChangeListener defining the reaction to changes of highlighters.
-
getResizable
public boolean getResizable()
Returns true if the user can resize the TableColumn's width, false otherwise. This is a usability override: it takes into account the case where it's principally allowed to resize the column but not possible because the column has fixed size.- Overrides:
getResizable
in classjavax.swing.table.TableColumn
- Returns:
- a boolean indicating whether the user can resize this column.
-
setEditable
public void setEditable(boolean editable)
Sets the editable property. This property allows to mark all cells in a column as read-only, independent of the per-cell editability as returned by theTableModel.isCellEditable
. If the cell is read-only in the model layer, this property will have no effect.- Parameters:
editable
- boolean indicating whether or not the user may edit cell values in this view column- See Also:
isEditable()
,JXTable.isCellEditable(int, int)
,TableModel.isCellEditable(int, int)
-
isEditable
public boolean isEditable()
Returns the per-column editable property. The default istrue
.- Returns:
- boolean indicating whether or not the user may edit cell values in this view column
- See Also:
setEditable(boolean)
-
setPrototypeValue
public void setPrototypeValue(java.lang.Object value)
Sets the prototypeValue property. The value should be of a type which corresponds to the column's class as defined by the table model. If non-null, the JXTable instance will use this property to calculate and set the initial preferredWidth of the column. Note that this initial preferredWidth will be overridden if the user resizes columns directly.- Parameters:
value
- Object containing the value of the prototype to be used to calculate the initial preferred width of the column- See Also:
getPrototypeValue()
,JXTable.getPreferredScrollableViewportSize()
-
getPrototypeValue
public java.lang.Object getPrototypeValue()
Returns the prototypeValue property. The default isnull
.- Returns:
- Object containing the value of the prototype to be used to calculate the initial preferred width of the column
- See Also:
setPrototypeValue(java.lang.Object)
-
setComparator
public void setComparator(java.util.Comparator<?> comparator)
Sets the comparator to use for this column.JXTable
sorting api respects this property by passing it on to theSortController
.- Parameters:
comparator
- a custom comparator to use in interactive sorting.- See Also:
getComparator()
,SortController
,org.jdesktop.swingx.decorator.SortKey
-
getComparator
public java.util.Comparator<?> getComparator()
Returns the comparator to use for the column. The default isnull
.- Returns:
Comparator
to use for this column- See Also:
setComparator(java.util.Comparator<?>)
-
setSortable
public void setSortable(boolean sortable)
Sets the sortable property.JXTable
sorting api respects this property by disabling interactive sorting on this column if false.- Parameters:
sortable
- boolean indicating whether or not this column can be sorted in the table- See Also:
isSortable()
-
isSortable
public boolean isSortable()
Returns the sortable property. The default value istrue
.- Returns:
- boolean indicating whether this view column is sortable
- See Also:
setSortable(boolean)
-
setToolTipText
public void setToolTipText(java.lang.String toolTipText)
Registers the text to display in the column's tool tip. Typically, this is used byJXTableHeader
to display when the mouse cursor lingers over the column's header cell.- Parameters:
toolTipText
- text to show.- See Also:
setToolTipText(String)
-
getToolTipText
public java.lang.String getToolTipText()
Returns the text of to display in the column's tool tip. The default isnull
.- Returns:
- the text of the column ToolTip.
- See Also:
setToolTipText(String)
-
setTitle
public void setTitle(java.lang.String title)
Sets the title of this view column. This is a convenience wrapper forsetHeaderValue
.- Parameters:
title
- String containing the title of this view column
-
getTitle
public java.lang.String getTitle()
Convenience method which returns the headerValue property after converting it to a string.- Returns:
- String containing the title of this view column or null if no headerValue is set.
-
setVisible
public void setVisible(boolean visible)
Sets the visible property. This property controls whether or not this view column is currently visible in the table.- Parameters:
visible
- boolean indicating whether or not this view column is visible in the table- See Also:
setVisible(boolean)
-
isVisible
public boolean isVisible()
Returns the visible property. The default istrue
.- Returns:
- boolean indicating whether or not this view column is visible in the table
- See Also:
setVisible(boolean)
-
putClientProperty
public void putClientProperty(java.lang.Object key, java.lang.Object value)
Sets the client property "key" tovalue
. Ifvalue
isnull
this method will remove the property. Changes to client properties are reported withPropertyChange
events. The name of the property (for the sake of PropertyChange events) iskey.toString()
.The
get/putClientProperty
methods provide access to a per-instance hashtable, which is intended for small scale extensions of TableColumn.- Parameters:
key
- Object which is used as key to retrieve valuevalue
- Object containing value of client property- Throws:
java.lang.IllegalArgumentException
- if key isnull
- See Also:
getClientProperty(java.lang.Object)
,JComponent.putClientProperty(java.lang.Object, java.lang.Object)
-
getClientProperty
public java.lang.Object getClientProperty(java.lang.Object key)
Returns the value of the property with the specified key. Only properties added withputClientProperty
will return a non-null
value.- Parameters:
key
- Object which is used as key to retrieve value- Returns:
- Object containing value of client property or
null
- See Also:
putClientProperty(java.lang.Object, java.lang.Object)
-
copyFrom
protected void copyFrom(TableColumnExt original)
Copies properties from original. Handles all properties except modelIndex, width, cellRenderer, cellEditor. Called from copy constructor.- Parameters:
original
- the tableColumn to copy from- See Also:
TableColumnExt(TableColumnExt)
-
copyClientPropertiesFrom
protected void copyClientPropertiesFrom(TableColumnExt original)
Copies all clientProperties of thisTableColumnExt
to the target column.- Parameters:
original
- the target column.
-
firePropertyChange
protected void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
Notifies registeredPropertyChangeListener
s about property changes. This method must be invoked internally whe any of the enhanced properties changed.Implementation note: needed to replicate super functionality because super's field
propertyChangeSupport
and methodfireXX
are both private.- Parameters:
propertyName
- name of changed propertyoldValue
- old value of changed propertynewValue
- new value of changed property
-
updateUI
public void updateUI()
Update ui of owned ui-dependent parts. This implementation updates the contained highlighters.- Specified by:
updateUI
in interfaceUIDependent
- See Also:
JComponent.updateUI()
-
-