|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JList
org.jdesktop.swingx.JXList
public class JXList
Enhanced List component with support for general SwingX sorting/filtering, rendering, highlighting, rollover and search functionality. List specific enhancements include ?? PENDING JW ...
list.setFilterEnabled(true);
list.setComparator(myComparator);
list.setSortOrder(SortOrder.DESCENDING);
list.toggleSortOder();
list.resetSortOrder();
Rows can be filtered from a JXList using a Filter class and a
FilterPipeline. One assigns a FilterPipeline to the table using
setFilters(FilterPipeline)
. Filtering hides, but does not delete nor
permanently remove rows from a JXList.
JXList provides api to access items of the underlying model in view coordinates and to convert from/to model coordinates. Note: List sorting/filtering is disabled by default because it has side-effects which might break "normal" expectations when using a JList: if enabled all row coordinates (including those returned by the selection) are in view coordinates. Furthermore, the model returned from getModel() is a wrapper around the actual data. Note: SwingX sorting/filtering is incompatible with core sorting/filtering in JDK 6+. Will be replaced by core functionality after switching the target jdk version from 5 to 6.
JXList list = new JXList(new Contributors());
// implement a custom string representation, concated from first-, lastName
StringValue sv = new StringValue() {
public String getString(Object value) {
if (value instanceof Contributor) {
Contributor contributor = (Contributor) value;
return contributor.lastName() + ", " + contributor.firstName();
}
return StringValues.TO_STRING(value);
}
};
list.setCellRenderer(new DefaultListRenderer(sv);
// highlight condition: gold merits
HighlightPredicate predicate = new HighlightPredicate() {
public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
if (!(value instanceof Contributor)) return false;
return ((Contributor) value).hasGold();
}
};
// highlight with foreground color
list.addHighlighter(new PainterHighlighter(predicate, goldStarPainter);
Note: to support the highlighting this implementation wraps the
ListCellRenderer set by client code with a DelegatingRenderer which applies
the Highlighter after delegating the default configuration to the wrappee. As
a side-effect, getCellRenderer does return the wrapper instead of the custom
renderer. To access the latter, client code must call getWrappedCellRenderer.
JXList list = new JXList();
list.setRolloverEnabled(true);
list.setCellRenderer(new DefaultListRenderer());
list.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
null, Color.RED);
JXList provides api to vend a renderer-controlled String representation of cell content. This allows the Searchable and Highlighters to use WYSIWYM (What-You-See-Is-What-You-Match), that is pattern matching against the actual string as seen by the user.
Nested Class Summary | |
---|---|
class |
JXList.DelegatingRenderer
A decorator for the original ListCellRenderer. |
protected static class |
JXList.ListAdapter
A component adapter targeted at a JXList. |
Nested classes/interfaces inherited from class javax.swing.JList |
---|
JList.AccessibleJList |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected CompoundHighlighter |
compoundHighlighter
The pipeline holding the highlighters. |
protected ComponentAdapter |
dataAdapter
The ComponentAdapter for model data access. |
static String |
EXECUTE_BUTTON_ACTIONCOMMAND
|
protected FilterPipeline |
filters
The pipeline holding the filters. |
Fields inherited from class javax.swing.JList |
---|
HORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAP |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JXList()
Constructs a JXList with an empty model and filters disabled. |
|
JXList(boolean filterEnabled)
Constructs a JXList with an empty model and
filterEnabled property. |
|
JXList(ListModel dataModel)
Constructs a JXList that displays the elements in the
specified, non-null model and filters disabled. |
|
JXList(ListModel dataModel,
boolean filterEnabled)
Constructs a JXList with the specified model and
filterEnabled property. |
|
JXList(Object[] listData)
Constructs a JXList that displays the elements in
the specified array and filters disabled. |
|
JXList(Object[] listData,
boolean filterEnabled)
Constructs a JXList that displays the elements in
the specified array and filterEnabled property. |
|
JXList(Vector<?> listData)
Constructs a JXList that displays the elements in
the specified Vector and filtes disabled. |
|
JXList(Vector<?> listData,
boolean filterEnabled)
Constructs a JXList that displays the elements in
the specified Vector and filtersEnabled property. |
Method Summary | |
---|---|
void |
addHighlighter(Highlighter highlighter)
Appends a Highlighter to the end of the list of used
Highlighter s. |
int |
convertIndexToModel(int viewIndex)
Convert row index from view coordinates to model coordinates accounting for the presence of sorters and filters. |
int |
convertIndexToView(int modelIndex)
Convert index from model coordinates to view coordinates accounting for the presence of sorters and filters. |
protected ListCellRenderer |
createDefaultCellRenderer()
Creates and returns the default cell renderer to use. |
protected ChangeListener |
createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters. |
protected ListRolloverController<JXList> |
createLinkController()
Creates and returns a RolloverController appropriate for this component. |
protected PipelineListener |
createPipelineListener()
creates the listener for changes in filters. |
protected RolloverProducer |
createRolloverProducer()
Creates and returns the RolloverProducer to use with this tree. |
protected void |
doFind()
Starts a search on this List's visible items. |
ListCellRenderer |
getCellRenderer()
Returns the object that renders the list items. |
Comparator<?> |
getComparator()
|
protected ComponentAdapter |
getComponentAdapter()
|
protected ComponentAdapter |
getComponentAdapter(int index)
Convenience to access a configured ComponentAdapter. |
protected CompoundHighlighter |
getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none. |
Object |
getElementAt(int viewIndex)
returns the element at the given index. |
int |
getElementCount()
Returns the number of elements in this list in view coordinates. |
protected PipelineListener |
getFilterPipelineListener()
returns the listener for changes in filters. |
FilterPipeline |
getFilters()
Returns the FilterPipeline assigned to this list, or null if filtering not enabled. |
protected ChangeListener |
getHighlighterChangeListener()
Returns the ChangeListener to use with highlighters. |
Highlighter[] |
getHighlighters()
Returns the Highlighter s used by this table. |
protected ListRolloverController<JXList> |
getLinkController()
Returns the RolloverController for this component. |
Searchable |
getSearchable()
Returns a Searchable for this component, guaranteed to be not null. |
protected SelectionMapper |
getSelectionMapper()
widened access for testing... |
protected SortController |
getSortController()
returns the currently active SortController. |
SortOrder |
getSortOrder()
Returns the SortOrder. |
String |
getStringAt(int row)
Returns the string representation of the cell value at the given position. |
ListCellRenderer |
getWrappedCellRenderer()
Returns the renderer installed by client code or the default if none has been set. |
ListModel |
getWrappedModel()
returns the underlying model. |
boolean |
isFilterEnabled()
|
boolean |
isRolloverEnabled()
Returns a boolean indicating whether or not rollover support is enabled. |
void |
removeHighlighter(Highlighter highlighter)
Removes the given Highlighter. |
void |
resetSortOrder()
Removes the interactive sorter. |
void |
setCellRenderer(ListCellRenderer renderer)
Sets the delegate that's used to paint each cell in the list. |
void |
setComparator(Comparator<?> comparator)
Sets the comparator used. |
void |
setFilterEnabled(boolean enabled)
Enables/disables filtering support. |
void |
setFilters(FilterPipeline pipeline)
Sets the FilterPipeline for filtering the items of this list, maybe null to remove all previously applied filters. |
void |
setHighlighters(Highlighter... highlighters)
Sets the Highlighter s to the table, replacing any old settings. |
void |
setModel(ListModel model)
Sets the model that represents the contents or "value" of the list and clears the list selection after notifying PropertyChangeListeners . |
void |
setRolloverEnabled(boolean rolloverEnabled)
Sets the property to enable/disable rollover support. |
void |
setSearchable(Searchable searchable)
Sets the Searchable for this component. |
void |
setSelectionModel(ListSelectionModel newModel)
Sets the selectionModel for the list to a
non-null ListSelectionModel
implementation. |
void |
setSortOrder(SortOrder sortOrder)
Sorts the list using SortOrder. |
void |
toggleSortOrder()
Toggles the sort order of the items. |
protected void |
updateHighlighterUI()
Updates highlighter after updateUI changes. |
protected void |
updateOnFilterContentChanged()
method called on change notification from filterpipeline. |
protected void |
updateSortAfterComparatorChange()
Updates sort after comparator has changed. |
void |
updateUI()
Resets the UI property with the value from the current look and feel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String EXECUTE_BUTTON_ACTIONCOMMAND
protected FilterPipeline filters
protected CompoundHighlighter compoundHighlighter
protected ComponentAdapter dataAdapter
Constructor Detail |
---|
public JXList()
JXList
with an empty model and filters disabled.
public JXList(ListModel dataModel)
JXList
that displays the elements in the
specified, non-null
model and filters disabled.
dataModel
- the data model for this list
IllegalArgumentException
- if dataModel
is null
public JXList(Object[] listData)
JXList
that displays the elements in
the specified array and filters disabled.
listData
- the array of Objects to be loaded into the data model
IllegalArgumentException
- if listData
is null
public JXList(Vector<?> listData)
JXList
that displays the elements in
the specified Vector
and filtes disabled.
listData
- the Vector
to be loaded into the
data model
IllegalArgumentException
- if listData
is null
public JXList(boolean filterEnabled)
JXList
with an empty model and
filterEnabled property.
filterEnabled
- boolean
to determine if
filtering/sorting is enabledpublic JXList(ListModel dataModel, boolean filterEnabled)
JXList
with the specified model and
filterEnabled property.
dataModel
- the data model for this listfilterEnabled
- boolean
to determine if
filtering/sorting is enabled
IllegalArgumentException
- if dataModel
is null
public JXList(Object[] listData, boolean filterEnabled)
JXList
that displays the elements in
the specified array and filterEnabled property.
listData
- the array of Objects to be loaded into the data modelfilterEnabled
- boolean
to determine if filtering/sorting
is enabled
IllegalArgumentException
- if listData
is null
public JXList(Vector<?> listData, boolean filterEnabled)
JXList
that displays the elements in
the specified Vector
and filtersEnabled property.
listData
- the Vector
to be loaded into the
data modelfilterEnabled
- boolean
to determine if filtering/sorting
is enabled
IllegalArgumentException
- if listData
is null
Method Detail |
---|
protected void doFind()
public Searchable getSearchable()
setSearchable(Searchable)
,
ListSearchable
public void setSearchable(Searchable searchable)
searchable
- the Searchable to use for this component, may be null to indicate
using the list's default searchable.getSearchable()
public void setRolloverEnabled(boolean rolloverEnabled)
This can be enabled to show "live" rollover behaviour, f.i. the cursor over a cell rendered by a JXHyperlink.
Default value is disabled.
rolloverEnabled
- a boolean indicating whether or not the rollover
functionality should be enabled.isRolloverEnabled()
,
getLinkController()
,
createRolloverProducer()
,
RolloverRenderer
public boolean isRolloverEnabled()
setRolloverEnabled(boolean)
protected ListRolloverController<JXList> getLinkController()
PENDING JW: rename to getRolloverController
setRolloverEnabled(boolean)
,
createLinkController()
,
RolloverController
protected ListRolloverController<JXList> createLinkController()
getLinkController()
,
RolloverController
protected RolloverProducer createRolloverProducer()
RolloverProducer
to use with this treesetRolloverEnabled(boolean)
public void resetSortOrder()
public void toggleSortOrder()
The exact behaviour is defined by the SortController's toggleSortOrder implementation. Typically a unsorted column is sorted in ascending order, a sorted column's order is reversed.
PENDING: where to get the comparator from?
public void setSortOrder(SortOrder sortOrder)
sortOrder
- the sort order to use. If null or SortOrder.UNSORTED,
this method has the same effect as resetSortOrder();public SortOrder getSortOrder()
public Comparator<?> getComparator()
setComparator(Comparator)
public void setComparator(Comparator<?> comparator)
comparator
- the comparator to use.protected void updateSortAfterComparatorChange()
protected SortController getSortController()
SortController
may be nullpublic Object getElementAt(int viewIndex)
viewIndex
- the index in view coordinates
IndexOutOfBoundsException
- if viewIndex < 0 or viewIndex >=
getElementCount()public int getElementCount()
public int convertIndexToModel(int viewIndex)
viewIndex
- index in view coordinates
IndexOutOfBoundsException
- if viewIndex < 0 or viewIndex >= getElementCount()public int convertIndexToView(int modelIndex)
modelIndex
- index in model coordinates
public ListModel getWrappedModel()
public void setFilterEnabled(boolean enabled)
enabled
-
IllegalStateException
- if trying to disable again.public boolean isFilterEnabled()
setFilterEnabled(boolean)
public void setSelectionModel(ListSelectionModel newModel)
selectionModel
for the list to a
non-null
ListSelectionModel
implementation. The selection model handles the task of making single
selections, selections of contiguous ranges, and non-contiguous
selections.
This is a JavaBeans bound property.
Overridden to update selectionMapper
setSelectionModel
in class JList
newModel
- the ListSelectionModel
that
implements the selectionsJList.getSelectionModel()
public void setModel(ListModel model)
PropertyChangeListeners
.
This is a JavaBeans bound property.
Sets the underlying data model. Note that if isFilterEnabled you must call getWrappedModel to access the model given here. In this case getModel returns a wrapper around the data!
setModel
in class JList
model
- the data model for this list.JList.getModel()
protected SelectionMapper getSelectionMapper()
public FilterPipeline getFilters()
FilterPipeline
assigned to this list, or
null if !isFiltersEnabled().public void setFilters(FilterPipeline pipeline)
pipeline
- the FilterPipeline
to use, null removes
all filters.
IllegalStateException
- if !isFilterEnabled()protected PipelineListener getFilterPipelineListener()
protected PipelineListener createPipelineListener()
protected void updateOnFilterContentChanged()
protected ComponentAdapter getComponentAdapter()
protected ComponentAdapter getComponentAdapter(int index)
index
- the row index in view coordinates, must be valid.
public void setHighlighters(Highlighter... highlighters)
Highlighter
s to the table, replacing any old settings.
None of the given Highlighters must be null.This is a bound property.
Note: as of version #1.257 the null constraint is enforced strictly. To remove all highlighters use this method without param.
highlighters
- zero or more not null highlighters to use for renderer decoration.
NullPointerException
- if array is null or array contains null values.getHighlighters()
,
addHighlighter(Highlighter)
,
removeHighlighter(Highlighter)
public Highlighter[] getHighlighters()
Highlighter
s used by this table.
Maybe empty, but guarantees to be never null.
setHighlighters(Highlighter[])
public void addHighlighter(Highlighter highlighter)
Highlighter
to the end of the list of used
Highlighter
s. The argument must not be null.
highlighter
- the Highlighter
to add, must not be null.
NullPointerException
- if Highlighter
is null.removeHighlighter(Highlighter)
,
setHighlighters(Highlighter[])
public void removeHighlighter(Highlighter highlighter)
Does nothing if the Highlighter is not contained.
highlighter
- the Highlighter to remove.addHighlighter(Highlighter)
,
setHighlighters(Highlighter...)
protected CompoundHighlighter getCompoundHighlighter()
protected ChangeListener getHighlighterChangeListener()
ChangeListener
to use with highlighters. Lazily
creates the listener.
not-null
protected ChangeListener createHighlighterChangeListener()
Here: repaints the table on receiving a stateChanged.
public String getStringAt(int row)
row
- the row index of the cell in view coordinates
protected ListCellRenderer createDefaultCellRenderer()
DefaultListRenderer
.
public ListCellRenderer getCellRenderer()
Overridden to return the delegating renderer which is wrapped around the original to support highlighting. The returned renderer is of type DelegatingRenderer and guaranteed to not-null
getCellRenderer
in class JList
ListCellRenderer
setCellRenderer(ListCellRenderer)
,
JXList.DelegatingRenderer
public ListCellRenderer getWrappedCellRenderer()
setCellRenderer(ListCellRenderer)
public void setCellRenderer(ListCellRenderer renderer)
prototypeCellValue
was set then the
fixedCellWidth
and fixedCellHeight
properties are set as well. Only one PropertyChangeEvent
is generated however - for the cellRenderer
property.
The default value of this property is provided by the ListUI delegate, i.e. by the look and feel implementation.
To see an example which sets the cell renderer, see the class description above.
This is a JavaBeans bound property.
Overridden to wrap the given renderer in a DelegatingRenderer to support highlighting.
Note: the wrapping implies that the renderer returned from the getCellRenderer
is not the renderer as given here, but the wrapper. To access the original,
use getWrappedCellRenderer
.
setCellRenderer
in class JList
renderer
- the ListCellRenderer
that paints list cellsgetWrappedCellRenderer()
,
getCellRenderer()
public void updateUI()
Overridden to update renderer and Highlighters.
updateUI
in class JList
UIManager.getUI(javax.swing.JComponent)
protected void updateHighlighterUI()
updateUI
changes.
UIDependent
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |