Class PainterHighlighter
- java.lang.Object
-
- org.jdesktop.swingx.decorator.AbstractHighlighter
-
- org.jdesktop.swingx.decorator.PainterHighlighter
-
- All Implemented Interfaces:
- Highlighter
public class PainterHighlighter extends AbstractHighlighter
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.
NOTE: this will change once the Painter api is stable.@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); }
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description PaintergetPainter()Returns to Painter used in this Highlighter.java.awt.Componenthighlight(java.awt.Component component, ComponentAdapter adapter)Decorates the specified component for the given component adapter.voidsetPainter(Painter painter)Sets the Painter to use in this Highlighter, may be null.-
Methods inherited from class org.jdesktop.swingx.decorator.AbstractHighlighter
addChangeListener, getChangeListeners, getHighlightPredicate, removeChangeListener, setHighlightPredicate
-
-
-
-
Constructor Detail
-
PainterHighlighter
public PainterHighlighter()
Instantiates a PainterHighlighter with null painter and default predicate.
-
PainterHighlighter
public PainterHighlighter(HighlightPredicate predicate)
Instantiates a PainterHighlighter with null painter which uses the given predicate.- Parameters:
predicate- the HighlightPredicate which controls the highlight application.
-
PainterHighlighter
public PainterHighlighter(Painter painter)
Instantiates a PainterHighlighter with the given Painter and default predicate.- Parameters:
painter- the painter to use
-
PainterHighlighter
public PainterHighlighter(HighlightPredicate predicate, Painter painter)
Instantiates a PainterHighlighter with the given painter and predicate.- Parameters:
predicate-painter-
-
-
Method Detail
-
getPainter
public Painter getPainter()
Returns to Painter used in this Highlighter.- Returns:
- the Painter used in this Highlighter, may be null.
-
setPainter
public void setPainter(Painter painter)
Sets the Painter to use in this Highlighter, may be null. Un/installs the listener to changes painter's properties.- Parameters:
painter- the Painter to uses for decoration.
-
highlight
public java.awt.Component highlight(java.awt.Component component, ComponentAdapter adapter)Decorates the specified component for the given component adapter. This calls doHighlight to apply the decoration if both HighlightPredicate isHighlighted and canHighlight return true. Returns the undecorated component otherwise.Overridden to set/reset the flag indicating whether or not painter's property changes should be passed on to the Highlighter's listener.
- Specified by:
highlightin interfaceHighlighter- Overrides:
highlightin classAbstractHighlighter- Parameters:
component- the cell renderer component that is to be decoratedadapter- the ComponentAdapter for this decorate operation- Returns:
- the decorated cell rendering component
- See Also:
AbstractHighlighter.canHighlight(Component, ComponentAdapter),AbstractHighlighter.doHighlight(Component, ComponentAdapter),AbstractHighlighter.getHighlightPredicate()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG