org.jdesktop.swingx.renderer
Class ButtonProvider

java.lang.Object
  extended by org.jdesktop.swingx.renderer.ComponentProvider<AbstractButton>
      extended by org.jdesktop.swingx.renderer.ButtonProvider
All Implemented Interfaces:
Serializable

public class ButtonProvider
extends ComponentProvider<AbstractButton>

A component provider which uses a 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 ButtonProvider(new MappedValue(sv, bv), JLabel.LEADING))); 
 
PENDING: rename ... this is actually a CheckBoxProvider.

See Also:
BooleanValue, StringValue, MappedValue, Serialized Form

Field Summary
 
Fields inherited from class org.jdesktop.swingx.renderer.ComponentProvider
alignment, defaultVisuals, formatter, rendererComponent
 
Constructor Summary
ButtonProvider()
          Instantiates a ButtonProvider with default properties.
ButtonProvider(StringValue stringValue)
           
ButtonProvider(StringValue stringValue, int alignment)
          Instantiates a ButtonProvider with the given StringValue and alignment.
 
Method Summary
protected  void configureState(CellContext context)
          Configures the renderering 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.
 
Methods inherited from class org.jdesktop.swingx.renderer.ComponentProvider
configureContent, configureVisuals, createRendererController, getHorizontalAlignment, getRendererComponent, getRendererController, getStringValue, getToStringConverter, getValueAsIcon, getValueAsString, setHorizontalAlignment, setToStringConverter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ButtonProvider

public ButtonProvider()
Instantiates a ButtonProvider with default properties.


ButtonProvider

public ButtonProvider(StringValue stringValue,
                      int alignment)
Instantiates a ButtonProvider with the given StringValue and alignment.

Parameters:
stringValue - the StringValue to use for formatting.
alignment - the horizontalAlignment.

ButtonProvider

public ButtonProvider(StringValue stringValue)
Parameters:
object -
Method Detail

isBorderPainted

public boolean isBorderPainted()
Returns the border painted flag.

Returns:
the borderpainted flag to use on the checkbox.
See Also:
setBorderPainted(boolean)

setBorderPainted

public void setBorderPainted(boolean borderPainted)
Sets the border painted flag. the underlying checkbox is configured with this value on every request.

The default value is true.

Parameters:
borderPainted - the borderPainted property to configure the underlying checkbox with.
See Also:
isBorderPainted()

format

protected void format(CellContext context)
Formats the renderering component's content from the given cell context.

Overridden to set the button's selected state and text.

PENDING: set icon?

Specified by:
format in class ComponentProvider<AbstractButton>
Parameters:
context - the cell context to configure from, must not be null.
See Also:
getValueAsBoolean(CellContext), ComponentProvider.getValueAsString(CellContext)

getValueAsBoolean

protected boolean getValueAsBoolean(CellContext context)
Returns a boolean representation of the content.

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.

Parameters:
context - the cell context, must not be null.
Returns:
a appropriate icon representation of the cell's content, or null if non if available.

configureState

protected void configureState(CellContext context)
Configures the renderering component's state from the given cell context.

Here: set's the buttons horizontal alignment and borderpainted properties to this controller's properties.

Specified by:
configureState in class ComponentProvider<AbstractButton>
Parameters:
context - the cell context to configure from, must not be null.

createRendererComponent

protected AbstractButton createRendererComponent()
Factory method to create and return the component to use for rendering.

Here: returns a JCheckBox as rendering component.

Specified by:
createRendererComponent in class ComponentProvider<AbstractButton>
Returns:
the component to use for rendering.