prefuse.action.assignment
Class ShapeAction

java.lang.Object
  extended by prefuse.activity.Activity
      extended by prefuse.action.Action
          extended by prefuse.action.GroupAction
              extended by prefuse.action.ItemAction
                  extended by prefuse.action.EncoderAction
                      extended by prefuse.action.assignment.ShapeAction
Direct Known Subclasses:
DataShapeAction

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.

Author:
jeffrey heer

Field Summary
protected  int m_defaultShape
           
 
Fields inherited from class prefuse.action.ItemAction
m_predicate
 
Fields inherited from class prefuse.action.GroupAction
m_group
 
Fields inherited from class prefuse.action.Action
m_vis
 
Fields inherited from class prefuse.activity.Activity
DEFAULT_STEP_TIME, INFINITY
 
Constructor Summary
ShapeAction()
          Constructor.
ShapeAction(java.lang.String group)
          Constructor.
ShapeAction(java.lang.String group, int shape)
          Constructor with a specified a default shape value.
 
Method Summary
 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.
 
Methods inherited from class prefuse.action.EncoderAction
add, clear, finish, lookup, remove, run, setup, setVisualization
 
Methods inherited from class prefuse.action.ItemAction
getFilterPredicate, setFilterPredicate
 
Methods inherited from class prefuse.action.GroupAction
getGroup, setGroup
 
Methods inherited from class prefuse.action.Action
getVisualization, run
 
Methods inherited from class prefuse.activity.Activity
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_defaultShape

protected int m_defaultShape
Constructor Detail

ShapeAction

public ShapeAction()
Constructor. A default rectangle shape will be used.


ShapeAction

public ShapeAction(java.lang.String group)
Constructor. A default rectangle shape will be used.

Parameters:
group - the data group processed by this Action.

ShapeAction

public ShapeAction(java.lang.String group,
                   int shape)
Constructor with a specified a default shape value.

Parameters:
group - the data group processed by this Action.
shape - the default shape value to use
Method Detail

getDefaultSize

public int getDefaultSize()
Returns the default shape value assigned to items.

Returns:
the default shape value

setDefaultShape

public void setDefaultShape(int defaultShape)
Sets the default shape value assigned to items. Items will be assigned the default shape if they do not match any registered rules.

Parameters:
defaultShape - the new default shape value

add

public void add(Predicate p,
                int shape)
Add a shape mapping rule to this ShapeAction. VisualItems that match the provided predicate will be assigned the given shape value (assuming they do not match an earlier rule).

Parameters:
p - the rule Predicate
shape - the shape value

add

public void add(java.lang.String expr,
                int shape)
Add a shape mapping rule to this ShapeAction. VisualItems that match the provided expression will be assigned the given shape value (assuming they do not match an earlier rule). The provided expression String will be parsed to generate the needed rule Predicate.

Parameters:
expr - the expression String, should parse to a Predicate.
shape - the shape value
Throws:
java.lang.RuntimeException - if the expression does not parse correctly or does not result in a Predicate instance.

add

public void add(Predicate p,
                ShapeAction f)
Add a size mapping rule to this ShapeAction. VisualItems that match the provided predicate will be assigned the shape value returned by the given ShapeAction's getSize() method.

Parameters:
p - the rule Predicate
f - the delegate ShapeAction to use

add

public void add(java.lang.String expr,
                ShapeAction f)
Add a shape mapping rule to this ShapeAction. VisualItems that match the provided expression will be assigned the given shape value (assuming they do not match an earlier rule). The provided expression String will be parsed to generate the needed rule Predicate.

Parameters:
expr - the expression String, should parse to a Predicate.
f - the delegate ShapeAction to use
Throws:
java.lang.RuntimeException - if the expression does not parse correctly or does not result in a Predicate instance.

process

public void process(VisualItem item,
                    double frac)
Description copied from class: ItemAction
Processes an individual item.

Specified by:
process in class ItemAction
Parameters:
item - the VisualItem to process
frac - the fraction of elapsed duration time
See Also:
ItemAction.process(prefuse.visual.VisualItem, double)

getShape

public int getShape(VisualItem item)
Returns a shape value for the given item.

Parameters:
item - the item for which to get the shape value
Returns:
the shape value for the item


Copyright © 2007 Regents of the University of California