|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.renderer.ComponentProvider<T>
public abstract class ComponentProvider<T extends javax.swing.JComponent>
Abstract base class of a provider for a cell rendering component. Configures
the component's content and default visuals depending on the renderee's state
as captured in a CellContext
. It's basically re-usable across
all types of renderees (JTable, JList, JTree).
To ease content configuration, it supports a pluggable
StringValue
which purpose is to create and return a string
representation of a given object. Implemenations of a ComponentProvider can
use it to configure their rendering component as appropriate.
F.i. to show a Contributor cell object as "Busywoman, Herta" implement a custom StringValue and use it in a text rendering provider. (Note that SwingX default implementations of Table/List/TreeCellRenderer have convenience constructors to take the converter and create a default LabelProvider which uses it).
StringValue stringValue = new StringValue() {
public String getString(Object value) {
if (!(value instanceof Contributor))
return TO_STRING.getString(value);
Contributor contributor = (Contributor) value;
return contributor.lastName + ", " + contributor.firstName;
}
};
table.setDefaultRenderer(Contributor.class, new DefaultTableRenderer(
stringValue));
list.setCellRenderer(new DefaultListRenderer(stringValue));
tree.setCellRenderer(new DefaultTreeRenderer(stringValue));
To ease handling of formatted localizable content, there's a
FormatStringValue
which is pluggable with a
Format
. F.i. to show a Date's time in the default Locale's SHORT version and right align the cell
StringValue stringValue = new FormatStringValue(
DateFormat.getTimeInstance(DateFormat.SHORT));
table.getColumnExt("timeID").setCellRenderer(
new DefaultTableRenderer(stringValue, JLabel.RIGHT);
Guarantees to completely configure the visual properties listed below. As a
consequence, client code (f.i. in Highlighter
s) can safely
change them without long-lasting visual artefacts.
DefaultVisuals
(which handles the first eight items)
subclasses have to guarantee the alignment only.
StringValue
,
FormatStringValue
,
IconValue
,
BooleanValue
,
CellContext
,
DefaultTableRenderer
,
DefaultListRenderer
,
DefaultTreeRenderer
,
DefaultVisuals
,
Serialized FormConstructor Summary | |
---|---|
ComponentProvider()
Instantiates a component provider with LEADING horizontal alignment and default to-String converter. |
|
ComponentProvider(StringValue converter)
Instantiates a component provider with LEADING horizontal alignment and the given converter. |
|
ComponentProvider(StringValue converter,
int alignment)
Instantiates a LabelProvider with given to-String converter and given horizontal alignment. |
Method Summary | |
---|---|
int |
getHorizontalAlignment()
Returns the horizontal alignment. |
T |
getRendererComponent(CellContext context)
Configures and returns an appropriate component to render a cell in the given context. |
java.lang.String |
getString(java.lang.Object value)
Returns a string representation of the content. |
StringValue |
getStringValue()
Returns the StringValue to use for obtaining the String representation. |
void |
setHorizontalAlignment(int alignment)
Sets the horizontal alignment property to configure the component with. |
void |
setStringValue(StringValue formatter)
Sets the StringValue to use. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ComponentProvider()
public ComponentProvider(StringValue converter)
converter
- the converter to use for mapping the cell value to a
String representation.public ComponentProvider(StringValue converter, int alignment)
converter
- the converter to use for mapping the cell value to a
String representation.alignment
- the horizontal alignment.Method Detail |
---|
public T getRendererComponent(CellContext context)
context
- the cell context to configure from
public void setHorizontalAlignment(int alignment)
alignment
- the horizontal alignment to use when configuring the
rendering component.public int getHorizontalAlignment()
setHorizontalAlignment(int)
public void setStringValue(StringValue formatter)
StringValue.TO_STRING
.
formatter
- the format to use.public StringValue getStringValue()
public java.lang.String getString(java.lang.Object value)
This method guarantees to return the same string representation as would appear in the renderer, given that the corresponding cellContext has the same value as the parameter passed-in here. That is (assuming that the rendering component has a getText())
if (equals(value, context.getValue()) {
assertEquals(provider.getString(value),
provider.getRenderingComponent(context).getText());
}
This implementation simply delegates to its StringValue. Subclasses might
need to override to comply.
This is a second attempt - the driving force is the need for a consistent string representation across all (new and old) themes: rendering, (pattern) filtering/highlighting, searching, auto-complete ...
value
- the object to represent as string.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |