|
||||||||||
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.setAutoCreateRowSorter(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: JXList needs a specific ui-delegate - BasicXListUI and subclasses - which is aware of model vs. view coordiate systems and which controls the synchronization of selection/dataModel and sorter state. SwingX comes with a subclass for Synth.
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 autoCreateRowSorter)
Constructs a JXList with an empty model and
automatic creation of a RowSorter as given. |
|
JXList(ListModel dataModel)
Constructs a JXList that displays the elements in the
specified, non-null model and automatic creation of a RowSorter disabled. |
|
JXList(ListModel dataModel,
boolean autoCreateRowSorter)
Constructs a JXList with the specified model and
automatic creation of a RowSorter as given. |
|
JXList(Object[] listData)
Constructs a JXList that displays the elements in
the specified array and automatic creation of a RowSorter disabled. |
|
JXList(Object[] listData,
boolean autoCreateRowSorter)
Constructs a JXList that displays the elements in
the specified array and automatic creation of a RowSorter as given. |
|
JXList(Vector<?> listData)
Constructs a JXList that displays the elements in
the specified Vector and automatic creation of a RowSorter disabled. |
|
JXList(Vector<?> listData,
boolean autoCreateRowSorter)
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. |
protected void |
configureSorterProperties()
Propagates sort-related properties from table/columns to the sorter if it is of type SortController, does nothing otherwise. |
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 RowSorter<? extends ListModel> |
createDefaultRowSorter()
Creates and returns the default RowSorter. |
protected StringValueRegistry |
createDefaultStringValueRegistry()
Creates and returns the default registry for StringValues. |
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. |
boolean |
getAutoCreateRowSorter()
Returns true if whenever the model changes, a new
RowSorter should be created and installed
as the table's sorter; otherwise, returns false . |
ListCellRenderer |
getCellRenderer()
Returns the object responsible for painting 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. |
protected boolean |
getControlsSorterProperties()
Returns a boolean indicating whether the table configures the sorter's properties. |
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. |
int |
getNextMatch(String prefix,
int startIndex,
Position.Bias bias)
Returns the next list element whose toString value
starts with the given prefix. |
RowFilter<?,?> |
getRowFilter()
Returns the filter of the sorter, if available and of type SortController. |
RowSorter<? extends ListModel> |
getRowSorter()
Returns the object responsible for sorting. |
Searchable |
getSearchable()
Returns a Searchable for this component, guaranteed to be not null. |
Object |
getSelectedValue()
Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. |
Object[] |
getSelectedValues()
Returns an array of all the selected values, in increasing order based on their indices in the list and taking into account sourting and filtering. |
protected SortController<? extends ListModel> |
getSortController()
Returns the currently active SortController. |
SortOrder |
getSortOrder()
Returns the SortOrder. |
SortOrder[] |
getSortOrderCycle()
Returns the sortOrder cycle used when toggle sorting this table's columns, guaranteed to be not null. |
boolean |
getSortsOnUpdates()
Returns true if a sort should happen when the underlying model is updated; otherwise, returns false. |
String |
getStringAt(int row)
Returns the string representation of the cell value at the given position. |
protected StringValueRegistry |
getStringValueRegistry()
Returns the StringValueRegistry which defines the string representation for each cells. |
String |
getUIClassID()
Returns "ListUI" , the UIDefaults key used to look
up the name of the javax.swing.plaf.ListUI class that defines
the look and feel for this component. |
ListCellRenderer |
getWrappedCellRenderer()
Returns the renderer installed by client code or the default if none has been set. |
ListModel |
getWrappedModel()
Deprecated. no longer used - custom ui-delegate does-the-right-thing when accessing elements. |
protected boolean |
hasSortController()
Returns a boolean indicating whether the table has a SortController. |
void |
invalidateCellSizeCache()
Invalidates cell size caching in the ui delegate. |
boolean |
isRolloverEnabled()
Returns a boolean indicating whether or not rollover support is enabled. |
boolean |
isSortable()
Returns the table's sortable property. |
void |
removeHighlighter(Highlighter highlighter)
Removes the given Highlighter. |
void |
resetSortOrder()
Resets sorting of all columns. |
void |
setAutoCreateRowSorter(boolean autoCreateRowSorter)
Specifies whether a RowSorter should be created for the
list whenever its model changes. |
void |
setCellRenderer(ListCellRenderer renderer)
Sets the delegate that is used to paint each cell in the list. |
void |
setComparator(Comparator<?> comparator)
Sets the comparator to use for sorting. |
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, notifies property change listeners, and then clears the list's selection. |
void |
setRolloverEnabled(boolean rolloverEnabled)
Sets the property to enable/disable rollover support. |
void |
setRowFilter(RowFilter<? super ListModel,? super Integer> filter)
Sets the filter to the sorter, if available and of type SortController. |
void |
setRowSorter(RowSorter<? extends ListModel> sorter)
Sets the RowSorter . |
void |
setSearchable(Searchable searchable)
Sets the Searchable for this component. |
void |
setSelectedValue(Object anObject,
boolean shouldScroll)
Selects the specified object from the list, taking into account sorting and filtering. |
void |
setSortable(boolean sortable)
Sets "sortable" property indicating whether or not this list isSortable. |
void |
setSortOrder(SortOrder sortOrder)
Sorts the list using SortOrder. |
void |
setSortOrderCycle(SortOrder... cycle)
Sets the sortorder cycle used when toggle sorting this table's columns. |
void |
setSortsOnUpdates(boolean sortsOnUpdates)
If true, specifies that a sort should happen when the underlying model is updated ( rowsUpdated is invoked). |
void |
toggleSortOrder()
Toggles the sort order of the list. |
protected void |
updateHighlighterUI()
Updates highlighter after updateUI changes. |
protected void |
updateSortAfterComparatorChange()
Updates the SortController's comparator, if available. |
void |
updateUI()
Resets the ListUI property by setting it to the value provided
by 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 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 automatic creation of a RowSorter 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 automatic creation of a RowSorter 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 automatic creation of a RowSorter disabled.
listData
- the Vector
to be loaded into the
data model
IllegalArgumentException
- if listData
is null
public JXList(boolean autoCreateRowSorter)
JXList
with an empty model and
automatic creation of a RowSorter as given.
autoCreateRowSorter
- boolean
to determine if
a RowSorter should be created automatically.public JXList(ListModel dataModel, boolean autoCreateRowSorter)
JXList
with the specified model and
automatic creation of a RowSorter as given.
dataModel
- the data model for this listautoCreateRowSorter
- boolean
to determine if
a RowSorter should be created automatically.
IllegalArgumentException
- if dataModel
is null
public JXList(Object[] listData, boolean autoCreateRowSorter)
JXList
that displays the elements in
the specified array and automatic creation of a RowSorter as given.
listData
- the array of Objects to be loaded into the data modelautoCreateRowSorter
- boolean
to determine if
a RowSorter should be created automatically.
IllegalArgumentException
- if listData
is null
public JXList(Vector<?> listData, boolean autoCreateRowSorter)
JXList
that displays the elements in
the specified Vector
and filtersEnabled property.
listData
- the Vector
to be loaded into the
data modelautoCreateRowSorter
- boolean
to determine if
a RowSorter should be created automatically.
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 int getNextMatch(String prefix, int startIndex, Position.Bias bias)
toString
value
starts with the given prefix. Overridden to cope with sorting/filtering, taking over completely.
getNextMatch
in class JList
prefix
- the string to test for a matchstartIndex
- the index for starting the searchbias
- the search direction, either
Position.Bias.Forward or Position.Bias.Backward.
-1
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 boolean getAutoCreateRowSorter()
true
if whenever the model changes, a new
RowSorter
should be created and installed
as the table's sorter; otherwise, returns false
.
RowSorter
should be created when
the model changespublic void setAutoCreateRowSorter(boolean autoCreateRowSorter)
RowSorter
should be created for the
list whenever its model changes.
When setAutoCreateRowSorter(true)
is invoked, a RowSorter
is immediately created and installed on the
list. While the autoCreateRowSorter
property remains
true
, every time the model is changed, a new RowSorter
is created and set as the list's row sorter.
The default value is false.
autoCreateRowSorter
- whether or not a RowSorter
should be automatically createdprotected RowSorter<? extends ListModel> createDefaultRowSorter()
public RowSorter<? extends ListModel> getRowSorter()
public void setRowSorter(RowSorter<? extends ListModel> sorter)
RowSorter
. RowSorter
is used
to provide sorting and filtering to a JXList
.
This method clears the selection and resets any variable row heights.
If the underlying model of the RowSorter
differs from
that of this JXList
undefined behavior will result.
sorter
- the RowSorter
; null
turns
sorting offprotected void configureSorterProperties()
public void setSortable(boolean sortable)
sortable
- boolean indicating whether or not this table supports
sortable columnsTableColumnExt.isSortable()
public boolean isSortable()
public void setSortsOnUpdates(boolean sortsOnUpdates)
rowsUpdated
is invoked). For
example, if this is true and the user edits an entry the
location of that item in the view may change. The default is
true.
sortsOnUpdates
- whether or not to sort on update eventspublic boolean getSortsOnUpdates()
public void setSortOrderCycle(SortOrder... cycle)
cycle
- the sequence of zero or more not-null SortOrders to cycle through.
NullPointerException
- if the array or any of its elements are nullpublic SortOrder[] getSortOrderCycle()
public Comparator<?> getComparator()
setComparator(Comparator)
public void setComparator(Comparator<?> comparator)
Note: as of post-1.0 the property is propagated to the SortController, if available. Whether or not a change triggers a re-sort is up to either the concrete controller implementation (the default doesn't) or client code. This behaviour is different from old SwingX style sorting.
comparator
- the comparator to use.protected void updateSortAfterComparatorChange()
public void setRowFilter(RowFilter<? super ListModel,? super Integer> filter)
filter
- the filter used to determine what entries should be
includedpublic RowFilter<?,?> getRowFilter()
PENDING JW: generics? had to remove return type from getSortController to make this compilable, so probably wrong.
public void resetSortOrder()
PENDING JW: method name - consistent in SortController and here.
public void toggleSortOrder()
The exact behaviour is defined by the SortController's toggleSortOrder implementation. Typically a unsorted list is sorted in ascending order, a sorted list's order is reversed.
public void setSortOrder(SortOrder sortOrder)
sortOrder
- the sort order to use.public SortOrder getSortOrder()
protected SortController<? extends ListModel> getSortController()
PENDING JW: swaying about hiding or not - currently the only way to make the view not configure a RowSorter of type SortController is to let this return null.
SortController
may be nullprotected boolean hasSortController()
getSortController()
protected boolean getControlsSorterProperties()
This implementation returns true if the sorter is of type SortController. Note: the synchronization is unidirection from the table to the sorter. Changing the sorter under the table's feet might lead to undefined behaviour.
public Object getElementAt(int viewIndex)
viewIndex
- the index in view coordinates
IndexOutOfBoundsException
- if viewIndex < 0 or viewIndex >=
getElementCount()public Object getSelectedValue()
null
if there is no selection.
This is a convenience method that simply returns the model value for
getMinSelectionIndex
, taking into account sorting and filtering.
getSelectedValue
in class JList
JList.getMinSelectionIndex()
,
JList.getModel()
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
public void setSelectedValue(Object anObject, boolean shouldScroll)
setSelectedValue
in class JList
anObject
- the object to selectshouldScroll
- true
if the list should scroll to display
the selected object, if one exists; otherwise false
public Object[] getSelectedValues()
getSelectedValues
in class JList
JList.isSelectedIndex(int)
,
JList.getModel()
,
JList.addListSelectionListener(javax.swing.event.ListSelectionListener)
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
@Deprecated public ListModel getWrappedModel()
public void setModel(ListModel model)
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()
,
JList.clearSelection()
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.
protected StringValueRegistry getStringValueRegistry()
Currently exposed for testing reasons, client code is recommended to not use nor override.
protected StringValueRegistry createDefaultStringValueRegistry()
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
cellRenderer
propertysetCellRenderer(ListCellRenderer)
,
JXList.DelegatingRenderer
public ListCellRenderer getWrappedCellRenderer()
setCellRenderer(ListCellRenderer)
public void setCellRenderer(ListCellRenderer renderer)
If the prototypeCellValue
property is non-null
,
setting the cell renderer also causes the fixedCellWidth
and
fixedCellHeight
properties to be re-calculated. 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.
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 invalidateCellSizeCache()
This implementation calls the corresponding method on BasicXListUI if available, does nothing otherwise.
public void updateUI()
ListUI
property by setting it to the value provided
by the current look and feel. If the current cell renderer was installed
by the developer (rather than the look and feel itself), this also causes
the cell renderer and its children to be updated, by calling
SwingUtilities.updateComponentTreeUI
on it. Overridden to update renderer and Highlighters.
updateUI
in class JList
UIManager.getUI(javax.swing.JComponent)
,
SwingUtilities.updateComponentTreeUI(java.awt.Component)
public String getUIClassID()
javax.swing.JList
"ListUI"
, the UIDefaults
key used to look
up the name of the javax.swing.plaf.ListUI
class that defines
the look and feel for this component.
getUIClassID
in class JList
JComponent.getUIClassID()
,
UIDefaults.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 |