public class DefaultListRenderer extends AbstractRenderer implements ListCellRenderer
Note: core DefaultListCellRenderer shows either an icon or the element's toString representation, depending on whether or not the given value is of type icon or implementors. This renderer's empty/null provider constructor takes care of configuring the default provider with a converter which mimics that behaviour. When instantiating this renderer with any of the constructors which have converters as parameters, it's up to the client code to supply the appropriate converter, if needed:
StringValue sv = new StringValue() {
public String getString(Object value) {
if (value instanceof Icon) {
return "";
}
return StringValue.TO_STRING.getString(value);
}
};
StringValue lv = new MappedValue(sv, IconValue.ICON);
listRenderer = new DefaultListRenderer(lv, alignment);
ComponentProvider
,
StringValue
,
IconValue
,
MappedValue
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected ListCellContext |
cellContext |
componentController
Constructor and Description |
---|
DefaultListRenderer()
Instantiates a default list renderer with the default component
provider.
|
DefaultListRenderer(ComponentProvider<?> componentProvider)
Instantiates a ListCellRenderer with the given ComponentProvider.
|
DefaultListRenderer(StringValue converter)
Instantiates a default table renderer with a default component controller
using the given converter.
|
DefaultListRenderer(StringValue stringValue,
IconValue iconValue)
Instantiates a default list renderer with default component provider
using both converters.
|
DefaultListRenderer(StringValue stringValue,
IconValue iconValue,
int alignment)
Instantiates a default list renderer with default component provider
using both converters and the given alignment.
|
DefaultListRenderer(StringValue converter,
int alignment)
Instantiates a default list renderer with a default component
controller using the given converter and horizontal
alignment.
|
Modifier and Type | Method and Description |
---|---|
protected ComponentProvider<?> |
createDefaultComponentProvider()
The default ComponentProvider to use if no special.
|
private StringValue |
createDefaultStringValue()
Creates and returns the default StringValue for a JList.
|
Component |
getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
Returns a configured component, appropriate to render the given
list cell.
|
doClick, getComponentProvider, getString, isEnabled, setBackground, setForeground, updateUI
protected ListCellContext cellContext
public DefaultListRenderer()
public DefaultListRenderer(ComponentProvider<?> componentProvider)
LabelProvider
Note: the default provider is configured with a custom StringValue which behaves exactly as core DefaultListCellRenderer: depending on whether or not given value is of type icon or implementors, it shows either the icon or the element's toString.
componentProvider
- the provider of the configured component to
use for cell renderingpublic DefaultListRenderer(StringValue converter)
PENDING JW: how to guarantee core consistent icon handling? Leave to client code?
converter
- the converter to use for mapping the content value to a
String representation.public DefaultListRenderer(StringValue converter, int alignment)
converter
- the converter to use for mapping the
content value to a String representation.alignment
- the horizontal alignment.public DefaultListRenderer(StringValue stringValue, IconValue iconValue)
stringValue
- the converter to use for the string representationiconValue
- the converter to use for the icon representationpublic DefaultListRenderer(StringValue stringValue, IconValue iconValue, int alignment)
stringValue
- the converter to use for the string representationiconValue
- the converter to use for the icon representationalignment
- the rendering component's horizontal alignmentpublic Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
Note: The component's name is set to "List.cellRenderer" for the sake of Synth-based LAFs.
getListCellRendererComponent
in interface ListCellRenderer
list
- the JList
to render onvalue
- the value to assign to the cellisSelected
- true if cell is selectedcellHasFocus
- true if cell has focusindex
- the row index (in view coordinates) of the cell to renderprotected ComponentProvider<?> createDefaultComponentProvider()
createDefaultComponentProvider
in class AbstractRenderer
ComponentProvider
private StringValue createDefaultStringValue()
This is added to keep consistent with core list rendering which shows either the Icon (for Icon value types) or the default to-string for non-icon types.
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses