Abstract base class for all component data adapter classes. A
ComponentAdapter
allows a {@link javax.swing.RowFilter}, {@link javax.swing.RowSorter}, or {@link Highlighter} to interact with a {@link #target} component through acommon API. It has two aspects:
- interact with the view state for a given data element. The row/column fields and the parameterless methods service this aspect. The coordinates are in view coordinate system. Typical clients of this service are HighlightPredicates and Highlighters.
- interact with the data of the component. The methods for this are those taking row/column indices as parameters. The coordinates are in model coordinate system. Typical clients of this service are Filters.
Typically, application code is interested in the first aspect. An example is highlighting the background of a row in a JXTable based on the value of a cell in a specific column. The solution is to implement a custom HighlightPredicate which decides if a given cell should be highlighted and configure a ColorHighlighter with the predicate and an appropriate background color.
HighlightPredicate feverWarning = new HighlightPredicate() { int temperatureColumn = 10; public boolean isHighlighted(Component component, ComponentAdapter adapter) { return hasFever(adapter.getValue(temperatureColumn)); } private boolean hasFever(Object value) { if (!value instanceof Number) return false; return ((Number) value).intValue() > 37; } }; Highlighter hl = new ColorHighlighter(feverWarning, Color.RED, null);
The adapter is responsible for mapping column coordinates. All input column indices are in model coordinates with exactly two exceptions:
- {@link #column} in column view coordinates
- the mapping method {@link #convertColumnIndexToModel(int)} in view coordinates
All input row indices are in model coordinates with exactly three exceptions:
- {@link #row} in row view coordinates
- the getter for the filtered value {@link #getFilteredValueAt(int,int)}takes the row in view coordinates.
- the getter for the filtered string representation {@link #getFilteredStringAt(int,int)}takes the row in view coordinates.
PENDING JW: add model-index based access to string rep.
PENDING JW: anything to gain by generics here?
PENDING JW: formally document that row/column coordinates must be valid in all methods taking model coordinates, that is 0<= row < getRowCount().
@author Ramesh Gupta
@author Karl Schaefer
@author Jeanette Winzenburg
@see org.jdesktop.swingx.decorator.HighlightPredicate
@see org.jdesktop.swingx.decorator.Highlighter
@see javax.swing.RowFilter