Exemplo n.º 1
0
  private Rectangle2D getContentsBoundingBox() {
    Rectangle2D bb = null;

    for (VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) {
      bb = BoundingBoxHelper.union(bb, a.getLabelBoundingBox());
    }
    if (bb == null) bb = contentsBB;
    else {
      bb.setRect(
          bb.getMinX() - frameDepth,
          bb.getMinY() - frameDepth,
          bb.getWidth() + 2.0 * frameDepth,
          bb.getHeight() + 2.0 * frameDepth);
    }

    if (bb == null) bb = new Rectangle2D.Double(0, 0, 1, 1);

    contentsBB = (Rectangle2D) bb.clone();

    return bb;
  }
  /** Paints the <tt>visualEdge</tt>. No arrowhead is drawn. */
  public void paint(VisualGraphComponent component, Graphics2D g2d) {
    VisualEdge vEdge = (VisualEdge) component;
    Rectangle fromvertexBounds;
    Rectangle tovertexBounds;
    GeneralPath drawPath;
    VisualVertex visualVertexA = vEdge.getVisualVertexA();
    VisualVertex visualVertexB = vEdge.getVisualVertexB();
    GraphLayoutManager layoutmanager = vEdge.getVisualGraph().getGraphLayoutManager();

    drawPath = vEdge.getGeneralPath();

    // If there is no layoutmanager or there is one but the layout has not
    // been initialised, by default, let us route edges as straight lines.
    if (layoutmanager == null || (layoutmanager != null && !layoutmanager.isInitialized())) {

      fromvertexBounds = visualVertexA.getBounds();
      tovertexBounds = visualVertexB.getBounds();

      // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous
      // path will be redrawn as well.
      drawPath.reset();

      // Start the line from the center of the vEdgertex
      drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY());
      drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY());
    } else {
      // Let the layout manager determine how the edge will be routed.
      layoutmanager.routeEdge(g2d, vEdge);
    }

    // Draw the line
    g2d.setColor(vEdge.getOutlinecolor());
    g2d.draw(drawPath);

    // Draw the edge label
    this.paintText(vEdge, g2d);
  }
Exemplo n.º 3
0
  /**
   * Adds the specified {@link VisualVertex} to the Grid.
   *
   * @param visualVertex The VisualVertex to add
   * @return <code>true</code> if the VisualVertex was added successfully to this Grid, <code>false
   *     </code> otherwise
   */
  boolean addVisualVertexToGrid(VisualVertex visualVertex) {
    int positionX = visualVertex.getGridPoint().getPositionX();
    int positionY = visualVertex.getGridPoint().getPositionY();

    // Early negative return if specified GridPoint is invalid
    if (!Validation.isValidGridPoint(
        visualVertex.getGridPoint(), this.horizontalGridPoints, this.verticalGridPoints)) {
      return false;
    }

    // Get VisualVertex at specified GridPoint
    VisualVertex visualVertexAtGridPoint = this.grid[positionX][positionY];

    // Return false if GridPoint is not empty
    if (visualVertexAtGridPoint != null) {
      return false;
    }

    // Add VisualVertex

    this.grid[positionX][positionY] = visualVertex;

    return true;
  }