org.jdesktop.swingx.renderer
Class HyperlinkProvider

java.lang.Object
  extended by org.jdesktop.swingx.renderer.ComponentProvider<JXHyperlink>
      extended by org.jdesktop.swingx.renderer.HyperlinkProvider
All Implemented Interfaces:
Serializable, RolloverRenderer

public class HyperlinkProvider
extends ComponentProvider<JXHyperlink>
implements RolloverRenderer

Renderer for hyperlinks".

The renderer is configured with a LinkAction. It's mostly up to the developer to guarantee that the all values which are passed into the getXXRendererComponent(...) are compatible with T: she can provide a runtime class to check against. If it isn't the renderer will configure the action with a null target.

It's recommended to not use the given Action anywhere else in code, as it is updated on each getXXRendererComponent() call which might lead to undesirable side-effects.

Internally uses JXHyperlink as rendering component.

PENDING: can go from ButtonProvider?

PENDING: make renderer respect selected cell state.

PENDING: TreeCellRenderer has several issues

  1. no icons
  2. usual background highlighter issues

See Also:
Serialized Form

Field Summary
protected  Class<?> targetClass
           
 
Fields inherited from class org.jdesktop.swingx.renderer.ComponentProvider
alignment, defaultVisuals, formatter, rendererComponent
 
Constructor Summary
HyperlinkProvider()
          Instantiate a LinkRenderer with null LinkAction and null targetClass.
HyperlinkProvider(LinkAction linkAction)
          Instantiate a LinkRenderer with the LinkAction to use with target values.
HyperlinkProvider(LinkAction linkAction, Class targetClass)
          Instantiate a LinkRenderer with a LinkAction to use with target values and the type of values the action can cope with.
 
Method Summary
protected  void configureState(CellContext context)
          Configures the renderering component's state from the given cell context.
protected  LinkAction createDefaultLinkAction()
          default action - does nothing...
protected  JXHyperlink createRendererComponent()
          Factory method to create and return the component to use for rendering.
 void doClick()
          Same as AbstractButton.doClick().
protected  void format(CellContext context)
          Formats the renderering component's content from the given cell context. Overridden to set the LinkAction's target to the context's value, if targetable.
 boolean isEnabled()
           
 boolean isTargetable(Object target)
          decides if the given target is acceptable for setTarget.
 void setLinkAction(LinkAction linkAction)
          Sets the LinkAction for handling the values.
 void setLinkAction(LinkAction linkAction, Class targetClass)
          Sets the LinkAction for handling the values and the class the action can handle.
 void setTargetClass(Class targetClass)
          Sets the class the action is supposed to handle.
 
Methods inherited from class org.jdesktop.swingx.renderer.ComponentProvider
configureContent, configureVisuals, createRendererController, getHorizontalAlignment, getRendererComponent, getRendererController, getStringValue, getToStringConverter, setHorizontalAlignment, setToStringConverter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

targetClass

protected Class<?> targetClass
Constructor Detail

HyperlinkProvider

public HyperlinkProvider()
Instantiate a LinkRenderer with null LinkAction and null targetClass.


HyperlinkProvider

public HyperlinkProvider(LinkAction linkAction)
Instantiate a LinkRenderer with the LinkAction to use with target values.

Parameters:
linkAction - the action that acts on values.

HyperlinkProvider

public HyperlinkProvider(LinkAction linkAction,
                         Class targetClass)
Instantiate a LinkRenderer with a LinkAction to use with target values and the type of values the action can cope with.

It's up to developers to take care of matching types.

Parameters:
linkAction - the action that acts on values.
targetClass - the type of values the action can handle.
Method Detail

setTargetClass

public void setTargetClass(Class targetClass)
Sets the class the action is supposed to handle.

PENDING: make sense to set independently of LinkAction?

Parameters:
targetClass - the type of values the action can handle.

setLinkAction

public void setLinkAction(LinkAction linkAction)
Sets the LinkAction for handling the values.

The action is assumed to be able to cope with any type, that is this method is equivalent to setLinkAction(linkAction, null).

Parameters:
linkAction -

setLinkAction

public void setLinkAction(LinkAction linkAction,
                          Class targetClass)
Sets the LinkAction for handling the values and the class the action can handle.

PENDING: in the general case this is not independent of the targetClass. Need api to set them combined?

Parameters:
linkAction -

isTargetable

public boolean isTargetable(Object target)
decides if the given target is acceptable for setTarget.

target == null is acceptable for all types. targetClass == null is the same as Object.class

Parameters:
target - the target to set.
Returns:
true if setTarget can cope with the object, false otherwise.

createDefaultLinkAction

protected LinkAction createDefaultLinkAction()
default action - does nothing... except showing the target.

Returns:
a default LinkAction for showing the target.

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface RolloverRenderer
Returns:
true if rollover effects are on and clickable.

doClick

public void doClick()
Description copied from interface: RolloverRenderer
Same as AbstractButton.doClick(). It's up to client code to prepare the renderer's component before calling this method.

Specified by:
doClick in interface RolloverRenderer

createRendererComponent

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

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

configureState

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

Overridden to set the hyperlink's rollover state.

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

format

protected void format(CellContext context)
Formats the renderering component's content from the given cell context. Overridden to set the LinkAction's target to the context's value, if targetable.

PENDING: Forces foreground color to those defined by hyperlink - this should happen automatically? Hyperlink bug?

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