Graphics2D Actor API

g2d.graph
Class IOPGraph

java.lang.Object
  extended by g2d.glyph.Identifiable
      extended by g2d.glyph.Attributable
          extended by g2d.glyph.Glyphish
              extended by g2d.glyph.GlyphList
                  extended by g2d.graph.IOPGraph
All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, EventListener

public class IOPGraph
extends GlyphList

Represents a directed graph as a list of glyphish things. The graph consists of nodes and edges, and is laid out by querying dot. For large graphs it is possible to optimize the expensive methods of painting and hit detecting by using a superimposed subgrid Manifold. One can also request a thumbnail Image of the graph.

Since:
August 2004, Optimized in July 2005.
Author:
Ben Funnell, Ian A. Mason., Linda (rewriting and some documentation)

Field Summary
 
Fields inherited from class g2d.glyph.Glyphish
DEBUG
 
Fields inherited from class g2d.glyph.Identifiable
uid
 
Constructor Summary
IOPGraph()
          Constructs an IOPGraph object.
IOPGraph(String r)
          Constructs an IOPGraph object with given layout.
 
Method Summary
 void add2Manifold(Glyphish glyph)
          Adds a glyph to the appropriate charts in the manifold.
 void addChangeListener(ChangeListener cl)
          Adds a listener to those registered for change events.
 void addEdge(IOPEdge e)
          Adds an edge to the graph.
 void addNode(IOPNode n)
          Adds a node to the graph.
 void clear()
          Resets the graph to be empty.
 void cloneFromGraph(IOPGraph clone)
          Clone nodes and edges in this graph from given graph.
 void createManifold()
          This procedure creates, but doesn't initialize, the covering manifold.
 boolean doLayout()
          Lays out an already existing graph.
 void fireChange()
          Is used to notify all those listeners registered that the graph has changed.
static boolean getAntiAliased()
          Fetches the current antialiasing setting.
 BufferedImage getBufferedImage(double scale)
          Obtain a scaled, buffered image of this graph.
 IOPEdge getEdge(IOPNode source, IOPNode sink)
          Obtain edge between given source and sink nodes.
 IOPEdge getEdge(Point2D p)
          Obtain (one) edge that contains given point or null if none of the edges intersects with point.
 IOPEdge getEdge(Point2D p, double distance)
          Obtain edge that intersects with square around given point of side length distance/2, or null if no such edge is found.
 IOPEdge[] getEdgesInArray()
          Returns the edges in an array of IOPEdges.
 Glyphish getGlyphThing(Point2D p)
          Overrides the method in the Glyphish hierarchy.
 GraphItem getGraphItem(Point2D p, double distance)
          Find a graph item (node or edge) that contains given point.
 double getHeight()
          Returns the height of the graph.
 IOPNode getNode(Point2D p)
          Attempt to find a node located at a particular point.
 IOPNode getNode(String id)
          Obtain node with given ID in this graph.
 IOPNode[] getNodesInArray()
          Returns the nodes in an array of IOPNodes.
 Image getThumbNail(int how, int thumbWidth, int thumbHeight, Component comp, int hints)
          Constructs an thumbnail image of the graph.
 double getWidth()
          Returns the width of the graph.
 HashMap makeAdjacencyList()
          Creates a new adjacency list.
 String makeDotInput()
          Produces a string that describes this graph, in dot format.
 void paint(Graphics2D g2d, Rectangle2D r)
          Overrides the method in the Glyphish hierarchy.
 void printAdjacencyList()
          Prints, to the error stream, the adjacency list.
 void removeChangeListener(ChangeListener cl)
          Removes a listener to those registered for change events.
 void rmEdge(IOPEdge e)
          Removes an edge from the graph.
 void rmNode(IOPNode n)
          Removes a node the graph.
static void setAntiAliased(boolean value)
          Sets whether or not antialiasing is used in drawing the graph.
 boolean setGraph(File file)
          Creates a graph from a stored file, in dot format.
 void setHeight(double h)
          Sets the height of the graph.
 void setStrokeWidth(float width)
          Sets the stroke width of all edges.
 void setWidth(double w)
          Sets the width of the graph.
 int size()
          The size of the glyph, i.e. the sum of the number of nodes and edges.
 void writeGraph(File file)
          Writes the graph out to a file, in dot format.
 
Methods inherited from class g2d.glyph.GlyphList
add, add, contains, getBounds, getListIterator, inside, intersects, length, paint, remove, transform
 
Methods inherited from class g2d.glyph.Glyphish
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, rotate, rotate, scale, setKeyAction, setMouseAction, shear, translate
 
Methods inherited from class g2d.glyph.Attributable
getAttribute, getAttributeAsBoolean, getAttributeAsByte, getAttributeAsChar, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsInt, getAttributeAsShort, getAttributeAsString, getKeys, getStaticAttribute, getStaticKeys, isAttribute, isStaticAttribute, setAttribute, setStaticAttribute
 
Methods inherited from class g2d.glyph.Identifiable
getObject, getUID, setUID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOPGraph

public IOPGraph()
Constructs an IOPGraph object. The default layout is "TB" for top to bottom.


IOPGraph

public IOPGraph(String r)
Constructs an IOPGraph object with given layout.

Parameters:
r - String indicating how to layout the graph, it should either be "LR" for left to right, or "TB" for top to bottom.
Method Detail

cloneFromGraph

public void cloneFromGraph(IOPGraph clone)
Clone nodes and edges in this graph from given graph. Will erase all glyphish things currently present in this graph before adding deep copies of nodes and edges from clone.

Parameters:
clone - IOPGraph to be cloned in this graph

getBufferedImage

public BufferedImage getBufferedImage(double scale)
Obtain a scaled, buffered image of this graph.

Parameters:
scale - Factor by which image should be scaled
Returns:
scaled BufferedImage of this graph or null if size is 0

getThumbNail

public Image getThumbNail(int how,
                          int thumbWidth,
                          int thumbHeight,
                          Component comp,
                          int hints)
Constructs an thumbnail image of the graph. If the graph image is a portrait (meaning height > width) then this will scale the thumbnail to the given height and adjust the width keeping the aspect ratio. If the graph image is a landscape (width > height) then this will scale the thumbnail to the given width and adjust the height keeping the aspect ratio.

If the graph is empty returns NULL.

Parameters:
how - specifies the way the thumbnail is made. -1 requests that its is made by Java using an offscreen image. Alternatively it can be made via dot using various formats:
    g2d.graph.Dot.GIF
    g2d.graph.Dot.PNG
    g2d.graph.Dot.JPG
thumbWidth - is the maximum width in pixels of the resulting thumbnail.
thumbHeight - is the maximum height in pixels of the resulting thumbnail.
comp - is a component used to obtain the necessary media tracker.
hints - is the scaling hint used to produce the thumbnail, see Image. Reasonable choices are: java.awt.Image.SCALE_SMOOTH and java.awt.Image.SCALE_FAST.
Returns:
the newly created thumbnail image or NULL if graph is empty.

createManifold

public void createManifold()
This procedure creates, but doesn't initialize, the covering manifold. The manifold is then initialized as part of the dot layout process. All this happens automatically, depending on the settings in the Manifold class.


add2Manifold

public void add2Manifold(Glyphish glyph)
Adds a glyph to the appropriate charts in the manifold. This is not meant to be called directly, but is called as part of the dot layout process.

Parameters:
glyph - the glyph to be added to all those charts that it's bounding rectangle has non-trivial intersection with.

paint

public void paint(Graphics2D g2d,
                  Rectangle2D r)
Overrides the method in the Glyphish hierarchy. Is optimized to use the manifold, if it is present.

Overrides:
paint in class Glyphish
Parameters:
g2d - the graphics object to be used to do the painting.
r - the rectangle that requires painting.

getGlyphThing

public Glyphish getGlyphThing(Point2D p)
Overrides the method in the Glyphish hierarchy. Is optimized to use the manifold, if it is present.

Overrides:
getGlyphThing in class GlyphList
Parameters:
p - the point where a glyph is sort.
Returns:
the top-most glyph residing at this point, or null if no such glyph exists.

size

public int size()
The size of the glyph, i.e. the sum of the number of nodes and edges. This is just the a crude measure of the graph's complexity. If the size of the graph, at layout time, is greater than THRESHOLD in the Manifold then a manifold is constructed for this graph.

Returns:
the cardinality of the nodes and edges in this graph.

setAntiAliased

public static void setAntiAliased(boolean value)
Sets whether or not antialiasing is used in drawing the graph.

Parameters:
value - the desired setting
See Also:
getAntiAliased()

getAntiAliased

public static boolean getAntiAliased()
Fetches the current antialiasing setting.

Returns:
the current boolean value
See Also:
setAntiAliased(boolean)

setStrokeWidth

public void setStrokeWidth(float width)
Sets the stroke width of all edges. Change will only take effect upon redrawing of this graph.

Parameters:
width - the desired stroke width, a float.

addNode

public void addNode(IOPNode n)
Adds a node to the graph. Does nothing if given node is null. Notifies all the registered change listeners otherwise.

Parameters:
n - IOPNode to be added

rmNode

public void rmNode(IOPNode n)
Removes a node the graph. Does nothing if given node is null. Notifies all the registered change listeners otherwise.

Parameters:
n - IOPNode to be removed

