public class HyperlinkProvider extends ComponentProvider<JXHyperlink> implements RolloverRenderer
The renderer is configured with a LinkAction
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
Modifier and Type | Field and Description |
---|---|
private AbstractHyperlinkAction<Object> |
linkAction |
protected Class<?> |
targetClass |
alignment, defaultVisuals, formatter, rendererComponent
Constructor and Description |
---|
HyperlinkProvider()
Instantiate a LinkRenderer with null LinkAction and null
targetClass.
|
HyperlinkProvider(AbstractHyperlinkAction linkAction)
Instantiate a LinkRenderer with the LinkAction to use with
target values.
|
HyperlinkProvider(AbstractHyperlinkAction linkAction,
Class<?> targetClass)
Instantiate a LinkRenderer with a LinkAction to use with
target values and the type of values the action can cope with.
|
Modifier and Type | Method and Description |
---|---|
protected void |
configureState(CellContext context)
Configures the rendering component's state from the
given cell context.
|
protected AbstractHyperlinkAction |
createDefaultLinkAction()
default action - does nothing... except showing the target.
|
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.
|
String |
getString(Object value)
Returns a string representation of the content.
|
boolean |
isEnabled() |
boolean |
isTargetable(Object target)
decides if the given target is acceptable for setTarget.
|
void |
setLinkAction(AbstractHyperlinkAction linkAction)
Sets the LinkAction for handling the values.
|
void |
setLinkAction(AbstractHyperlinkAction 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.
|
configureContent, configureVisuals, createDefaultVisuals, getDefaultVisuals, getHorizontalAlignment, getRendererComponent, getStringValue, getValueAsIcon, getValueAsString, setHorizontalAlignment, setStringValue, updateUI
private AbstractHyperlinkAction<Object> linkAction
protected Class<?> targetClass
public HyperlinkProvider()
public HyperlinkProvider(AbstractHyperlinkAction linkAction)
linkAction
- the action that acts on values.public HyperlinkProvider(AbstractHyperlinkAction linkAction, Class<?> targetClass)
It's up to developers to take care of matching types.
linkAction
- the action that acts on values.targetClass
- the type of values the action can handle.public void setTargetClass(Class<?> targetClass)
PENDING: make sense to set independently of LinkAction?
targetClass
- the type of values the action can handle.public void setLinkAction(AbstractHyperlinkAction linkAction)
The action is assumed to be able to cope with any type, that is this method is equivalent to setLinkAction(linkAction, null).
linkAction
- public void setLinkAction(AbstractHyperlinkAction linkAction, Class<?> targetClass)
PENDING: in the general case this is not independent of the targetClass. Need api to set them combined?
linkAction
- public boolean isTargetable(Object target)
target == null is acceptable for all types. targetClass == null is the same as Object.class
target
- the target to set.protected AbstractHyperlinkAction createDefaultLinkAction()
public boolean isEnabled()
isEnabled
in interface RolloverRenderer
public void doClick()
RolloverRenderer
doClick
in interface RolloverRenderer
public String getString(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 ...
PENDING JW: Needs to be overridden - doesn't comply to contract!. Not sure how to do it without disturbing the hyperlinks current setting? All hyperlink properties are defined by the LinkAction configured with the target ...
getString
in class ComponentProvider<JXHyperlink>
value
- the object to represent as string.protected void configureState(CellContext context)
Overridden to set the hyperlink's rollover state.
configureState
in class ComponentProvider<JXHyperlink>
context
- the cell context to configure from, must not be null.protected void format(CellContext context)
Forces foreground color to the one defined by hyperlink for unselected cells, doesn't change the foreground for selected (as darkish text on dark selection background might be unreadable, Issue #840-swingx). Not entirely safe because the unselected background might be dark as well. Need to find a better way in the long run. Until then, client code can use Highlighters to repair (which is nasty!).
PENDING JW: by-passes XXValues - state currently is completely defined by the action. Hmm ...
format
in class ComponentProvider<JXHyperlink>
context
- the cell context to configure from, must not be null.protected JXHyperlink createRendererComponent()
createRendererComponent
in class ComponentProvider<JXHyperlink>
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses