org.jdesktop.swingx.decorator
Class Filter

java.lang.Object
  extended by org.jdesktop.swingx.decorator.Filter
Direct Known Subclasses:
FilterPipeline.IdentityFilter, PatternFilter, Sorter

public abstract class Filter
extends java.lang.Object

A Filter is used to filter the data presented in a data-aware component such as a JXList or a JXTable. Filtering involves interposing one or more filters in a FilterPipeline between a data model and a view to change the apparent order and/or number of records in the data model.

See Also:
FilterPipeline, JXTable

Field Summary
protected  ComponentAdapter adapter
           
protected  int[] fromPrevious
           
protected  FilterPipeline pipeline
           
 
Constructor Summary
Filter()
          Constructs a new filter for the first column of a data model (in model coordinates).
Filter(int col)
          Constructs a new filter for the specified column of a data model (in model coordinates).
 
Method Summary
protected  void assign(ComponentAdapter adapter)
          Binds this filter to the specified ComponentAdapter.
 int convertRowIndexToModel(int row)
          Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters.
 int convertRowIndexToView(int row)
          Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.
protected abstract  void filter()
          Performs the filter operation defined by this filter.
 int getColumnIndex()
          Returns the model index of the column that this filter has been bound to.
 java.lang.String getColumnName()
           
protected  int getInputSize()
          Returns the number of records that are processed by this filter.
protected  java.lang.Object getInputValue(int row, int column)
          Returns the value of the cell at the specified row and column (in model coordinates).
protected  FilterPipeline getPipeline()
           
abstract  int getSize()
          Returns the number of records that remain in this filter's "view" after the input records have been filtered.
 java.lang.Object getValueAt(int row, int column)
          Returns the value at the specified row and column.
protected abstract  void init()
          Provides filter-specific initialization.
 boolean isCellEditable(int row, int column)
          returns editability of the cell identified by the specified row and column index.
protected abstract  int mapTowardModel(int row)
          PRE: 0 <= row < getSize();
protected  int mapTowardView(int row)
          PRE: 0 <= row < getInputSize();
 void refresh()
          Refreshes the internal state of the filter, performs the filter operation and regenerates row mappings from the previous filter.
protected  void refresh(boolean reset)
          Refreshes the internal state of the filter, optionally resetting the cache of existing row mappings from this filter to the previous filter.
protected abstract  void reset()
          Resets the internal row mappings from this filter to the previous filter.
 void setColumnIndex(int modelColumn)
          PENDING: not tested!
 void setValueAt(java.lang.Object aValue, int row, int column)
          Sets the specified value as the new value for the cell identified by the specified row and column index.
protected  int translateFromPreviousFilter(int row)
          Deprecated. 
protected  int translateToPreviousFilter(int row)
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pipeline

protected FilterPipeline pipeline

adapter

protected ComponentAdapter adapter

fromPrevious

protected int[] fromPrevious
Constructor Detail

Filter

public Filter()
Constructs a new filter for the first column of a data model (in model coordinates).


Filter

public Filter(int col)
Constructs a new filter for the specified column of a data model (in model coordinates).

Parameters:
col - column index in model coordinates
Method Detail

refresh

public void refresh()
Refreshes the internal state of the filter, performs the filter operation and regenerates row mappings from the previous filter. If this filter is bound to a filter pipeline (as most filters are), it also triggers a filterChanged notification.


getColumnIndex

public int getColumnIndex()
Returns the model index of the column that this filter has been bound to.

Returns:
the model index of the column that this filter has been bound to

setColumnIndex

public void setColumnIndex(int modelColumn)
PENDING: not tested!

Parameters:
modelColumn -

getColumnName

public java.lang.String getColumnName()

convertRowIndexToModel

public int convertRowIndexToModel(int row)
Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters. PRE: 0 <= row < getSize()

Parameters:
row - row index in this filters "view" coordinates -
Returns:
row index in model coordinates

convertRowIndexToView

public int convertRowIndexToView(int row)
Convert row index from model coordinates to view coordinates accounting for the presence of sorters and filters.

Parameters:
row - row index in model coordinates
Returns:
row index in this filter's "view" coordinates

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Returns the value at the specified row and column. PRE: 0 <= row < getSize()

Parameters:
row - row index in this filter's "view" coordinates
column - column index in model coordinates
Returns:
the value at the specified row and column

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Sets the specified value as the new value for the cell identified by the specified row and column index. PRE: 0 <= row < getSize()

Parameters:
aValue - new value for the specified cell
row - row index in this filter's "view" coordinates
column - column index in model coordinates

isCellEditable

public boolean isCellEditable(int row,
                              int column)
returns editability of the cell identified by the specified row and column index. PRE: 0 <= row < getSize()

Parameters:
row - row index in this filter's "view" coordinates
column -
Returns:

getSize

public abstract int getSize()
Returns the number of records that remain in this filter's "view" after the input records have been filtered.

Returns:
the number of records that remain in this filter's "view" after the input records have been filtered

getInputSize

protected int getInputSize()
Returns the number of records that are processed by this filter.

Returns:
the number of records that are processed by this filter

getInputValue

protected java.lang.Object getInputValue(int row,
                                         int column)
Returns the value of the cell at the specified row and column (in model coordinates).

Parameters:
row - in the coordinates of what is the filter's "view" of the model
column - in model coordinates
Returns:
the value of the cell at the specified row and column (in model coordinates)

init

protected abstract void init()
Provides filter-specific initialization. Called from the Filter constructor.


reset

protected abstract void reset()
Resets the internal row mappings from this filter to the previous filter.


filter

protected abstract void filter()
Performs the filter operation defined by this filter.


mapTowardModel

protected abstract int mapTowardModel(int row)
PRE: 0 <= row < getSize();

Parameters:
row -
Returns:

mapTowardView

protected int mapTowardView(int row)
PRE: 0 <= row < getInputSize();

Parameters:
row -
Returns:

translateFromPreviousFilter

@Deprecated
protected int translateFromPreviousFilter(int row)
Deprecated. 

Returns the row in this filter that maps to the specified row in the previous filter. If there is no previous filter in the pipeline, this returns the row in this filter that maps to the specified row in the data model. This method is called from convertRowIndexToView

Parameters:
row - a row index in the previous filter's "view" of the data model
Returns:
the row in this filter that maps to the specified row in the previous filter

translateToPreviousFilter

@Deprecated
protected int translateToPreviousFilter(int row)
Deprecated. 

Returns the row in the previous filter that maps to the specified row in this filter. If there is no previous filter in the pipeline, this returns the row in the data model that maps to the specified row in this filter. This method is called from convertRowIndexToModel

Parameters:
row - a row index in this filter's "view" of the data model
Returns:
the row in the previous filter that maps to the specified row in this filter

refresh

protected void refresh(boolean reset)
Refreshes the internal state of the filter, optionally resetting the cache of existing row mappings from this filter to the previous filter. Always performs the filter operation and regenerates row mappings from the previous filter. If this filter is bound to a filter pipeline (as most filters are), it also triggers a filterChanged notification.

Parameters:
reset - true if existing row mappings from this filter to the previous filter should be reset; false, if the existing row mappings should be preserved.

assign

protected void assign(ComponentAdapter adapter)
Binds this filter to the specified ComponentAdapter. Called by FilterPipeline.bind().

Parameters:
adapter - adapter that this filter is bound to

getPipeline

protected FilterPipeline getPipeline()