示例#1
0
  /**
   * Adds the specified JGraphT edge to be reflected by this graph model. To be called only for
   * edges that already exist in the JGraphT graph.
   *
   * @param jtEdge a JGraphT edge to be reflected by this graph model.
   */
  void handleJGraphTAddedEdge(E jtEdge) {
    DefaultEdge edgeCell = cellFactory.createEdgeCell(jtEdge);
    edgeToCell.put(jtEdge, edgeCell);
    cellToEdge.put(edgeCell, jtEdge);

    ConnectionSet cs = new ConnectionSet();
    cs.connect(
        edgeCell,
        getVertexPort(jtGraph.getEdgeSource(jtEdge)),
        getVertexPort(jtGraph.getEdgeTarget(jtEdge)));

    internalInsertCell(edgeCell, createEdgeAttributeMap(edgeCell), cs);
  }
示例#2
0
  /**
   * Adds/removes an edge to/from the underlying JGraphT graph according to the change in the
   * specified JGraph edge. If both vertices are connected, we ensure to have a corresponding
   * JGraphT edge. Otherwise, we ensure NOT to have a corresponding JGraphT edge.
   *
   * <p>This method is to be called only for edges that have already been changed in the JGraph
   * graph.
   *
   * @param jEdge the JGraph edge that has changed.
   */
  void handleJGraphChangedEdge(org.jgraph.graph.Edge jEdge) {
    if (isDangling(jEdge)) {
      if (cellToEdge.containsKey(jEdge)) {
        // a non-dangling edge became dangling -- remove the JGraphT
        // edge by faking as if the edge is removed from the JGraph.
        // TODO: Consider keeping the JGraphT edges outside the graph
        // to avoid loosing user data, such as weights.
        handleJGraphRemovedEdge(jEdge);
      } else {
        // a dangling edge is still dangling -- just ignore.
      }
    } else {
      // edge is not dangling
      if (cellToEdge.containsKey(jEdge)) {
        // edge already has a corresponding JGraphT edge.
        // check if any change to its endpoints.
        E jtEdge = cellToEdge.get(jEdge);

        Object jSource = getSourceVertex(this, jEdge);
        Object jTarget = getTargetVertex(this, jEdge);

        Object jtSource = cellToVertex.get(jSource);
        Object jtTarget = cellToVertex.get(jTarget);

        if ((jtGraph.getEdgeSource(jtEdge) == jtSource)
            && (jtGraph.getEdgeTarget(jtEdge) == jtTarget)) {
          // no change in edge's endpoints -- nothing to do.
        } else {
          // edge's end-points have changed -- need to refresh the
          // JGraphT edge. Refresh by faking as if the edge has been
          // removed from JGraph and then added again.
          // ALSO HERE: consider an alternative that maintains user
          // data
          handleJGraphRemovedEdge(jEdge);
          handleJGraphInsertedEdge(jEdge);
        }
      } else {
        // a new edge
        handleJGraphInsertedEdge(jEdge);
      }
    }
  }