public class ShapeAction extends EncoderAction
Assignment Action that assigns shape values to VisualItems.
Shape values are simple integer codes that indicate to
appropriate renderer instances what shape should be drawn. The default
list of shape values is included in the Constants
class,
all beginning with the prefix SHAPE
. Of course, clients can
always create their own shape codes that are handled by a custom Renderer.
By default, a ShapeAction simply sets each VisualItem to be a rectangle. Clients can change this default value to achieve uniform shape assignment, or can add any number of additional rules for shape assignment. Rules are specified by a Predicate instance which, if returning true, will trigger that rule, causing either the provided shape value or the result of a delegate ShapeAction to be applied. Rules are evaluated in the order in which they are added to the ShapeAction, so earlier rules will have precedence over rules added later.
In addition, subclasses can simply override getShape(VisualItem)
to achieve custom shape assignment. In some cases, this may be the simplest
or most flexible approach.
This Action only sets the shape field of the VisualItem. For this value
to have an effect, a renderer instance that takes this shape value
into account must be used (e.g., ShapeRenderer
).
To automatically assign shape values based on varying values of a
particular data field, consider using the DataShapeAction
.
Modifier and Type | Field and Description |
---|---|
protected int |
m_defaultShape |
m_predicate
m_group
DEFAULT_STEP_TIME, INFINITY
Constructor and Description |
---|
ShapeAction()
Constructor.
|
ShapeAction(java.lang.String group)
Constructor.
|
ShapeAction(java.lang.String group,
int shape)
Constructor with a specified a default shape value.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Predicate p,
int shape)
Add a shape mapping rule to this ShapeAction.
|
void |
add(Predicate p,
ShapeAction f)
Add a size mapping rule to this ShapeAction.
|
void |
add(java.lang.String expr,
int shape)
Add a shape mapping rule to this ShapeAction.
|
void |
add(java.lang.String expr,
ShapeAction f)
Add a shape mapping rule to this ShapeAction.
|
int |
getDefaultSize()
Returns the default shape value assigned to items.
|
int |
getShape(VisualItem item)
Returns a shape value for the given item.
|
void |
process(VisualItem item,
double frac)
Processes an individual item.
|
void |
setDefaultShape(int defaultShape)
Sets the default shape value assigned to items.
|
add, clear, finish, lookup, remove, run, setup, setVisualization
getFilterPredicate, setFilterPredicate
getGroup, setGroup
getVisualization, run
addActivityListener, alwaysRunAfter, cancel, fireActivityCancelled, fireActivityFinished, fireActivityScheduled, fireActivityStarted, fireActivityStepped, getDuration, getNextTime, getPace, getPacingFunction, getStartTime, getStepTime, getStopTime, isEnabled, isRunning, isScheduled, removeActivityListener, run, runAfter, runAt, setDuration, setEnabled, setPacingFunction, setStartTime, setStepTime
public ShapeAction()
public ShapeAction(java.lang.String group)
group
- the data group processed by this Action.public ShapeAction(java.lang.String group, int shape)
group
- the data group processed by this Action.shape
- the default shape value to usepublic int getDefaultSize()
public void setDefaultShape(int defaultShape)
defaultShape
- the new default shape valuepublic void add(Predicate p, int shape)
p
- the rule Predicateshape
- the shape valuepublic void add(java.lang.String expr, int shape)
expr
- the expression String, should parse to a Predicate.shape
- the shape valuejava.lang.RuntimeException
- if the expression does not parse correctly or
does not result in a Predicate instance.public void add(Predicate p, ShapeAction f)
p
- the rule Predicatef
- the delegate ShapeAction to usepublic void add(java.lang.String expr, ShapeAction f)
expr
- the expression String, should parse to a Predicate.f
- the delegate ShapeAction to usejava.lang.RuntimeException
- if the expression does not parse correctly or
does not result in a Predicate instance.public void process(VisualItem item, double frac)
ItemAction
process
in class ItemAction
item
- the VisualItem to processfrac
- the fraction of elapsed duration timeItemAction.process(prefuse.visual.VisualItem, double)
public int getShape(VisualItem item)
item
- the item for which to get the shape valueCopyright ? 2013 Regents of the University of California