java.lang.Object
javax.swing.AbstractListModel
org.gjt.sp.jedit.gui.FilteredListModel<E>
- All Implemented Interfaces:
Serializable
,EventListener
,ListDataListener
,ListModel
public abstract class FilteredListModel<E extends ListModel<?>>
extends AbstractListModel
implements ListDataListener
This ListModel delegates another model to add some filtering features to any
JList.
To use it you must implement the abstract method passFilter().
This method is called for each row, and must return true if the row should be
visible, and false otherwise.
It is also possible to override the method prepareFilter() that allow you to
transform the filter String. Usually you can return it as lowercase
It is not mandatory but highly recommended to give the JList instance to the
model in order to keep the selection after the filter has been updated
- Since:
- jEdit 4.3pre11
- Version:
- $Id: Buffer.java 8190 2006-12-07 07:58:34Z kpouer $
- Author:
- Matthieu Casanova
- See Also:
-
Field Summary
Fields inherited from class javax.swing.AbstractListModel
listenerList
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
getElementAt
(int index) int
getInternal2ExternalRow
(int internalRowIndex) Converts a row index from the delegated table model into a row index of the JTable.int
getSize()
int
getTrueRow
(int rowIndex) Converts a row index from the JTable to an internal row index from the delegated model.void
void
abstract boolean
passFilter
(int row, String filter) This callback indicates if a row passes the filter.prepareFilter
(String filter) protected void
restoreSelection
(Set<Integer> selectedIndices) void
setDelegated
(E delegated) void
void
Set the JList that uses this model.Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
-
Field Details
-
delegated
The delegated table model.
-
-
Constructor Details
-
FilteredListModel
-
-
Method Details
-
setList
Set the JList that uses this model. It is used to restore the selection after the filter has been applied If it is null,- Parameters:
list
- the list that uses the model
-
getDelegated
-
setDelegated
-
setFilter
-
prepareFilter
-
passFilter
This callback indicates if a row passes the filter.- Parameters:
row
- the row number the delegate row countfilter
- the filter string- Returns:
- true if the row must be visible
-
saveSelection
-
restoreSelection
-
getTrueRow
public int getTrueRow(int rowIndex) Converts a row index from the JTable to an internal row index from the delegated model.- Parameters:
rowIndex
- the row index- Returns:
- the row index in the delegated model
-
getInternal2ExternalRow
public int getInternal2ExternalRow(int internalRowIndex) Converts a row index from the delegated table model into a row index of the JTable.- Parameters:
internalRowIndex
- the internal row index- Returns:
- the table row index or -1 if this row is not visible
-
getElementAt
- Specified by:
getElementAt
in interfaceListModel<E extends ListModel<?>>
-
getSize
public int getSize() -
contentsChanged
- Specified by:
contentsChanged
in interfaceListDataListener
-
intervalAdded
- Specified by:
intervalAdded
in interfaceListDataListener
-
intervalRemoved
- Specified by:
intervalRemoved
in interfaceListDataListener
-