swingx
Version 2005-08-19

org.jdesktop.swingx.decorator
Class ComponentAdapter

java.lang.Object
  extended by org.jdesktop.swingx.decorator.ComponentAdapter
Direct Known Subclasses:
JXList.ListAdapter, JXTable.TableAdapter, JXTree.TreeAdapter

public abstract class ComponentAdapter
extends Object

Abstract base class for all component data adapter classes. A ComponentAdapter allows a Filter, Sorter, or Highlighter to interact with a target component through a common API. It has two aspects:

The adapter is responsible for mapping column coordinates. All input column indices are in model coordinates with exactly two exceptions: All input row indices are in model coordinates with exactly two exceptions:


Field Summary
 int column
          current column in view coordinates.
 int row
          current row in view coordinates.
protected  JComponent target
           
 
Constructor Summary
ComponentAdapter(JComponent component)
          Constructs a ComponentAdapter, setting the specified component as the target component.
 
Method Summary
 int getColumnCount()
          Returns the number of columns in the target's data model.
abstract  String getColumnIdentifier(int columnIndex)
          returns the logical name (== identifier) of the column at columnIndex in model coordinates.
abstract  String getColumnName(int columnIndex)
          returns the column's label (= headerValue).
 JComponent getComponent()
           
abstract  Object getFilteredValueAt(int row, int column)
          returns the filtered value of the cell identified by the row in view coordinate and the column in model coordinates.
 int getRowCount()
          Returns the number of rows in the target's data model.
 Object getValue()
          Returns the value of the cell identified by this adapter by invoking getValueAt(int, int), passing in the row and column values of this adapter.
abstract  Object getValueAt(int row, int column)
          Returns the value of the target component's cell identified by the specified row and column in model coordinates.
abstract  boolean hasFocus()
          Returns true if the cell identified by this adapter currently has focus; Otherwise, it returns false.
abstract  boolean isCellEditable(int row, int column)
           
 boolean isExpanded()
          Returns true if the cell identified by this adapter is currently expanded; Otherwise, it returns false.
 boolean isHierarchical()
          Returns true if the cell identified by this adapter displays the hierarchical node; Otherwise, it returns false.
 boolean isLeaf()
          Returns true if the cell identified by this adapter is a leaf node; Otherwise, it returns false.
abstract  boolean isSelected()
          Returns true if the cell identified by this adapter is currently selected; Otherwise, it returns false.
 boolean isTestable(int column)
          returns true if the column should be included in testing.
 int modelToView(int columnIndex)
          For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from model coordinates to view coordinates.
 void refresh()
           
abstract  void setValueAt(Object aValue, int row, int column)
           
 int viewToModel(int columnIndex)
          For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from view coordinates to model coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row

public int row
current row in view coordinates.


column

public int column
current column in view coordinates.


target

protected final JComponent target
Constructor Detail

ComponentAdapter

public ComponentAdapter(JComponent component)
Constructs a ComponentAdapter, setting the specified component as the target component.

Parameters:
component - target component for this adapter
Method Detail

getComponent

public JComponent getComponent()

getColumnName

public abstract String getColumnName(int columnIndex)
returns the column's label (= headerValue). Used f.i. in SearchPanel to fill the field with the column name. Note: it's up to the implementation to decide for which columns it returns a name - most will do so for the subset with isTestable = true.

Parameters:
columnIndex - in model coordinates
Returns:
column name or null if not found/not testable.

getColumnIdentifier

public abstract String getColumnIdentifier(int columnIndex)
returns the logical name (== identifier) of the column at columnIndex in model coordinates. Used f.i. JNTable to store and apply column properties by identifier. Note: it's up to the implementation to decide for which columns it returns a name - most will do so for the subset with isTestable = true.

Parameters:
columnIndex - in model coordinates
Returns:
the String value of the column identifier at columnIndex or null if no identifier set

getColumnCount

public int getColumnCount()
Returns the number of columns in the target's data model.

Returns:
the number of columns in the target's data model.

getRowCount

public int getRowCount()
Returns the number of rows in the target's data model.

Returns:
the number of rows in the target's data model.

getValueAt

public abstract Object getValueAt(int row,
                                  int column)
Returns the value of the target component's cell identified by the specified row and column in model coordinates.

Parameters:
row - in model coordinates
column - in model coordinates
Returns:
the value of the target component's cell identified by the specified row and column

setValueAt

public abstract void setValueAt(Object aValue,
                                int row,
                                int column)

isCellEditable

public abstract boolean isCellEditable(int row,
                                       int column)

isTestable

public boolean isTestable(int column)
returns true if the column should be included in testing. Here: returns true if visible (that is modelToView gives a valid view column coordinate).

Parameters:
column - in model coordinates
Returns:
true if the column should be included in testing

getValue

public Object getValue()
Returns the value of the cell identified by this adapter by invoking getValueAt(int, int), passing in the row and column values of this adapter. For target components that don't support multiple columns, the value of column is always zero. PENDING: needs clarification/cleanup - getValueAt(row, column) expects model coordinates!.

Returns:
the value of the cell identified by this adapter

getFilteredValueAt

public abstract Object getFilteredValueAt(int row,
                                          int column)
returns the filtered value of the cell identified by the row in view coordinate and the column in model coordinates. Note: the asymetry of the coordinates is intentional - clients like Highlighters are interested in view values but might need to access non-visible columns for testing.

Parameters:
row -
column -
Returns:
the filtered value of the cell identified by the row in view coordinate and the column in model coordiantes

hasFocus

public abstract boolean hasFocus()
Returns true if the cell identified by this adapter currently has focus; Otherwise, it returns false.

Returns:
true if the cell identified by this adapter currently has focus; Otherwise, return false

isSelected

public abstract boolean isSelected()
Returns true if the cell identified by this adapter is currently selected; Otherwise, it returns false.

Returns:
true if the cell identified by this adapter is currently selected; Otherwise, return false

isExpanded

public boolean isExpanded()
Returns true if the cell identified by this adapter is currently expanded; Otherwise, it returns false. For components that do not support hierarchical data, this method always returns true because the cells in such components can never be collapsed.

Returns:
true if the cell identified by this adapter is currently expanded; Otherwise, return false

isLeaf

public boolean isLeaf()
Returns true if the cell identified by this adapter is a leaf node; Otherwise, it returns false. For components that do not support hierarchical data, this method always returns true because the cells in such components can never have children.

Returns:
true if the cell identified by this adapter is a leaf node; Otherwise, return false

isHierarchical

public boolean isHierarchical()
Returns true if the cell identified by this adapter displays the hierarchical node; Otherwise, it returns false. For components that do not support hierarchical data, this method always returns false because the cells in such components can never have children.

Returns:
true if the cell identified by this adapter displays the hierarchical node; Otherwise, return false

modelToView

public int modelToView(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from model coordinates to view coordinates. For all other types of target components, this method returns the columnIndex unchanged.

Parameters:
columnIndex - index of a column in model coordinates
Returns:
index of the specified column in view coordinates

viewToModel

public int viewToModel(int columnIndex)
For target components that support multiple columns in their model, along with column reordering in the view, this method transforms the specified columnIndex from view coordinates to model coordinates. For all other types of target components, this method returns the columnIndex unchanged.

Parameters:
columnIndex - index of a column in view coordinates
Returns:
index of the specified column in model coordinates

refresh

public void refresh()

swingx
Version 2005-08-19