コード例 #1
0
  /**
   * Shows an insertion line if there is one or more current children.
   *
   * @see LayoutEditPolicy#showLayoutTargetFeedback(Request)
   */
  protected void showLayoutTargetFeedback(Request request) {
    if (getHost().getChildren().size() == 0) return;
    Polyline fb = getLineFeedback();
    Transposer transposer = new Transposer();
    transposer.setEnabled(!isLayoutHorizontal());

    int epIndex = getFeedbackIndexFor(request);
    Rectangle r = null;
    if (epIndex == -1) {
      epIndex = getHost().getChildren().size() - 1;
      EditPart editPart = (EditPart) getHost().getChildren().get(epIndex);
      r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart));
    } else {
      EditPart editPart = (EditPart) getHost().getChildren().get(epIndex);
      r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart));
      Point p = transposer.t(getLocationFromRequest(request));
      if (p.x > r.x + (r.width / 2)) {
        editPart = (EditPart) getHost().getChildren().get(epIndex);
        r = transposer.t(getAbsoluteBounds((GraphicalEditPart) editPart));
      }
    }
    int x = r.x;
    Point p1 = new Point(x, r.y - 4);
    p1 = transposer.t(p1);
    fb.translateToRelative(p1);
    Point p2 = new Point(x, r.y + r.height + 4);
    p2 = transposer.t(p2);
    fb.translateToRelative(p2);
    fb.setPoint(p1, 0);
    fb.setPoint(p2, 1);
  }
コード例 #2
0
  /**
   * @param request the Request
   * @return the index for the insertion reference
   */
  protected int getFeedbackIndexFor(Request request) {
    List children = getHost().getChildren();
    if (children.isEmpty()) return -1;

    Transposer transposer = new Transposer();
    transposer.setEnabled(!isLayoutHorizontal());

    Point p = transposer.t(getLocationFromRequest(request));
    if (children.size() == 0 || children.size() == 1) {
      return -1;
    }
    int[] y = new int[children.size()];
    for (int i = 0; i < children.size(); i++) {
      EditPart child = (EditPart) children.get(i);
      Rectangle rect = transposer.t(getAbsoluteBounds(((GraphicalEditPart) child)));
      y[i] = rect.y;
    }
    int height = 5;
    if (y[0] + height >= p.y) {
      // add to first item;
      return 0;
    }
    if (y[y.length - 1] - height <= p.y) {
      // add to end item;
      return y.length - 1;
    }

    int candidateIndex = -1;
    for (int i = 0; i < y.length; i++) {
      if (i + 1 == y.length) {
        break;
      }
      if (p.y >= y[i] && p.y <= y[i + 1]) {
        candidateIndex = i;
        break;
      }
    }

    return candidateIndex;
  }