Exemplo n.º 1
0
  /**
   * This method calculates the size of this compound model and then recursively calculates the size
   * of its parent, which continues until root.
   */
  public void calculateSizeUp() {
    if (getParentModel() != null && !isRoot) {
      if (this.children.size() == 0) {
        setSize(CompoundModel.DEFAULT_SIZE);
      } else {
        Rectangle bound = calculateBounds();
        Dimension diff = getLocationAbs().getDifference(bound.getLocation());

        setLocationAbs(new Point(bound.x - this.MARGIN_SIZE, bound.y - this.MARGIN_SIZE));
        setSize(
            new Dimension(
                bound.width + (2 * this.MARGIN_SIZE),
                bound.height + (2 * this.MARGIN_SIZE) + this.labelHeight));

        Iterator iter = this.children.iterator();

        while (iter.hasNext()) {
          NodeModel child = (NodeModel) iter.next();
          child.setLocationAbs(
              child
                  .getLocationAbs()
                  .translate(diff.width + this.MARGIN_SIZE, diff.height + this.MARGIN_SIZE));
        }
      }

      (getParentModel()).calculateSizeUp();
    }

    updatePolygonsOfChildren();
  }
Exemplo n.º 2
0
  /** This method calculates sizes of children recursively and then calculates its own size. */
  public void calculateSizeDown() {

    // First, recursively calculate sizes of children compounds
    Iterator iter = this.children.iterator();

    while (iter.hasNext()) {
      NodeModel child = (NodeModel) iter.next();

      if (child instanceof CompoundModel) {
        ((CompoundModel) child).calculateSizeDown();
      }
    }

    if (getParentModel() != null && !isRoot) {
      // Second, calculate size of this compound model
      if (this.children.size() == 0) {
        setSize(CompoundModel.DEFAULT_SIZE);
      } else {
        Rectangle bound = calculateBounds();
        Dimension diff = getLocationAbs().getDifference(bound.getLocation());

        setLocationAbs(new Point(bound.x - this.MARGIN_SIZE, bound.y - this.MARGIN_SIZE));
        setSize(
            new Dimension(
                bound.width + (2 * this.MARGIN_SIZE),
                bound.height + (2 * this.MARGIN_SIZE) + this.labelHeight));

        iter = this.children.iterator();

        while (iter.hasNext()) {
          NodeModel child = (NodeModel) iter.next();
          child.setLocationAbs(
              child
                  .getLocationAbs()
                  .translate(diff.width + this.MARGIN_SIZE, diff.height + this.MARGIN_SIZE));
        }
      }
    }
  }
Exemplo n.º 3
0
  /** This method finds the boundaries of this compound node. */
  public Rectangle calculateBounds() {
    int top = Integer.MAX_VALUE;
    int left = Integer.MAX_VALUE;
    int right = 0;
    int bottom = 0;
    int nodeTop;
    int nodeLeft;
    int nodeRight;
    int nodeBottom;

    /* Checks the nodes' locations which are children of
     * this compound node.
     */
    Iterator itr = this.getChildren().iterator();

    while (itr.hasNext()) {
      NodeModel node = (NodeModel) itr.next();

      Point locAbs = node.getLocationAbs();
      Dimension size = node.getSize();
      nodeTop = locAbs.y;
      nodeLeft = locAbs.x;
      nodeRight = locAbs.x + size.width;
      nodeBottom = locAbs.y + size.height;

      if (top > nodeTop) {
        top = nodeTop;
      }

      if (left > nodeLeft) {
        left = nodeLeft;
      }

      if (right < nodeRight) {
        right = nodeRight;
      }

      if (bottom < nodeBottom) {
        bottom = nodeBottom;
      }
    }

    // Checks the bendpoints' locations.
    if (this.isRoot) {
      itr = this.getEdges().iterator();
    } else {
      itr = this.getEdgeIterator(ALL_EDGES, true, true);
    }

    while (itr.hasNext()) {
      EdgeModel edge = (EdgeModel) itr.next();
      edge.updateBendpoints();

      for (int i = 0; i < edge.bendpoints.size(); i++) {
        EdgeBendpoint eb = (EdgeBendpoint) edge.bendpoints.get(i);
        Point loc = eb.getLocationFromModel(edge);

        int x = loc.x;
        int y = loc.y;

        if (top > y) {
          top = y;
        }

        if (left > x) {
          left = x;
        }

        if (right < x) {
          right = x;
        }

        if (bottom < y) {
          bottom = y;
        }
      }
    }

    // Do we have any nodes in this graph?
    if (top == Double.MAX_VALUE) {
      return null;
    }

    return new Rectangle(left, top, right - left, bottom - top);
  }