edu.uci.ics.jung.graph.decorators
Class StringLabeller

java.lang.Object
  extended byedu.uci.ics.jung.graph.decorators.StringLabeller
Direct Known Subclasses:
GlobalStringLabeller, ToStringLabeller

public class StringLabeller
extends java.lang.Object

A StringLabeller applies a set of labels to a Graph. The Labeller, specifically, attaches itself to a Graph's UserData, and maintains an index of Strings that are labels. Note that the strings must be unique so that getVertex( label ) will work.

Author:
danyelf

Nested Class Summary
static class StringLabeller.UniqueLabelException
          A minor class to store exceptions from duplicate labels in the Graph.
 
Field Summary
static java.lang.Object DEFAULT_STRING_LABELER_KEY
          The key that hasLabeller() and getLabeller() use.
 
Method Summary
 void assignDefaultLabels(java.util.Set vertices, int offset)
          Assigns textual labels to every vertex passed in.
 void clear()
          Wipes the entire table.
 Graph getGraph()
          Gets the graph associated with this StringLabeller
 java.lang.String getLabel(Vertex v)
          Gets the String label associated with a particular Vertex.
static StringLabeller getLabeller(Graph g)
          Gets a labeller associated with this graph.
static StringLabeller getLabeller(Graph g, java.lang.Object key)
          Returns a labeller attached to a particular key in the graph.
 Vertex getVertex(java.lang.String label)
          Gets the Vertex from the graph associated with this label.
static boolean hasStringLabeller(Graph g)
          Checks if a labeller is associated with this graph.
static boolean hasStringLabeller(Graph g, java.lang.Object key)
          Checks for a labeller attached to a particular key in the graph.
 Vertex removeLabel(java.lang.String string)
           
 void setLabel(Vertex v, java.lang.String l)
          Associates a Vertex with a Label, overrwriting any previous labels on this vertex.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STRING_LABELER_KEY

public static final java.lang.Object DEFAULT_STRING_LABELER_KEY
The key that hasLabeller() and getLabeller() use.

Method Detail

getLabeller

public static StringLabeller getLabeller(Graph g)
Gets a labeller associated with this graph. If no Labeller is associated, creates one and returns it. This method is the same as getLabeller with a key argument, but uses the DEFAULT_STRING_LABELER_KEY as its UserData key. param g The Graph to check.


hasStringLabeller

public static boolean hasStringLabeller(Graph g)
Checks if a labeller is associated with this graph.

Parameters:
g - The graph to check.

hasStringLabeller

public static boolean hasStringLabeller(Graph g,
                                        java.lang.Object key)
Checks for a labeller attached to a particular key in the graph. Useful for creating more than one Labeller for a particular Graph.

Parameters:
g - the Graph
key - the UserData key to which it is attached
Returns:
true if the graph has this labeller.

getLabeller

public static StringLabeller getLabeller(Graph g,
                                         java.lang.Object key)
Returns a labeller attached to a particular key in the graph. Useful for creating more than one Labeller for a particular Graph.

Parameters:
g - the Graph
key - the UserData key to which it is attached
Returns:
a StringLabeller

getGraph

public Graph getGraph()
Gets the graph associated with this StringLabeller

Returns:
a Graph that uses this StringLabeller.

getLabel

public java.lang.String getLabel(Vertex v)
Gets the String label associated with a particular Vertex.

Parameters:
v - a Vertex inside the Graph.
Throws:
FatalException - if the Vertex is not in the Graph associated with this Labeller.

getVertex

public Vertex getVertex(java.lang.String label)
Gets the Vertex from the graph associated with this label.

Parameters:
label -

setLabel

public void setLabel(Vertex v,
                     java.lang.String l)
              throws StringLabeller.UniqueLabelException
Associates a Vertex with a Label, overrwriting any previous labels on this vertex.

Parameters:
v - a Vertex in the labeller's graph
l - a Label to be associated with this vertex
Throws:
FatalException - thrown if this vertex isn't in the Labeller's graph
StringLabeller.UniqueLabelException - thrown if this label is already associated with some other vertex.

assignDefaultLabels

public void assignDefaultLabels(java.util.Set vertices,
                                int offset)
                         throws StringLabeller.UniqueLabelException
Assigns textual labels to every vertex passed in. Walks through the graph in iterator order, assigning labels "offset", "offset+1" "offset+2". The count starts at offset.

Parameters:
vertices - The set of Vertices to label. All must be part of this graph.
offset - The starting value to number vertices from
Throws:
StringLabeller.UniqueLabelException - Is thrown if some other vertexc is already numbered.
FatalException - if any Vertex is not part of the Graph.

removeLabel

public Vertex removeLabel(java.lang.String string)
Parameters:
string -

clear

public void clear()
Wipes the entire table. Resets everything.