Class ImprovedJGraph<NodeType,NodeData extends INodeData<NodeType>,EdgeType,EdgeData extends IEdgeData<EdgeType>>

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.jgraph.JGraph
de.saar.chorus.jgraph.improvedjgraph.ImprovedJGraph<NodeType,NodeData,EdgeType,EdgeData>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
ImprovedJGraphAdapter

public abstract class ImprovedJGraph<NodeType,NodeData extends INodeData<NodeType>,EdgeType,EdgeData extends IEdgeData<EdgeType>> extends org.jgraph.JGraph
See Also:
  • Field Details

    • nodes

      protected Set<org.jgraph.graph.DefaultGraphCell> nodes
    • edges

      protected Set<org.jgraph.graph.DefaultEdge> edges
    • nameToNode

      protected Map<String,org.jgraph.graph.DefaultGraphCell> nameToNode
    • parents

      protected Map<org.jgraph.graph.DefaultGraphCell,List<org.jgraph.graph.DefaultGraphCell>> parents
    • children

      protected Map<org.jgraph.graph.DefaultGraphCell,List<org.jgraph.graph.DefaultGraphCell>> children
    • name

      protected String name
    • nodeFont

      protected Font nodeFont
    • edgeOrder

      protected Map<org.jgraph.graph.DefaultEdge,Integer> edgeOrder
    • edgeCounter

      protected int edgeCounter
  • Constructor Details

    • ImprovedJGraph

      public ImprovedJGraph()
  • Method Details

    • clear

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

      public org.jgraph.graph.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.
    • defaultNodeAttributes

      protected abstract org.jgraph.graph.AttributeMap defaultNodeAttributes(NodeType type)
    • addEdge

      public org.jgraph.graph.DefaultEdge addEdge(EdgeData data, org.jgraph.graph.DefaultGraphCell src, org.jgraph.graph.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.
    • defaultEdgeAttributes

      protected abstract org.jgraph.graph.AttributeMap defaultEdgeAttributes(EdgeType type)
    • getNodes

      public Set<org.jgraph.graph.DefaultGraphCell> getNodes()
      Get all nodes of the graph.
      Returns:
      the set of all nodes.
    • getEdges

      public Set<org.jgraph.graph.DefaultEdge> getEdges()
      Get all edges of the graph.
      Returns:
      the set of all edges.
    • computeNodeWidth

      public int computeNodeWidth(org.jgraph.graph.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(org.jgraph.graph.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
    • computeLayout

      public abstract void computeLayout()
    • getNodeData

      public NodeData getNodeData(org.jgraph.graph.DefaultGraphCell node)
      Get the node data of a node cell.
      Parameters:
      node -
      Returns:
      the node data.
    • getEdgeData

      public EdgeData getEdgeData(org.jgraph.graph.DefaultEdge edge)
      Get the edge data of an edge cell.
      Parameters:
      edge -
      Returns:
      the edge data.
    • getNodeForName

      public org.jgraph.graph.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 org.jgraph.JGraph
    • findNodeOrEdgeAt

      public org.jgraph.graph.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(org.jgraph.graph.DefaultGraphCell node)
    • isRelativeRoot

      public boolean isRelativeRoot(org.jgraph.graph.DefaultGraphCell node, Collection<org.jgraph.graph.DefaultGraphCell> subgraph)
    • isLeaf

      public boolean isLeaf(org.jgraph.graph.DefaultGraphCell node)
    • isRelativeLeaf

      public boolean isRelativeLeaf(org.jgraph.graph.DefaultGraphCell node, Collection<org.jgraph.graph.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<org.jgraph.graph.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<org.jgraph.graph.DefaultEdge> getInEdges(org.jgraph.graph.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 org.jgraph.graph.DefaultGraphCell getSourceNode(org.jgraph.graph.DefaultEdge edge)
      Returns the source node of an edge.
      Parameters:
      edge - the edge
      Returns:
      the edge's source node
    • getTargetNode

      public org.jgraph.graph.DefaultGraphCell getTargetNode(org.jgraph.graph.DefaultEdge edge)
      Returns the target node of and edge.
      Parameters:
      edge - the edge
      Returns:
      the edge's target node
    • getOutEdges

      public List<org.jgraph.graph.DefaultEdge> getOutEdges(org.jgraph.graph.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.
    • isForest

      public boolean isForest(Set<org.jgraph.graph.DefaultGraphCell> subgraph)
    • getChildren

      public List<org.jgraph.graph.DefaultGraphCell> getChildren(org.jgraph.graph.DefaultGraphCell node)
      Returns:
      Returns the children.
    • getParents

      public List<org.jgraph.graph.DefaultGraphCell> getParents(org.jgraph.graph.DefaultGraphCell node)
      Returns:
      Returns the parents.
    • getRelativeRightSibling

      public org.jgraph.graph.DefaultGraphCell getRelativeRightSibling(org.jgraph.graph.DefaultGraphCell node, Collection<org.jgraph.graph.DefaultGraphCell> subgraph)
      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
    • wccs

      protected List<Set<org.jgraph.graph.DefaultGraphCell>> wccs()
    • getNodeFont

      public Font getNodeFont()