prefuse.action.assignment
Class FontAction

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.FontAction

public class FontAction
extends EncoderAction

Assignment Action that assigns font values to VisualItems. By default, a FontAction simply sets each VisualItem to use a default 10 point sans-serif font (10 point sans-serif). Clients can change this default value to achieve uniform font assignment, or can add any number of additional rules for font assignment. Rules are specified by a Predicate instance which, if returning true, will trigger that rule, causing either the provided font value or the result of a delegate FontAction to be applied. Rules are evaluated in the order in which they are added to the FontAction, so earlier rules will have precedence over rules added later.

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

Author:
jeffrey heer

Field Summary
protected  java.awt.Font defaultFont
           
 
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
FontAction()
          Create a new FontAction that processes all data groups.
FontAction(java.lang.String group)
          Create a new FontAction that processes the specified group.
FontAction(java.lang.String group, java.awt.Font defaultFont)
          Create a new FontAction that processes the specified group.
 
Method Summary
 void add(Predicate p, java.awt.Font font)
          Add a font mapping rule to this FontAction.
 void add(Predicate p, FontAction f)
          Add a font mapping rule to this FontAction.
 void add(java.lang.String expr, java.awt.Font font)
          Add a font mapping rule to this FontAction.
 void add(java.lang.String expr, FontAction f)
          Add a font mapping rule to this FontAction.
 java.awt.Font getDefaultFont()
          Get the default font assigned to items.
 java.awt.Font getFont(VisualItem item)
          Returns the Font to use for a given VisualItem.
 void process(VisualItem item, double frac)
          Processes an individual item.
 void setDefaultFont(java.awt.Font f)
          Set the default font to be 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

defaultFont

protected java.awt.Font defaultFont
Constructor Detail

FontAction

public FontAction()
Create a new FontAction that processes all data groups.


FontAction

public FontAction(java.lang.String group)
Create a new FontAction that processes the specified group.

Parameters:
group - the data group to process

FontAction

public FontAction(java.lang.String group,
                  java.awt.Font defaultFont)
Create a new FontAction that processes the specified group.

Parameters:
group - the data group to process
defaultFont - the default Font to assign
Method Detail

setDefaultFont

public void setDefaultFont(java.awt.Font f)
Set the default font to be assigned to items. Items will be assigned the default font if they do not match any registered rules.

Parameters:
f - the default font to use

getDefaultFont

public java.awt.Font getDefaultFont()
Get the default font assigned to items.

Returns:
the default font

add

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

Parameters:
p - the rule Predicate
font - the font

add

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

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

add

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

getFont

public java.awt.Font getFont(VisualItem item)
Returns the Font to use for a given VisualItem. Subclasses should override this method to perform customized font assignment.

Parameters:
item - the VisualItem for which to get the Font
Returns:
the Font for the given item


Copyright © 2007 Regents of the University of California