|
swingx Version 2009-07-31 |
|||||||||
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 ...
JXList supports sorting and filtering. It provides api to apply a specific sort order, to toggle the sort order and to reset a sort. Sort sequence can be configured by setting a custom comparator.
list.setFilterEnabled(true);
list.setComparator(myComparator);
list.setSortOrder(SortOrder.DESCENDING);
list.toggleSortOder();
list.resetSortOrder();
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, we are on the move right now.
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, JList.DropLocation |
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.BaselineResizeBehavior, 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
|
static String |
uiClassID
UI Class ID |
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 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()
Overridden to return the delegating renderer which is wrapped around the original to support highlighting. |
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 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 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. |
String |
getUIClassID()
|
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)
Overridden to wrap the given renderer in a DelegatingRenderer to support highlighting. |
void |
setComparator(Comparator<?> comparator)
Sets the comparator used. |
void |
setFilterEnabled(boolean enabled)
Enables/disables filtering support. |
void |
setHighlighters(Highlighter... highlighters)
Sets the Highlighter s to the table, replacing any old settings. |
void |
setModel(ListModel model)
Sets the underlying data model. |
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)
Overridden to update selectionMapper |
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 |
updateSortAfterComparatorChange()
Updates sort after comparator has changed. |
void |
updateUI()
Overridden to update renderer and Highlighters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String uiClassID
public static final String EXECUTE_BUTTON_ACTIONCOMMAND
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)
NOTE: Currently, this method has no effect - filtering/sorting of a JXList is disabled until SwingX is fully moved to the core style filtering/sorting.
Note: as an implementation side-effect calling this method clears the selection (done in super.setModel).
PENDING: cleanup state transitions!! - currently this can be safely applied once only to enable. Internal state is inconsistent if trying to disable again. As a temporary emergency measure, this will throw a IllegalStateException. see Issue #2-swinglabs.
enabled
-
IllegalStateException
- if trying to disable again.public boolean isFilterEnabled()
setFilterEnabled(boolean)
public void setSelectionModel(ListSelectionModel newModel)
Overridden to update selectionMapper
setSelectionModel
in class JList
public void setModel(ListModel model)
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.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
setCellRenderer(ListCellRenderer)
,
JXList.DelegatingRenderer
public ListCellRenderer getWrappedCellRenderer()
setCellRenderer(ListCellRenderer)
public void setCellRenderer(ListCellRenderer renderer)
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
getWrappedCellRenderer()
,
getCellRenderer()
public void updateUI()
Overridden to update renderer and Highlighters.
updateUI
in class JList
public String getUIClassID()
getUIClassID
in class JList
protected void updateHighlighterUI()
updateUI
changes.
UIDependent
|
swingx Version 2009-07-31 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |