示例#1
1
  private void analyzeEdges(UniversalGraph<Node, Edge> graph, int colCount) {
    for (Node node : graph.getNodes()) {
      node.conLeft = false;
      node.conRight = false;
      node.conTop = false;
      node.conBottom = false;
      node.conLeftTop = 0;
      node.conLeftBottom = 0;
      node.conRightTop = 0;
      node.conRightBottom = 0;
    }

    int rowCount = coordinates.size();
    ArrayList<Edge> edgesList = new ArrayList<Edge>(graph.getEdges());
    for (int row = 0; row < rowCount; row++) {
      for (int jump = 0; jump < colCount - 1; jump++) {
        Iterator<Edge> edges = edgesList.iterator();
        while (edges.hasNext()) {
          Edge edge = edges.next();
          if (edge.forward() && edge.sameRow(row) && edge.jump() == jump) {
            analyzeEdge(row, jump, edge);
            edges.remove();
          }
        }
        edges = edgesList.iterator();
        while (edges.hasNext()) {
          Edge edge = edges.next();
          if (edge.backward() && edge.sameRow(row) && edge.jump() == jump) {
            analyzeEdge(row, jump, edge);
            edges.remove();
          }
        }
      }
    }
  }
示例#2
0
  @Override
  protected void performGraphLayout(UniversalGraph<Node, Edge> graph) {
    RuleScene scene = (RuleScene) graph.getScene();
    if (scene.getRule() == null) return;

    coordinates = scene.getRule().node.coordinates();

    List<Integer> columns = new ArrayList<Integer>();
    columns.add(originX);
    for (List<Node> nodes : coordinates) {
      for (int col = 1; col < nodes.size(); col++) {
        while (columns.size() <= col) columns.add(horizontalGap);

        Node minNode = nodes.get(col - 1);
        Node maxNode = nodes.get(col);
        int width = horizontalGap;
        if (maxNode != null && minNode != null) {
          int middleWidth = 0;
          for (Edge edge : minNode.outgoing) {
            if (edge.target == maxNode) {
              LabelWidget label = (LabelWidget) scene.findWidget(edge).getChildren().get(0);
              if (label.getLabel() != null)
                middleWidth = Math.max(middleWidth, 30 + label.getPreferredBounds().width);
            }
          }
          for (Edge edge : maxNode.outgoing) {
            if (edge.target == minNode) {
              LabelWidget label = (LabelWidget) scene.findWidget(edge).getChildren().get(0);
              if (label.getLabel() != null)
                middleWidth = Math.max(middleWidth, 30 + label.getPreferredBounds().width);
            }
          }
          middleWidth = Math.max(horizontalGap, middleWidth);

          int minWidth = scene.findWidget(minNode).getPreferredBounds().width / 2;
          int minLoopWidth = 0;
          for (Edge edge : minNode.outgoing) {
            if (edge.loop()) {
              LabelWidget label = (LabelWidget) scene.findWidget(edge).getChildren().get(0);
              if (label.getLabel() != null)
                minLoopWidth = Math.max(minLoopWidth, label.getPreferredBounds().width / 2);
            }
          }

          int maxWidth = scene.findWidget(maxNode).getPreferredBounds().width / 2;
          int maxLoopWidth = 0;
          for (Edge edge : maxNode.outgoing) {
            if (edge.loop()) {
              LabelWidget label = (LabelWidget) scene.findWidget(edge).getChildren().get(0);
              if (label.getLabel() != null)
                maxLoopWidth = Math.max(maxLoopWidth, label.getPreferredBounds().width / 2);
            }
          }

          width =
              Math.max(
                  horizontalGap,
                  Math.max(minWidth, minLoopWidth)
                      + middleWidth
                      + Math.max(maxWidth, maxLoopWidth));
        }
        columns.set(col, Math.max(columns.get(col), width));
      }
    }

    for (int i = 1; i < columns.size(); i++) columns.set(i, columns.get(i - 1) + columns.get(i));

    analyzeEdges(graph, columns.size());

    int rowCount = coordinates.size();
    int rows[] = new int[rowCount];
    for (int row = 0; row < rowCount; row++) {
      int top = 0;
      for (Node node : coordinates.get(row)) {
        if (node != null) {
          top = Math.max(top, node.conLeftTop);
          top = Math.max(top, node.conRightTop);

          int loop = 0;
          for (Edge edge : node.outgoing) {
            if (edge.loop()) loop++;
          }
          top = Math.max(top, loop);
        }
      }

      int bottom = 0;
      if (row > 0) {
        for (Node node : coordinates.get(row - 1)) {
          if (node != null) {
            bottom = Math.max(bottom, node.conLeftBottom);
            bottom = Math.max(bottom, node.conRightBottom);
          }
        }
      }

      int height = top + bottom;
      rows[row] = 50 * height;
      if (row > 0) rows[row] += rows[row - 1];
      if (height == 0) rows[row] += originY;
      else rows[row] += verticalGap;
    }

    for (Node node : graph.getNodes()) {
      Widget widget = scene.findWidget(node);
      Point location =
          new Point(columns.get(node.col), rows[node.row] /*originY + node.row * verticalGap*/);
      if (animated) scene.getSceneAnimator().animatePreferredLocation(widget, location);
      else widget.setPreferredLocation(location);
    }
  }