de.saar.chorus.jgraph
Class ImprovedJGraph<NodeType,NodeData extends INodeData<NodeType>,EdgeType,EdgeData extends IEdgeData<EdgeType>>

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by JGraph
                  extended by ImprovedJGraph<NodeType,NodeData,EdgeType,EdgeData>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, CellViewFactory
Direct Known Subclasses:
ImprovedJGraphAdapter, JDomGraph

public abstract class ImprovedJGraph<NodeType,NodeData extends INodeData<NodeType>,EdgeType,EdgeData extends IEdgeData<EdgeType>>
extends JGraph

See Also:
Serialized Form

Nested Class Summary
 class ImprovedJGraph.EdgeSortingComparator
           
 
Nested classes/interfaces inherited from class JGraph
JGraph.EmptySelectionModel
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class JGraph
ANTIALIASED_PROPERTY, CROSS_GRID_MODE, DOT_GRID_MODE, EDITABLE_PROPERTY, GRAPH_LAYOUT_CACHE_PROPERTY, GRAPH_MODEL_PROPERTY, GRID_SIZE_PROPERTY, GRID_VISIBLE_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, LINE_GRID_MODE, MARQUEE_HANDLER_PROPERTY, PORTS_VISIBLE_PROPERTY, SCALE_PROPERTY, SELECTION_MODEL_PROPERTY, VERSION
 
Fields inherited from class JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImprovedJGraph()
           
 
Method Summary
 DefaultEdge addEdge(EdgeData data, DefaultGraphCell src, DefaultGraphCell tgt)
          Adds a new edge to the graph (and the underlying model).
 DefaultGraphCell addNode(String name, NodeData data)
          Adds a new node to the graph (and the underlying model).
static
<E,T> void
addToMapList(Map<E,List<T>> map, E key, T nVal)
          Generic method that handles maps from an Object to a list of objects and ads a new entry to the value list with the specified object key.
 void adjustNodeWidths()
          Compute the true widths of the node labels in the graph, change the node widths such that all the labels fit in, and recompute the layout.
 void clear()
          Remove all nodes and edges in the graph.
 void computeAdjacency()
          Go through all the edges of the graph and record the adjacency matrix in the "parents" and "children" maps.
abstract  void computeLayout()
           
 int computeNodeHeight(DefaultGraphCell node)
          Computes the height of the label of a node.
 int computeNodeWidth(DefaultGraphCell node)
          Computes the width of the label of a node.
 DefaultGraphCell findNodeOrEdgeAt(int x, int y)
          Return the node at the mouse position (x,y).
 List<DefaultGraphCell> getChildren(DefaultGraphCell node)
           
 EdgeData getEdgeData(DefaultEdge edge)
          Get the edge data of an edge cell.
 Set<DefaultEdge> getEdges()
          Get all edges of the graph.
 List<DefaultEdge> getInEdges(DefaultGraphCell node)
          Compute the incoming edges for a node.
 String getName()
          Get the name (= ID) of the graph.
 NodeData getNodeData(DefaultGraphCell node)
          Get the node data of a node cell.
 DefaultGraphCell getNodeForName(String name)
          Look up the node with the specified name.
 Set<DefaultGraphCell> getNodes()
          Get all nodes of the graph.
 List<DefaultEdge> getOutEdges(DefaultGraphCell node)
          Compute the outgoing edges for a node.
 List<DefaultGraphCell> getParents(DefaultGraphCell node)
           
 DefaultGraphCell getRightSibling(DefaultGraphCell node)
          Returns the right sibling of a given node (if there is one).
 List<DefaultEdge> getSortedEdges()
          Return all edges of the graph in a sorted List .
 DefaultGraphCell getSourceNode(DefaultEdge edge)
          Returns the source node of an edge.
 DefaultGraphCell getTargetNode(DefaultEdge edge)
          Returns the target node of and edge.
 String getToolTipText(MouseEvent e)
          Overrides the getToolTipText method of JComponent.
 boolean isForest()
          Determines whether or not this graph is a forest.
 boolean isLeaf(DefaultGraphCell node)
           
 boolean isRelativeLeaf(DefaultGraphCell node, Collection<DefaultGraphCell> subgraph)
           
 boolean isRelativeRoot(DefaultGraphCell node, Collection<DefaultGraphCell> subgraph)
           
 boolean isRoot(DefaultGraphCell node)
           
 void setName(String name)
          Set the name (= ID) of the dominance graph.
 
