swingx
Version 2005-08-19

org.jdesktop.swingx
Class LinkRenderer

java.lang.Object
  extended by javax.swing.AbstractCellEditor
      extended by org.jdesktop.swingx.LinkRenderer
All Implemented Interfaces:
Serializable, CellEditor, ListCellRenderer, TableCellEditor, TableCellRenderer, TreeCellRenderer, RolloverRenderer

public class LinkRenderer
extends AbstractCellEditor
implements TableCellRenderer, TableCellEditor, ListCellRenderer, TreeCellRenderer, RolloverRenderer

A Renderer/Editor for "Links".

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 for both CellRenderer and CellEditor It's recommended to not reuse the same instance for both functions.

PENDING: make renderer respect selected cell state. PENDING: TreeCellRenderer has several issues - no icons - usual background highlighter issues

See Also:
Serialized Form

Field Summary
protected  Class<?> targetClass
           
 
Fields inherited from class javax.swing.AbstractCellEditor
changeEvent, listenerList
 
Constructor Summary
LinkRenderer()
          Instantiate a LinkRenderer with null LinkAction and null targetClass.
LinkRenderer(LinkAction linkAction)
          Instantiate a LinkRenderer with the LinkAction to use with target values.
LinkRenderer(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  LinkAction createDefaultLinkAction()
          default action - does nothing... except showing the target.
protected  JXHyperlink createHyperlink()
          creates and returns the hyperlink component used for rendering the value and activating the action on the target value.
 void doClick()
          Same as AbstractButton.doClick().
protected  void fireEditingStopped()
           
 Object getCellEditorValue()
           
 Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
           
 Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
           
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
           
 Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus)
           
 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 javax.swing.AbstractCellEditor
addCellEditorListener, cancelCellEditing, fireEditingCanceled, getCellEditorListeners, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.CellEditor
addCellEditorListener, cancelCellEditing, isCellEditable, removeCellEditorListener, shouldSelectCell, stopCellEditing
 

Field Detail

targetClass

protected Class<?> targetClass
Constructor Detail

LinkRenderer

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


LinkRenderer

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

Parameters:
linkAction - the action that acts on values.

LinkRenderer

public LinkRenderer(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.

createHyperlink

protected JXHyperlink createHyperlink()
creates and returns the hyperlink component used for rendering the value and activating the action on the target value.

Returns:
the hyperlink renderer component.

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

getListCellRendererComponent

public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus)
Specified by:
getListCellRendererComponent in interface ListCellRenderer

getTableCellRendererComponent

public Component getTableCellRendererComponent(JTable table,
                                               Object value,
                                               boolean isSelected,
                                               boolean hasFocus,
                                               int row,
                                               int column)
Specified by:
getTableCellRendererComponent in interface TableCellRenderer

getTableCellEditorComponent

public Component getTableCellEditorComponent(JTable table,
                                             Object value,
                                             boolean isSelected,
                                             int row,
                                             int column)
Specified by:
getTableCellEditorComponent in interface TableCellEditor

getCellEditorValue

public Object getCellEditorValue()
Specified by:
getCellEditorValue in interface CellEditor

fireEditingStopped

protected void fireEditingStopped()
Overrides:
fireEditingStopped in class AbstractCellEditor

getTreeCellRendererComponent

public Component getTreeCellRendererComponent(JTree tree,
                                              Object value,
                                              boolean isSelected,
                                              boolean expanded,
                                              boolean leaf,
                                              int row,
                                              boolean hasFocus)
Specified by:
getTreeCellRendererComponent in interface TreeCellRenderer

swingx
Version 2005-08-19