ptolemy.vergil.kernel
Class AnimationRenderer

java.lang.Object
  extended by ptolemy.vergil.kernel.AnimationRenderer
All Implemented Interfaces:
SelectionRenderer
Direct Known Subclasses:
DebugRenderer

public class AnimationRenderer
extends java.lang.Object
implements SelectionRenderer

An implementation of a selection renderer that is used for animation. It highlights specified figures by wrapping them in an instance of a FigureDecorator. The figure decorator is obtained by cloning a prototype decorator, accessible through the get/setFigureDecorator() methods. The default prototype is an instance of BasicHighlighter that highlights in red.

This class is fashioned after BasicSelectionRenderer, but differs in that it ensures that selection and deselection occurs in the event thread. Also, it highlights objects in red rather than yellow.

Since:
Ptolemy II 2.0
Version:
$Id: AnimationRenderer.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Field Summary
private  java.util.Hashtable _decorators
          Mapping from figures to decorators
protected  FigureDecorator _prototypeDecorator
          The prototype decorator.
 
Constructor Summary
AnimationRenderer()
          Create a new selection renderer with the default prototype decorator.
AnimationRenderer(java.awt.Color color)
          Create a new selection renderer with the default prototype decorator using the specified color.
AnimationRenderer(java.awt.Color color, java.awt.Stroke stroke)
          Create a new selection renderer with the default prototype decorator using the specified color and stroke.
AnimationRenderer(FigureDecorator decorator)
          Create a new renderer with the given prototype decorator.
 
Method Summary
 FigureDecorator getDecorator()
          Get the prototype decorator.
 boolean isRenderedSelected(Figure figure)
          Test whether the given figure is currently rendered highlighted.
 void renderDeselected(Figure figure)
          Set the rendering of the figure to not be highlighted.
 void renderSelected(Figure figure)
          Set the rendering of the figure as highlighted.
 void setDecorator(FigureDecorator decorator)
          Set the prototype decorator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_prototypeDecorator

protected FigureDecorator _prototypeDecorator
The prototype decorator.


_decorators

private java.util.Hashtable _decorators
Mapping from figures to decorators

Constructor Detail

AnimationRenderer

public AnimationRenderer()
Create a new selection renderer with the default prototype decorator.


AnimationRenderer

public AnimationRenderer(java.awt.Color color)
Create a new selection renderer with the default prototype decorator using the specified color.

Parameters:
color - The color for the highlight.

AnimationRenderer

public AnimationRenderer(java.awt.Color color,
                         java.awt.Stroke stroke)
Create a new selection renderer with the default prototype decorator using the specified color and stroke. This draws an outline rather than a filled shape.

Parameters:
color - The color for the highlight.
stroke - The stroke for the highlight.

AnimationRenderer

public AnimationRenderer(FigureDecorator decorator)
Create a new renderer with the given prototype decorator.

Parameters:
decorator - The prototype decorator.
Method Detail

getDecorator

public FigureDecorator getDecorator()
Get the prototype decorator.

Returns:
The prototype decorator.
See Also:
setDecorator(FigureDecorator)

isRenderedSelected

public boolean isRenderedSelected(Figure figure)
Test whether the given figure is currently rendered highlighted.

Specified by:
isRenderedSelected in interface SelectionRenderer
Parameters:
figure - The figure that may be highlighted.
Returns:
True if the figure is highlighted.

renderDeselected

public void renderDeselected(Figure figure)
Set the rendering of the figure to not be highlighted. The figure has the decorator unwrapped off it and is inserted back into its parent figure container, if there is one. If the figure is not rendered highlighted, do nothing. The rendering is performed later in the event thread, and the calling thread is suspended by calling Thread.yield(), to give the event thread a chance to catch up.

Specified by:
renderDeselected in interface SelectionRenderer
Parameters:
figure - The figure to deselect.

renderSelected

public void renderSelected(Figure figure)
Set the rendering of the figure as highlighted. If the figure is already rendered highlighted, just repaint. Otherwise create a new BasicHighlighter, and wrap the figure in the decorator, inserting the decorator into the figure's parent. The rendering is performed later in the event thread, and the calling thread is suspended by calling Thread.yield(), to give the event thread a chance to catch up.

Specified by:
renderSelected in interface SelectionRenderer
Parameters:
figure - The figure to highlight.

setDecorator

public void setDecorator(FigureDecorator decorator)
Set the prototype decorator.

Parameters:
decorator - The prototype decorator.
See Also:
getDecorator()