Package org.jdesktop.swingx.decorator
Class Filter
- java.lang.Object
-
- 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 aJXList
or aJXTable
. Filtering involves interposing one or more filters in aFilterPipeline
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
Fields Modifier and Type Field Description protected ComponentAdapter
adapter
protected int[]
fromPrevious
TODO: make privateprotected FilterPipeline
pipeline
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
assign(ComponentAdapter adapter)
Binds this filter to the specifiedComponentAdapter
.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.protected void
fireFilterChanged()
Notifies interested parties that this filter has changed.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 of this filter's input ("model").protected java.lang.String
getInputString(int row, int column)
Returns the string representation of cell at the specified row and column.protected java.lang.Object
getInputValue(int row, int column)
Returns the value of the cell at the specified row and column.protected Filter
getMappingFilter()
Returns the filter to use for accessing input.protected FilterPipeline
getPipeline()
abstract int
getSize()
Returns the number of records that remain in this filter's output ("view") after the input records have been filtered.java.lang.String
getStringAt(int row, int column)
Returns the string representation at the specified row and column.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 thefilter
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)
TODO: 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.
-
-
-
Field Detail
-
pipeline
protected FilterPipeline pipeline
-
adapter
protected ComponentAdapter adapter
-
fromPrevious
protected int[] fromPrevious
TODO: make private
-
-
Method Detail
-
refresh
public void refresh()
Refreshes the internal state of the filter, performs thefilter
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 afilterChanged
notification.
-
getColumnIndex
public int getColumnIndex()
Returns the model index of the column that this filter has been bound to.- Returns:
- the column index in absolute model coordinates
-
setColumnIndex
public void setColumnIndex(int modelColumn)
TODO: PENDING: not tested!- Parameters:
column
- column index in absolute model coordinates
-
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
- the row index in this filter's output ("view") coordinates- Returns:
- row index in absolute 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. The column index is in absolute column coordinates. PRE: 0 <= row < getSize()- Parameters:
row
- the row index in this filter's output ("view") coordinatescolumn
- column index in absolute model coordinates- Returns:
- the value at the specified row and column
-
getStringAt
public java.lang.String getStringAt(int row, int column)
Returns the string representation at the specified row and column. The column index is in absolute column coordinates. PRE: 0 <= row < getSize()- Parameters:
row
- the row index in this filter's output ("view") coordinatescolumn
- column index in model coordinates- Returns:
- the string representation of the cell 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. The column index is in absolute column coordinates. PRE: 0 <= row < getSize()- Parameters:
aValue
- new value for the specified cellrow
- the row index in this filter's output ("view") coordinatescolumn
- the column index in absolute model coordinates
-
isCellEditable
public boolean isCellEditable(int row, int column)
Returns editability of the cell identified by the specified row and column index. The column index is in absolute column coordinates. PRE: 0 <= row <getSize()
- Parameters:
row
- the row index in this filter's output ("view") coordinatescolumn
- column index in model coordinates- Returns:
- true if the cell at the specified row/col is editable
-
getSize
public abstract int getSize()
Returns the number of records that remain in this filter's output ("view") after the input records have been filtered.- Returns:
- the number of records that remain in this filter's output ("view") after the input records have been filtered
-
getInputSize
protected int getInputSize()
Returns the number of records of this filter's input ("model").- Returns:
- the number of records of this filter's input ("model").
-
getInputValue
protected java.lang.Object getInputValue(int row, int column)
Returns the value of the cell at the specified row and column. The column index is in absolute column coordinates.- Parameters:
row
- in the coordinates of what is the filter's input ("model").column
- in model coordinates- Returns:
- the value of the cell at the specified row and column.
-
getInputString
protected java.lang.String getInputString(int row, int column)
Returns the string representation of cell at the specified row and column.- Parameters:
row
- in the coordinates of what is the filter's "model" (== input) coordinatescolumn
- in model coordinates- Returns:
- the string representation of the cell at the specified row and column.
-
init
protected abstract void init()
Provides filter-specific initialization. Called from theFilter
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:
- TODO:
-
mapTowardView
protected int mapTowardView(int row)
PRE: 0 <= row <getInputSize();
- Parameters:
row
-- Returns:
- TODO:
-
getMappingFilter
protected Filter getMappingFilter()
Returns the filter to use for accessing input. That's the previous (model is first) filter if this is part of a pipeline or null if this is standalone or the first in the pipeline.- Returns:
- filter to use for accessing input
-
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 thefilter
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 afilterChanged
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.
-
fireFilterChanged
protected void fireFilterChanged()
Notifies interested parties that this filter has changed.
-
assign
protected void assign(ComponentAdapter adapter)
Binds this filter to the specifiedComponentAdapter
. Called byFilterPipeline.assign(ComponentAdapter)
- Parameters:
adapter
- adapter that this filter is bound to
-
getPipeline
protected FilterPipeline getPipeline()
-
-