Serializable
, UIDependent
public class CheckBoxProvider extends ComponentProvider<AbstractButton>
This implementation respects a BooleanValue and a StringValue to configure the button's selected and text property. By default, the selected is mapped to a Boolean-type value and the text is empty.
To allow mapping to different types, client code can supply a custom StringValue which also implements BooleanValue. F.i. to render a cell value of type TableColumnExt with the column's visibility mapped to the selected and the column's title to the text:
BooleanValue bv = new BooleanValue(){
public boolean getBoolean(Object value) {
if (value instanceof TableColumnExt)
return ((TableColumnExt) value).isVisible();
return false;
}
};
StringValue sv = new StringValue() {
public String getString(Object value) {
if (value instanceof TableColumnExt)
return ((TableColumnExt) value).getTitle();
return "";
}
};
list.setCellRenderer(new DefaultListRenderer(
new CheckBoxProvider(new MappedValue(sv, null, bv), JLabel.LEADING)));
BooleanValue
,
StringValue
,
MappedValue
,
Serialized Formalignment, defaultVisuals, formatter, rendererComponent
Constructor | Description |
---|---|
CheckBoxProvider() |
Instantiates a CheckBoxProvider with default properties.
|
CheckBoxProvider(StringValue stringValue) |
Instantiates a CheckBoxProvider with the given StringValue and default
alignment.
|
CheckBoxProvider(StringValue stringValue,
int alignment) |
Instantiates a CheckBoxProvider with the given StringValue and
alignment.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
configureState(CellContext context) |
Configures the rendering component's state from the
given cell context.
|
protected AbstractButton |
createRendererComponent() |
Factory method to create and return the component to use for rendering.
|
protected void |
format(CellContext context) |
Formats the renderering component's content from the
given cell context.
|
protected boolean |
getValueAsBoolean(CellContext context) |
Returns a boolean representation of the content.
|
boolean |
isBorderPainted() |
Returns the border painted flag.
|
void |
setBorderPainted(boolean borderPainted) |
Sets the border painted flag.
|
configureContent, configureVisuals, createDefaultVisuals, getDefaultVisuals, getHorizontalAlignment, getRendererComponent, getString, getStringValue, getValueAsIcon, getValueAsString, setHorizontalAlignment, setStringValue, updateUI
public CheckBoxProvider()
public CheckBoxProvider(StringValue stringValue)
stringValue
- the StringValue to use for formatting.public CheckBoxProvider(StringValue stringValue, int alignment)
stringValue
- the StringValue to use for formatting.alignment
- the horizontalAlignment.public boolean isBorderPainted()
setBorderPainted(boolean)
public void setBorderPainted(boolean borderPainted)
The default value is true.
borderPainted
- the borderPainted property to configure
the underlying checkbox with.isBorderPainted()
protected void format(CellContext context)
Overridden to set the button's selected state and text.
PENDING: set icon?
format
in class ComponentProvider<AbstractButton>
context
- the cell context to configure from, must not be null.getValueAsBoolean(CellContext)
,
ComponentProvider.getValueAsString(CellContext)
protected boolean getValueAsBoolean(CellContext context)
This method messages the
BooleanValue
to get the boolean rep. If none available,
checks for Boolean type directly and returns its value. Returns
false otherwise.
PENDING: fallback to check for boolean is convenient .. could cleanup to use a default BooleanValue instead.
context
- the cell context, must not be null.protected void configureState(CellContext context)
Here: set's the buttons horizontal alignment and borderpainted properties to this provider's properties.
configureState
in class ComponentProvider<AbstractButton>
context
- the cell context to configure from, must not be null.protected AbstractButton createRendererComponent()
Here: returns a JCheckBox as rendering component.
createRendererComponent
in class ComponentProvider<AbstractButton>
Copyright © 2018. All rights reserved.