Methods inherited from class JGraph
addGraphSelectionListener, addSampleData, addSelectionCell, addSelectionCells, cancelEditing, clearSelection, cloneCells, convertValueToString, createBounds, createView, fromScreen, fromScreen, getCellBounds, getCellBounds, getDescendantList, getDescendants, getEditClickCount, getEditingCell, getFirstCellForLocation, getGraphLayoutCache, getGridColor, getGridMode, getGridSize, getHandleColor, getHandleSize, getHighlightColor, getInvokesStopCellEditing, getLockedHandleColor, getMarqueeColor, getMarqueeHandler, getMinimumMove, getModel, getNextCellForLocation, getNextViewAt, getNextViewAt, getPortForLocation, getPortViewAt, getPreferredScrollableViewportSize, getRoots, getRoots, getScale, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectionCell, getSelectionCells, getSelectionCount, getSelectionModel, getTolerance, getUI, getUIClassID, graphDidChange, isAntiAliased, isBendable, isCellEditable, isCellSelected, isCloneable, isConnectable, isDisconnectable, isDisconnectOnMove, isDragEnabled, isDropEnabled, isEditable, isEditing, isGridEnabled, isGridVisible, isMoveable, isMoveBelowZero, isPortsVisible, isSelectionEmpty, isSelectNewCells, isSizeable, main, removeGraphSelectionListener, removeSelectionCell, scrollCellToVisible, scrollPointToVisible, setAntiAliased, setBendable, setCloneable, setConnectable, setDisconnectable, setDisconnectOnMove, setDragEnabled, setDropEnabled, setEditable, setEditClickCount, setGraphLayoutCache, setGridColor, setGridEnabled, setGridMode, setGridSize, setGridVisible, setHandleColor, setHandleSize, setHighlightColor, setInvokesStopCellEditing, setLockedHandleColor, setMarqueeColor, setMarqueeHandler, setMinimumMove, setModel, setMoveable, setMoveBelowZero, setPortsVisible, setScale, setSelectionCell, setSelectionCells, setSelectionModel, setSelectNewCells, setSizeable, setTolerance, setUI, snap, snap, startEditingAtCell, stopEditing, toScreen, toScreen, updateAutoSize, updateUI
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Accessible
getAccessibleContext
 

Constructor Detail

ImprovedJGraph

public ImprovedJGraph()
Method Detail

clear

public void clear()
Remove all nodes and edges in the graph.


addNode

public DefaultGraphCell addNode(String name,
                                NodeData data)
Adds a new node to the graph (and the underlying model). The attributes of the new node are computed automatically from the node data.

Parameters:
data - the data for the new node.
Returns:
a new DefaultGraphCell object in this graph.

addEdge

public DefaultEdge addEdge(EdgeData data,
                           DefaultGraphCell src,
                           DefaultGraphCell tgt)
Adds a new edge to the graph (and the underlying model). The edge goes from the 0-th port of the node src to the 0-th port of the node tgt. The style attributes of the new edge are computed automatically from the edge data.

Parameters:
data - the data for the new edge.
src - the node cell at which the edge should start.
tgt - the node cell at which the edge should end.
Returns:
a new DefaultEdge object in this graph.

getNodes

public Set<DefaultGraphCell> getNodes()
Get all nodes of the graph.

Returns:
the set of all nodes.

getEdges

public Set<DefaultEdge> getEdges()
Get all edges of the graph.

Returns:
the set of all edges.

computeNodeWidth

public int computeNodeWidth(DefaultGraphCell node)
Computes the width of the label of a node. This is based on computeTextWidth, and is subject to the same caveats.

Parameters:
node - the node whose width we want to know
Returns:
the width of node in pixels, or 30 if this can't be determined.
See Also:
computeTextWidth

computeNodeHeight

public int computeNodeHeight(DefaultGraphCell node)
Computes the height of the label of a node. This is based on computeTextHeight, and is subject to the same caveats.

Parameters:
node - the node whose height we want to know
Returns:
the height of node in pixels, or 30 if this can't be determined.
See Also:
computeTextHeight

adjustNodeWidths

