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.
@author Jeanette Winzenburg
|
|
|
|
|
|