|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.swingx.decorator.AbstractHighlighter
org.jdesktop.swingx.decorator.PainterHighlighter
public class PainterHighlighter
Highlighter implementation which uses a Painter to decorate the component.
As Painter implementations can be mutable and Highlighters have the responsibility to notify their own listeners about any changes which might effect the visuals, this class provides api to install/uninstall a listener to the painter, as appropriate. It takes care of Painters of type AbstractHighlighter by registering a PropertyChangeListener. Subclasses might override to correctly handle different types as well.
Subclasses might be implemented to change the Painter during the decoration process, which must not passed-on to the Highlighter's listeners. The default routing is controlled by a flag isAdjusting. This is set/reset in this implementation's highlight method to ease subclass' burden (and to keep backward compatibility with implementations preceding the introduction of the painter listener). That is, subclasses are free to change painter properties during the decoration.
As an example, a ValueBasedPainterHighlighter might safely change any painter property to decorate a component depending on content.
@Override
protected Component doHighlight(Component renderer, ComponentAdapter adapter) {
float end = getEndOfGradient((Number) adapter.getValue());
RelativePainter painter = (RelativePainter) getPainter();
painter.setXFraction(end);
((PainterAware) renderer).setPainter(painter);
return renderer;
}
@Override
protected boolean canHighlight(Component renderer, ComponentAdapter adapter) {
return super.canHighlight(renderer, adapter) &&
(adapter.getValue() instanceof Number);
}
NOTE: this will change once the Painter api is stable.
Field Summary |
---|
Fields inherited from class org.jdesktop.swingx.decorator.AbstractHighlighter |
---|
listenerList |
Constructor Summary | |
---|---|
PainterHighlighter()
Instantiates a PainterHighlighter with null painter and default predicate. |
|
PainterHighlighter(HighlightPredicate predicate)
Instantiates a PainterHighlighter with null painter which uses the given predicate. |
|
PainterHighlighter(HighlightPredicate predicate,
Painter painter)
Instantiates a PainterHighlighter with the given painter and predicate. |
|
PainterHighlighter(Painter painter)
Instantiates a PainterHighlighter with the given Painter and default predicate. |
Method Summary | |
---|---|
protected boolean |
canHighlight(Component component,
ComponentAdapter adapter)
Subclasses may override to further limit the highlighting based on Highlighter state, f.i. |
protected PropertyChangeListener |
createPainterListener()
Creates and returns the property change listener used to listen to changes of the painter. |
protected Component |
doHighlight(Component component,
ComponentAdapter adapter)
Apply the highlights. |
Painter |
getPainter()
Returns to Painter used in this Highlighter. |
protected PropertyChangeListener |
getPainterListener()
Lazyly creates and returns the property change listener used to listen to changes of the painter. |
Component |
highlight(Component component,
ComponentAdapter adapter)
Decorates the specified component for the given component adapter. |
protected void |
installPainterListener()
Installs a listener to the painter if appropriate. |
void |
setPainter(Painter painter)
Sets the Painter to use in this Highlighter, may be null. |
protected void |
uninstallPainterListener()
Uninstalls a listener from the painter if appropriate. |
Methods inherited from class org.jdesktop.swingx.decorator.AbstractHighlighter |
---|
addChangeListener, areEqual, fireStateChanged, getChangeListeners, getHighlightPredicate, removeChangeListener, setHighlightPredicate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PainterHighlighter()
public PainterHighlighter(HighlightPredicate predicate)
predicate
- the HighlightPredicate which controls the highlight
application.public PainterHighlighter(Painter painter)
painter
- the painter to usepublic PainterHighlighter(HighlightPredicate predicate, Painter painter)
predicate
- painter
- Method Detail |
---|
public Painter getPainter()
public void setPainter(Painter painter)
painter
- the Painter to uses for decoration.protected void installPainterListener()
protected void uninstallPainterListener()
protected final PropertyChangeListener getPainterListener()
protected PropertyChangeListener createPainterListener()
This implementation fires a stateChanged on receiving any propertyChange, if the isAdjusting flag is false. Otherwise does nothing.
public Component highlight(Component component, ComponentAdapter adapter)
Overridden to set/reset the flag indicating whether or not painter's property changes should be passed on to the Highlighter's listener.
highlight
in interface Highlighter
highlight
in class AbstractHighlighter
component
- the cell renderer component that is to be decoratedadapter
- the ComponentAdapter for this decorate operation
AbstractHighlighter.canHighlight(Component, ComponentAdapter)
,
AbstractHighlighter.doHighlight(Component, ComponentAdapter)
,
AbstractHighlighter.getHighlightPredicate()
protected Component doHighlight(Component component, ComponentAdapter adapter)
This implementation sets the painter if it is not null. Does nothing otherwise.
doHighlight
in class AbstractHighlighter
component
- the cell renderer component that is to be decoratedadapter
- the ComponentAdapter for this decorate operationAbstractHighlighter.highlight(Component, ComponentAdapter)
protected boolean canHighlight(Component component, ComponentAdapter adapter)
This implementation returns true always.
Overridden to return false if the Painter is null or the component is not of type PainterAware.
canHighlight
in class AbstractHighlighter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |