/**
   * Set the graph being viewed. If there is a graph already and it contains data, delete the
   * figures of that graph's nodes and edges (but don't modify the graph itself).
   */
  public void setGraphModel(GraphModel model) {
    Iterator i;

    // FIXME we shouldn't have to cast this.
    // FigureLayer layer = getGraphPane().getForegroundLayer();

    if (_model != null) {
      // Clear existing figures
      Object root = _model.getRoot();

      if (_model.getNodeCount(root) != 0) {
        for (i = _model.nodes(root); i.hasNext(); ) {
          clearNode(i.next());
        }

        for (i = GraphUtilities.totallyContainedEdges(root, _model); i.hasNext(); ) {
          clearEdge(i.next());
        }
      }

      _model.removeGraphListener(_localListener);
    }

    // Set the graph
    _model = model;

    if (_model != null) {
      _model.addGraphListener(_localListener);

      Object root = _model.getRoot();
      GraphEvent evt = new GraphEvent(new Object(), GraphEvent.STRUCTURE_CHANGED, root);
      _localListener.structureChanged(evt);
    }
  }
  /** @see HorizontalPlacement#buildRankSeparators(RankList) */
  void buildRankSeparators(RankList ranks) {
    CompoundDirectedGraph g = (CompoundDirectedGraph) graph;

    Rank rank;
    for (int row = 0; row < g.ranks.size(); row++) {
      rank = g.ranks.getRank(row);
      Node n = null, prev = null;
      for (int j = 0; j < rank.size(); j++) {
        n = rank.getNode(j);
        if (prev == null) {
          Node left = addSeparatorsLeft(n, null);
          if (left != null) {
            Edge e = new Edge(graphLeft, getPrime(left), 0, 0);
            prime.edges.add(e);
            e.delta = graph.getPadding(n).left + graph.getMargin().left;
          }

        } else {
          Subgraph s = GraphUtilities.getCommonAncestor(prev, n);
          Node left = addSeparatorsRight(prev, s);
          Node right = addSeparatorsLeft(n, s);
          createEdge(left, right);
        }
        prev = n;
      }
      if (n != null) addSeparatorsRight(n, null);
    }
  }
Exemplo n.º 3
0
  private void checkValidEndParallel(JSONObject graph) {
    List<JSONObject> endParallels =
        GraphUtilities.findOperatorByKind(BVirtualMarker.END_PARALLEL, graph);

    for (JSONObject endParallel : endParallels) {
      List<JSONObject> endParallelParents = null;
      // Setting up loop
      JSONObject endParallelParent = endParallel;
      do {
        endParallelParents = GraphUtilities.getUpstream(endParallelParent, graph);
        if (endParallelParents.size() != 1) {
          throw new IllegalStateException(
              "Cannot union multiple streams before invoking endParallel()");
        }
        endParallelParent = endParallelParents.get(0);
      } while (((String) endParallelParent.get("kind")).startsWith("$"));
      List<JSONObject> endParallelParentChildren =
          GraphUtilities.getDownstream(endParallelParent, graph);
      if (endParallelParentChildren.size() != 1) {
        throw new IllegalStateException("Cannot fanout a stream before invoking endParallel()");
      }
    }
  }
Exemplo n.º 4
0
 /**
  * Checks if the path is already contained in the map
  *
  * @param map
  * @param path
  * @return
  */
 private static boolean containsPath(
     Set<GraphPath<IModelEntity, Relationship>> map, GraphPath<IModelEntity, Relationship> path) {
   logger.debug("IN");
   Iterator<GraphPath<IModelEntity, Relationship>> iter = map.iterator();
   while (iter.hasNext()) {
     GraphPath<IModelEntity, Relationship> graphPath = iter.next();
     if (GraphUtilities.arePathsEquals(graphPath, path)) {
       logger.debug("Adding the path in the map" + path.toString());
       return true;
     }
   }
   logger.debug("OUT");
   return false;
 }
  /**
   * Render the current graph again by recreating the figures for all nodes and edges, but do not
   * alter the connectivity in the graph. This should be called when changes to renderers are made.
   */
  public void rerender() {
    // FIXME: it would be nice to be able to do this without all
    // stupid business with the selection model.
    List selectedEdges = new LinkedList();
    List selectedNodes = new LinkedList();

    // Remove any old objects that no longer exist in the model Do
    // the edges first, then the nodes, since we cannot blow away
    // selection on an edge before getting rid of the endpoints of
    // the edge.
    Iterator figures = (new HashSet(_map.values())).iterator();

    while (figures.hasNext()) {
      Figure figure = (Figure) figures.next();
      Object object = figure.getUserObject();

      if (_model.isEdge(object)) {
        if (!GraphUtilities.isPartiallyContainedEdge(object, _model.getRoot(), _model)) {
          if (_selectionModel.containsSelection(figure)) {
            _selectionModel.removeSelection(figure);
          }

          clearEdge(object);

          // Previously, the figure was being left in _map,
          // which results in an accumulation over time
          // of figures that should not be rendered.
          // EAL 4/29/04.
          _map.remove(object);
        }
      }
    }

    figures = (new HashSet(_map.values())).iterator();

    while (figures.hasNext()) {
      Figure figure = (Figure) figures.next();
      Object object = figure.getUserObject();

      if (_model.isNode(object)) {
        if (!GraphUtilities.isContainedNode(object, _model.getRoot(), _model)) {
          if (_selectionModel.containsSelection(figure)) {
            _selectionModel.removeSelection(figure);
          }

          clearNode(object);

          // Previously, the figure was being left in _map,
          // which results in an accumulation over time
          // of figures that should not be rendered.
          // EAL 4/29/04.
          _map.remove(object);
        }
      }
    }

    // Save the selected edges.
    Iterator edges = GraphUtilities.totallyContainedEdges(_model.getRoot(), _model);

    while (edges.hasNext()) {
      Object edge = edges.next();
      Figure oldFigure = getFigure(edge);
      boolean selected = _selectionModel.containsSelection(oldFigure);

      if (selected) {
        selectedEdges.add(edge);
      }
    }

    // Save the selected nodes.
    Iterator nodes = (GraphUtilities.nodeSet(_model.getRoot(), _model)).iterator();

    while (nodes.hasNext()) {
      Object node = nodes.next();
      Figure oldFigure = getFigure(node);
      boolean selected = _selectionModel.containsSelection(oldFigure);

      if (selected) {
        selectedNodes.add(node);
      }
    }

    // Clear all the selections (note that there may be selected objects
    // which no longer exist!)
    _selectionModel.clearSelection();

    // Draw the nodes to be rendered before the edges.
    nodes = _model.nodesBeforeEdges(_model.getRoot());

    while (nodes.hasNext()) {
      Object node = nodes.next();
      drawNode(node);
    }

    // Draw the edges that are connected to any of the above nodes.
    edges = GraphUtilities.partiallyContainedEdges(_model.getRoot(), _model);

    while (edges.hasNext()) {
      Object edge = edges.next();
      drawEdge(edge);

      if (selectedEdges.contains(edge)) {
        _selectionModel.addSelection(getFigure(edge));
      }
    }

    // Draw the nodes to be rendered after the edges.
    nodes = _model.nodesAfterEdges(_model.getRoot());

    while (nodes.hasNext()) {
      Object node = nodes.next();
      drawNode(node);
    }

    // Restore the selected nodes.
    nodes = (GraphUtilities.nodeSet(_model.getRoot(), _model)).iterator();

    while (nodes.hasNext()) {
      Object node = nodes.next();

      if (selectedNodes.contains(node)) {
        _selectionModel.addSelection(getFigure(node));
      }
    }
  }