prefuse.render
Class DefaultRendererFactory

java.lang.Object
  extended by prefuse.render.DefaultRendererFactory
All Implemented Interfaces:
RendererFactory

public class DefaultRendererFactory
extends java.lang.Object
implements RendererFactory

Default factory implementation from which to retrieve VisualItem renderers.

This class supports the use of a default renderer for EdgeItems (the default edge renderer) and another for all other non-edge VisualItems (the default item renderer). In addition, any number of additional Renderer mapping rules can be added, by specifying a Predicate to apply and a Renderer to return for matching items. Predicate/Renderer mappings are checked in the order in which they were added to the factory.

If left unspecified, a ShapeRenderer is used as the default item renderer and an EdgeRenderer instance is used as the default edge renderer.

For example, the following code snippet creates a new DefaultRendererFactory, changes the default edge renderer to be an EdgeRenderer using curved edges, and adds a new rule which maps items in the group "data" to a text renderer that pulls its text from a field named "label".

   DefaultRendererFactory rf = new DefaultRendererFactory();
   rf.setDefaultEdgeRenderer(new EdgeRenderer(Constants.EDGE_TYPE_CURVE);
   rf.add("INGROUP('data')", new LabelRenderer("label");
 

Author:
jeffrey heer

Constructor Summary
DefaultRendererFactory()
          Default Constructor.
DefaultRendererFactory(Renderer itemRenderer)
          Constructor.
DefaultRendererFactory(Renderer itemRenderer, Renderer edgeRenderer)
          Constructor.
 
Method Summary
 void add(Predicate p, Renderer r)
          Adds a new mapping to this RendererFactory.
 void add(java.lang.String predicate, Renderer r)
          Adds a new mapping to this RendererFactory.
 Renderer getDefaultEdgeRenderer()
          Gets the default edge renderer.
 Renderer getDefaultRenderer()
          Gets the default renderer.
 Renderer getRenderer(VisualItem item)
          Return a Renderer instance for the input VisualItem.
 void setDefaultEdgeRenderer(Renderer r)
          Sets the default edge renderer.
 void setDefaultRenderer(Renderer r)
          Sets the default renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultRendererFactory

public DefaultRendererFactory()
Default Constructor. A ShapeRenderer instance will be used for the default item renderer and an EdgeRenderer instance will be used for the default edge renderer.

See Also:
ShapeRenderer, EdgeRenderer

DefaultRendererFactory

public DefaultRendererFactory(Renderer itemRenderer)
Constructor. Creates a new DefaultRendererFactory with the specified default item renderer. An EdgeRenderer instance will be used for the default edge renderer.

Parameters:
itemRenderer - the default item renderer. This is the default for rendering all items except EdgeItem instances.
See Also:
EdgeRenderer

DefaultRendererFactory

public DefaultRendererFactory(Renderer itemRenderer,
                              Renderer edgeRenderer)
Constructor. Creates a new DefaultRendererFactory with the specified default item and edge renderers.

Parameters:
itemRenderer - the default item renderer. This is the default for rendering all items except EdgeItem instances.
edgeRenderer - the default edge renderer. This is the default for rendering EdgeItem instances.
Method Detail

setDefaultRenderer

public void setDefaultRenderer(Renderer r)
Sets the default renderer. This renderer will be returned by getRenderer(VisualItem) whenever there are no matching predicates and the input item is not an EdgeItem. To set the default renderer for EdgeItems, see setDefaultEdgeRenderer(Renderer).

Parameters:
r - the Renderer to use as the default
See Also:
setDefaultEdgeRenderer(Renderer)

getDefaultRenderer

public Renderer getDefaultRenderer()
Gets the default renderer. This renderer will be returned by getRenderer(VisualItem) whenever there are no matching predicates and the input item is not an EdgeItem.

Returns:
the default Renderer for non-edge VisualItems

setDefaultEdgeRenderer

public void setDefaultEdgeRenderer(Renderer r)
Sets the default edge renderer. This renderer will be returned by getRenderer(VisualItem) whenever there are no matching predicates and the input item is an EdgeItem. To set the default renderer for non-EdgeItems, see setDefaultRenderer(Renderer).

Parameters:
r - the Renderer to use as the default for EdgeItems
See Also:
setDefaultRenderer(Renderer)

getDefaultEdgeRenderer

public Renderer getDefaultEdgeRenderer()
Gets the default edge renderer. This renderer will be returned by getRenderer(VisualItem) whenever there are no matching predicates and the input item is an EdgeItem.

Returns:
the default Renderer for EdgeItems

add

public void add(Predicate p,
                Renderer r)
Adds a new mapping to this RendererFactory. If an input item to getRenderer(VisualItem) matches the predicate, then the corresponding Renderer will be returned. Predicates are evaluated in the order in which they are added, so if an item matches multiple predicates, the Renderer for the earliest match will be returned.

Parameters:
p - a Predicate for testing a VisualItem
r - the Renderer to return if an item matches the Predicate

add

public void add(java.lang.String predicate,
                Renderer r)
Adds a new mapping to this RendererFactory. If an input item to getRenderer(VisualItem) matches the predicate, then the corresponding Renderer will be returned. Predicates are evaluated in the order in which they are added, so if an item matches multiple predicates, the Renderer for the earliest match will be returned.

Parameters:
predicate - a String in the prefuse expression language. This String will be parsed to create a corresponding Predicate instance.
r - the Renderer to return if an item matches the Predicate

getRenderer

public Renderer getRenderer(VisualItem item)
Return a Renderer instance for the input VisualItem. The VisualItem is matched against the registered Predicates, and if a match is found the corresponding Renderer is returned. Predicate matches are evaluated in the order in which Predicate/Renderer mappings were added to this RendererFactory. If no matches are found, either the default renderer (for all VisualItems except EdgeItems) or the default edge renderer (for EdgeItems) is returned.

Specified by:
getRenderer in interface RendererFactory
Parameters:
item - the item for which to retrieve the renderer
Returns:
the Renderer for the given VisualItem


Copyright © 2007 Regents of the University of California