prefuse.action.assignment
Class ColorAction

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.ColorAction
Direct Known Subclasses:
DataColorAction

public class ColorAction
extends EncoderAction

Assignment Action that assigns color values to VisualItems for a given color field (e.g., the stroke, text, or fill color).

By default, a ColorAction simply assigns a single default color value to all items (the initial default color is black). Clients can change this default value to achieve uniform color assignment, or can add any number of additional rules for color assignment. Rules are specified by a Predicate instance which, if returning true, will trigger that rule, causing either the provided color value or the result of a delegate ColorAction to be applied. Rules are evaluated in the order in which they are added to the ColorAction, so earlier rules will have precedence over rules added later.

In addition, subclasses can simply override getColor(VisualItem) to achieve custom color assignment. In some cases, this may be the simplest or most flexible approach.

To automatically assign color values based on varying values of a particular data field, consider using the DataColorAction.

Color values are represented using integers, into which 8-bit values for the red, green, blue, and alpha channels are stored. For more information and utilities for creating and manipulating color values, see the ColorLib class.

Author:
jeffrey heer
See Also:
ColorLib, DataColorAction

Field Summary
protected  int m_cidx
           
protected  java.lang.String m_colorField
           
protected  int m_defaultColor
           
protected  int m_eidx
           
protected  java.lang.String m_endField
           
protected  int m_sidx
           
protected  java.lang.String m_startField
           
 
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
ColorAction(java.lang.String group, Predicate filter, java.lang.String field)
          Constructor, sets the data group, filter predicate and color field for color assignment.
ColorAction(java.lang.String group, Predicate filter, java.lang.String field, int color)
          Constructor, sets the data group, filter predicate, color field, and default color value for color assignment.
ColorAction(java.lang.String group, java.lang.String field)
          Constructor, sets the data group and color field for color assignment.
ColorAction(java.lang.String group, java.lang.String field, int color)
          Constructor, sets the data group, color field, and default color value for color assignment.
 
Method Summary
 void add(Predicate p, ColorAction f)
          Add a color mapping rule to this ColorAction.
 void add(Predicate p, int color)
          Add a color mapping rule to this ColorAction.
 void add(java.lang.String expr, ColorAction f)
          Add a color mapping rule to this ColorAction.
 void add(java.lang.String expr, int color)
          Add a color mapping rule to this ColorAction.
 int getColor(VisualItem item)
          Returns a color value for the given item.
 int getDefaultColor()
          Returns the default color for this ColorAction
 void process(VisualItem item, double frac)
          Processes an individual item.
 void setDefaultColor(int color)
          Sets the default color for this ColorAction.
 void setField(java.lang.String field)
          Set the color field name that this ColorAction should set.
 
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_colorField

protected java.lang.String m_colorField

m_startField

protected java.lang.String m_startField

m_endField

protected java.lang.String m_endField

m_cidx

protected int m_cidx

m_sidx

protected int m_sidx

m_eidx

protected int m_eidx

m_defaultColor

protected int m_defaultColor
Constructor Detail

ColorAction

public ColorAction(java.lang.String group,
                   java.lang.String field)
Constructor, sets the data group and color field for color assignment. Uses an initial default color value of black [RGB value (0,0,0)].

Parameters:
group - the data group processed by this Action
field - the color field assigned by this Action

ColorAction

public ColorAction(java.lang.String group,
                   java.lang.String field,
                   int color)
Constructor, sets the data group, color field, and default color value for color assignment.

Parameters:
group - the data group processed by this Action
field - the color field assigned by this Action
color - the default color value assigned by this ColorAction

ColorAction

public ColorAction(java.lang.String group,
                   Predicate filter,
                   java.lang.String field)
Constructor, sets the data group, filter predicate and color field for color assignment. Uses an initial default color value of black [RGB value (0,0,0)].

Parameters:
group - the data group processed by this Action
filter - the filter predicate Predicate
field - the color field assigned by this Action

ColorAction

public ColorAction(java.lang.String group,
                   Predicate filter,
                   java.lang.String field,
                   int color)
Constructor, sets the data group, filter predicate, color field, and default color value for color assignment.

Parameters:
group - the data group processed by this Action
filter - the filter predicate Predicate
field - the color field assigned by this Action
color - the default color value assigned by this ColorAction
Method Detail

setField

public void setField(java.lang.String field)
Set the color field name that this ColorAction should set. The ColorAction will automatically try to update the start and end values for this field if it is an interpolated field.

Parameters:
field -

getDefaultColor

public int getDefaultColor()
Returns the default color for this ColorAction

Returns:
the default color value

setDefaultColor

public void setDefaultColor(int color)
Sets the default color for this ColorAction. Items will be assigned the default color if they do not match any registered rules.

Parameters:
color - the new default color

add

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

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

add

public void add(java.lang.String expr,
                int color)
Add a color mapping rule to this ColorAction. VisualItems that match the provided expression will be assigned the given color 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.
color - the color 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,
                ColorAction f)
Add a color mapping rule to this ColorAction. VisualItems that match the provided predicate will be assigned the color value returned by the given ColorAction's getColor() method.

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

add

public void add(java.lang.String expr,
                ColorAction f)
Add a color mapping rule to this ColorAction. VisualItems that match the provided expression will be assigned the given color 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 ColorAction 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)

getColor

public int getColor(VisualItem item)
Returns a color value for the given item. Colors are represented as integers, interpreted as holding values for the red, green, blue, and alpha channels. This is the same color representation returned by the Color.getRGB() method.

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


Copyright © 2007 Regents of the University of California