addEdge

public void addEdge(IOPEdge e)
Adds an edge to the graph. Does nothing if given edge is null. Notifies all the registered change listeners otherwise.

Parameters:
e - IOPEdge to be added

rmEdge

public void rmEdge(IOPEdge e)
Removes an edge from the graph. Does nothing if given edge is null. Notifies all the registered change listeners otherwise.

Parameters:
e - IOPEdge to be removed

makeAdjacencyList

public HashMap makeAdjacencyList()
Creates a new adjacency list.

Returns:
a hash mapping nodes to vectors of nodes that lie at the end of and edge starting from that node.

printAdjacencyList

public void printAdjacencyList()
Prints, to the error stream, the adjacency list.


clear

public void clear()
Resets the graph to be empty.

Overrides:
clear in class GlyphList

setGraph

public boolean setGraph(File file)
Creates a graph from a stored file, in dot format.

Parameters:
file - from which the graph is to be loaded
Returns:
a boolean indicating success or failure

makeDotInput

public String makeDotInput()
Produces a string that describes this graph, in dot format. This string is used to layout the graph, via dot.

Returns:
the dot string describing this graph.

doLayout

public boolean doLayout()
Lays out an already existing graph.

Returns:
a boolean indicating success or failure.

writeGraph

public void writeGraph(File file)
Writes the graph out to a file, in dot format.

Parameters:
file - to be written.

getEdge

public IOPEdge getEdge(Point2D p)
Obtain (one) edge that contains given point or null if none of the edges intersects with point.

Parameters:
p - Point that indicates edge to be retrieved
Returns:
Edge that intersects with given point (or null if no edge is found intersecting)

getEdge

public IOPEdge getEdge(Point2D p,
                       double distance)
Obtain edge that intersects with square around given point of side length distance/2, or null if no such edge is found. This method first computes all eligible candidates by intersecting all edges with a square of side length distance/2 and then determines the (approximately) closest one among these.

Parameters:
p - Point to define center of square where to look for edge
distance - side length of square to find edge
Returns:
Edge that intersects with square of size distance around given point and is (approximately) closest to point (or null if no edge is found intersecting)

getNode

public IOPNode getNode(Point2D p)
Attempt to find a node located at a particular point.

Parameters:
p - the desired location
Returns:
the desired node, or null if there is none

getGraphItem

public GraphItem getGraphItem(Point2D p,
                              double distance)
Find a graph item (node or edge) that contains given point. Will test first if point is inside a node. If not, will then test whether point is inside or close to an edge. Here, the given distance is the maximum distance away from an edge. If none are found will return NULL.

Parameters:
p - Point to use for finding graph item (cannot be NULL)
distance - Maximum distance that clicked point may be away from edge
Returns:
IOPNode or IOPEdge if one is found to contain/be near given point, or NULL otherwise

getNodesInArray

public IOPNode[] getNodesInArray()
Returns the nodes in an array of IOPNodes.

Returns:
array of nodes

getNode

public IOPNode getNode(String id)
Obtain node with given ID in this graph.

Parameters:
id - String with ID of desired node
Returns:
IOPNode if graph contains one with given ID or null otherwise

getEdgesInArray

public IOPEdge[] getEdgesInArray()
Returns the edges in an array of IOPEdges.

Returns:
array of edges

getEdge

public IOPEdge getEdge(IOPNode source,
                       IOPNode sink)
Obtain edge between given source and sink nodes.

Parameters:
source - IOPNode that is source of desired edge (cannot be null!)
sink - IOPNode that is sink of desired edge (cannot be null!)
Returns:
IOPEdge between given nodes if graph contains such an edge or null otherwise

setHeight

public void setHeight(double h)
Sets the height of the graph.

Parameters:
h - the desired height, a double.
See Also:
getHeight()

setWidth

public void setWidth(double w)
Sets the width of the graph.

Parameters:
w - the desired width, a double.
See Also:
getWidth()

getHeight

public double getHeight()
Returns the height of the graph.

Returns:
the height, a double.
See Also:
setHeight(double)

getWidth

public double getWidth()
Returns the width of the graph.

Returns:
the width, a double.
See Also:
setWidth(double)

addChangeListener

public void addChangeListener(ChangeListener cl)
Adds a listener to those registered for change events.

Parameters:
cl - the new listener
See Also:
removeChangeListener(javax.swing.event.ChangeListener)

removeChangeListener

public void removeChangeListener(ChangeListener cl)
Removes a listener to those registered for change events.

Parameters:
cl - the new listener
See Also:
addChangeListener(javax.swing.event.ChangeListener)

fireChange

public void fireChange()
Is used to notify all those listeners registered that the graph has changed.


Graphics2D Actor API