public void adjustNodeWidths()
Compute the true widths of the node labels in the graph, change the node widths such that all the labels fit in, and recompute the layout. A typical sequence of method calls is as follows: 1. graph.computeLayout(): This computes an initial layout. 2. display the JFrame; this determines the window size based on the results of the preliminary layout computation 3. graph.adjustNodeWidths(): This corrects the node sizes and graph layout.


computeLayout

public abstract void computeLayout()

getNodeData

public NodeData getNodeData(DefaultGraphCell node)
Get the node data of a node cell.

Parameters:
node -
Returns:
the node data.

getEdgeData

public EdgeData getEdgeData(DefaultEdge edge)
Get the edge data of an edge cell.

Parameters:
edge -
Returns:
the edge data.

getNodeForName

public DefaultGraphCell getNodeForName(String name)
Look up the node with the specified name.

Parameters:
name -
Returns:
that node.

getToolTipText

public String getToolTipText(MouseEvent e)
Overrides the getToolTipText method of JComponent.

Overrides:
getToolTipText in class JGraph

findNodeOrEdgeAt

public DefaultGraphCell findNodeOrEdgeAt(int x,
                                         int y)
Return the node at the mouse position (x,y).

Parameters:
x -
y -
Returns:
reference to the node cell; null if there is no node at the position.

isRoot

public boolean isRoot(DefaultGraphCell node)

isRelativeRoot

public boolean isRelativeRoot(DefaultGraphCell node,
                              Collection<DefaultGraphCell> subgraph)

isLeaf

public boolean isLeaf(DefaultGraphCell node)

isRelativeLeaf

public boolean isRelativeLeaf(DefaultGraphCell node,
                              Collection<DefaultGraphCell> subgraph)

computeAdjacency

public void computeAdjacency()
Go through all the edges of the graph and record the adjacency matrix in the "parents" and "children" maps.


addToMapList

public static <E,T> void addToMapList(Map<E,List<T>> map,
                                      E key,
                                      T nVal)
Generic method that handles maps from an Object to a list of objects and ads a new entry to the value list with the specified object key. If the map does not contain the key yet, it is added.

Type Parameters:
E - the key type
T - the type of the list elements
Parameters:
map - the map
key - the key to which list the new value shall be added
nVal - the new value

getSortedEdges

public List<DefaultEdge> getSortedEdges()
Return all edges of the graph in a sorted List .

Returns:
the edges sorted by their order of inserting

setName

public void setName(String name)
Set the name (= ID) of the dominance graph. This name could e.g. be displayed in the window title.

Overrides:
setName in class Component
Parameters:
name - new name of the graph.

getName

public String getName()
Get the name (= ID) of the graph.

Overrides:
getName in class Component
Returns:
Returns the name.

getInEdges

public List<DefaultEdge> getInEdges(DefaultGraphCell node)
Compute the incoming edges for a node. The returned list lists the complete edges (with types). The list is sorted before returning by the EdgeSortingComparator

Parameters:
node - the node whose in-edges we want
Returns:
the list of its in-edges.

getSourceNode

public DefaultGraphCell getSourceNode(DefaultEdge edge)
Returns the source node of an edge.

Parameters:
edge - the edge
Returns:
the edge's source node

getTargetNode

public DefaultGraphCell getTargetNode(DefaultEdge edge)
Returns the target node of and edge.

Parameters:
edge - the edge
Returns:
the edge's target node

getOutEdges

public List<DefaultEdge> getOutEdges(DefaultGraphCell node)
Compute the outgoing edges for a node. The returned list lists the complete edges (with types). The list is sorted before returning by the EdgeSortingComparator

Parameters:
node - the node to compute the outgoing edges for
Returns:
the sorted list of out-edges

isForest

public boolean isForest()
Determines whether or not this graph is a forest. TODO Consider possible cycles here!!

Returns:
true if this graph is a forest.

getChildren

public List<DefaultGraphCell> getChildren(DefaultGraphCell node)
Returns:
Returns the children.

getParents

public List<DefaultGraphCell> getParents(DefaultGraphCell node)
Returns:
Returns the parents.

getRightSibling

public DefaultGraphCell getRightSibling(DefaultGraphCell node)
Returns the right sibling of a given node (if there is one). If the node has more than one parent, then the method returns null.

Parameters:
node - the node (the left sibling)
Returns:
the right sibling, or null if there is none