示例#1
0
  // TODO: cache required
  protected int getEdgeIndex(EdgeItem e) {
    if (isIgnored(e)) {
      return -1;
    }

    NodeItem sourceItem = e.getSourceItem();
    NodeItem targetItem = e.getTargetItem();
    Iterator<EdgeItem> edges = sourceItem.edges();

    // number of equal edges = same target and source
    int equalEdges = 0;
    // number of nearequal edges = same nodes, but any order target and source
    int sameEdges = 0;
    int edgeIndex = 0;
    int row = e.getRow();
    while (edges.hasNext()) {
      EdgeItem edge = edges.next();
      int edgeRow = edge.getRow();
      if (isIgnored(edge)) {
        continue;
      }
      if (edge.getSourceItem() == sourceItem && edge.getTargetItem() == targetItem) {
        if (row == edgeRow) {
          edgeIndex = equalEdges;
        }
        equalEdges++;
        sameEdges++;
      } else if (edge.getSourceItem() == targetItem && edge.getTargetItem() == sourceItem) {
        sameEdges++;
      }
    }

    // draw the line straight if we found one edge
    if (lineForSingleEdge && edgeIndex == 0 && sameEdges == 1) {
      return -1;
    } else if (sameEdges > 1) {
      edgeIndex++;
    }

    return edgeIndex;
  }
示例#2
0
  /** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */
  @Override
  protected Shape getRawShape(VisualItem item) {
    EdgeItem e = (EdgeItem) item;
    VisualItem source = e.getSourceItem();
    VisualItem target = e.getTargetItem();

    int type = m_edgeType;
    int edgeIndex = -1;

    getAlignedPoint(m_tmpPoints[0], source.getBounds(), m_xAlign1, m_yAlign1);
    getAlignedPoint(m_tmpPoints[1], target.getBounds(), m_xAlign2, m_yAlign2);
    m_curWidth = (float) (m_width * getLineWidth(item));

    boolean curveCtrlPtsReady = false;
    Polygon arrowHead;
    // create the arrow head, if needed
    if (isDirected(e)
        && m_edgeArrow != Constants.EDGE_ARROW_NONE
        && (arrowHead = getArrowHead(e)) != null) {
      // get starting and ending edge endpoints
      boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD);
      Point2D start = null, end = null;
      start = m_tmpPoints[forward ? 0 : 1];
      end = m_tmpPoints[forward ? 1 : 0];
      // compute the intersection with the source/target bounding box
      VisualItem src = getSourceItem(e, forward);
      VisualItem dest = getTargetItem(e, forward);

      if (edgeBounded && !e.isAggregating()) {
        adjustEndingPoint(start, end, src, dest);
      } else if (GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints)
          > 0) {
        end.setLocation(m_isctPoints[0]);
      }

      // create the arrow head shape
      AffineTransform arrowTrans;
      if (multipleEdge) {
        edgeIndex = adjustEndingPointByMultipleEdge(e, start, end);
        if (lineForSingleEdge && edgeIndex < 0) {
          type = Constants.EDGE_TYPE_LINE;
          arrowTrans = getArrowTrans(start, end, m_curWidth);
        } else {
          getCurveControlPoints(
              edgeIndex, m_ctrlPoints, start.getX(), start.getY(), end.getX(), end.getY());
          curveCtrlPtsReady = true;
          arrowTrans = getArrowTrans(m_ctrlPoints[0], end, m_curWidth);
        }
      } else {
        arrowTrans = getArrowTrans(start, end, m_curWidth);
      }
      m_curArrow = m_tmpArrow.set(arrowHead, arrowTrans);

      // update the endpoints for the edge shape
      // need to bias this by arrow head size
      adjustLineEndByArrowHead(e, end);
      arrowTrans.transform(end, end);
    } else {
      m_curArrow = null;
      if (edgeBounded && !e.isAggregating()) {
        adjustEndingPoint(m_tmpPoints[0], m_tmpPoints[1], source, target);
      }
      if (multipleEdge) {
        edgeIndex = adjustEndingPointByMultipleEdge(e, m_tmpPoints[0], m_tmpPoints[1]);
        if (lineForSingleEdge && edgeIndex < 0) {
          type = Constants.EDGE_TYPE_LINE;
        } else {
          getCurveControlPoints(
              edgeIndex,
              m_ctrlPoints,
              m_tmpPoints[0].getX(),
              m_tmpPoints[0].getY(),
              m_tmpPoints[1].getX(),
              m_tmpPoints[1].getY());
          curveCtrlPtsReady = true;
        }
      }
    }

    // create the edge shape
    Shape shape = null;
    double sx = m_tmpPoints[0].getX();
    double sy = m_tmpPoints[0].getY();
    double ex = m_tmpPoints[1].getX();
    double ey = m_tmpPoints[1].getY();
    switch (type) {
      case Constants.EDGE_TYPE_LINE:
        m_line.setLine(sx, sy, ex, ey);
        shape = m_line;
        break;
      case Constants.EDGE_TYPE_CURVE:
        if (!curveCtrlPtsReady) {
          getCurveControlPoints(e, m_ctrlPoints, sx, sy, ex, ey);
        }
        m_quad.setCurve(sx, sy, m_ctrlPoints[0].getX(), m_ctrlPoints[0].getY(), ex, ey);
        shape = m_quad;
        break;
      default:
        throw new IllegalStateException("Unknown edge type");
    }

    // return the edge shape
    return shape;
  }
示例#3
0
 protected VisualItem getTargetItem(EdgeItem e, boolean forward) {
   VisualItem target = forward ? e.getTargetItem() : e.getSourceItem();
   return target;
 }