コード例 #1
0
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);
    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
コード例 #2
0
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);

    // Only enable horizontal dragging on lifelines(except lifelines that are result of a create
    // message).
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364688
    if (this.getHost() instanceof LifelineEditPart) {
      LifelineEditPart lifelineEP = (LifelineEditPart) this.getHost();
      if (!SequenceUtil.isCreateMessageEndLifeline(lifelineEP)) {
        request.getMoveDelta().y = 0;
      }
    }

    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
コード例 #3
0
 // @unused
 public static Request getNewSourceFeedbackRequest(Request request, ShapeNodeEditPart editPart) {
   if (request instanceof ChangeBoundsRequest) {
     ChangeBoundsRequest currRequest = (ChangeBoundsRequest) request;
     Dimension oldDelta = currRequest.getSizeDelta();
     Dimension newDelta =
         getSizeDeltaToFitAnchors(editPart, oldDelta, PreserveAnchorsPositionCommand.PRESERVE_Y);
     // Information for creating a new ChangeBoundsRequest has been taken
     // from org.eclipse.gef.editpolicies.ResizableEditPolicy
     ChangeBoundsRequest newRequest = new ChangeBoundsRequest();
     newRequest.setMoveDelta(currRequest.getMoveDelta());
     newRequest.setSizeDelta(newDelta);
     newRequest.setLocation(currRequest.getLocation());
     newRequest.setExtendedData(currRequest.getExtendedData());
     newRequest.setResizeDirection(currRequest.getResizeDirection());
     newRequest.setType(currRequest.getType());
     return newRequest;
   } else {
     return request;
   }
 }
コード例 #4
0
 /**
  * Shows or updates feedback for a change bounds request. The request is updated by the way so
  * that the shape stays a square.
  *
  * @param request the request
  */
 @Override
 protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
   // adapt the request for a square resize
   Point move = request.getMoveDelta();
   Dimension delta = request.getSizeDelta();
   int dH = delta.height;
   int dW = delta.width;
   int signum = 0;
   if (dH <= 0 && dW <= 0) {
     signum = -1;
   } else {
     signum = 1;
   }
   int positiveResize = Math.max(dH, dW);
   if (positiveResize <= 0) {
     if (dH == 0) {
       positiveResize = -dW;
     } else if (dW == 0) {
       positiveResize = -dH;
     } else {
       positiveResize = Math.min(-dH, -dW);
     }
   }
   int newDH = signum * positiveResize;
   int newDW = newDH;
   int dir = request.getResizeDirection();
   // adjust new position if impacted by resizing
   if ((dir & PositionConstants.NORTH) > 0) {
     move.y += dH - newDH;
   }
   if ((dir & PositionConstants.WEST) > 0) {
     move.x += dW - newDW;
   }
   request.setMoveDelta(move);
   delta.height = newDH;
   delta.width = newDW;
   super.showChangeBoundsFeedback(request);
 }
コード例 #5
0
  /**
   * This method can be overridden by clients to customize the snapping behavior.
   *
   * @param request the <code>ChangeBoundsRequest</code> from which the move delta can be extracted
   *     and updated
   * @since 3.4
   */
  protected void snapPoint(ChangeBoundsRequest request) {
    Point moveDelta = request.getMoveDelta();
    SnapToHelper snapToHelper =
        (SnapToHelper) getConnectionEditPart().getAdapter(SnapToHelper.class);

    Rectangle rect = new Rectangle(originalLocation.x, originalLocation.y, 1, 1);
    if (sourceRectangle == null) {
      sourceRectangle = new PrecisionRectangle(rect);
    }

    if (snapToHelper != null && request.isSnapToEnabled()) {
      PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
      baseRect.translate(moveDelta);

      PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
      snapToHelper.snapPoint(
          request,
          PositionConstants.HORIZONTAL | PositionConstants.VERTICAL,
          new PrecisionRectangle[] {baseRect},
          preciseDelta);
      request.setMoveDelta(preciseDelta);
    }
  }
  private Collection<ChangeBoundsRequest> getConstrainedRegionRequests(
      ChangeBoundsRequest request) {
    Collection<ChangeBoundsRequest> constrainedRequests = Lists.newArrayList();

    RequestQuery query = new RequestQuery(request);
    Dimension sizeDelta = request.getSizeDelta().getCopy();
    Point moveDelta = request.getMoveDelta().getCopy();

    List<AbstractDiagramElementContainerEditPart> regionToResize = getRegionParts();
    int stackDirection = getStackDirection();
    // Handle first and last regions.
    Object resizePropagator = request.getExtendedData().get(REGION_RESIZE_PROPAGATOR);
    if (query.isResizeFromTop() && stackDirection == PositionConstants.NORTH_SOUTH
        || query.isResizeFromLeft() && stackDirection == PositionConstants.EAST_WEST) {
      Option<AbstractDiagramElementContainerEditPart> firstRegionPart = getFirstRegionPart();
      if (firstRegionPart.some()
          && (!request.isConstrainedResize() || resizePropagator != firstRegionPart.get())) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(firstRegionPart.get());
        req.setSizeDelta(sizeDelta.getCopy());
        constrainedRequests.add(req);
      }
      // shift all other regions.
      regionToResize.remove(firstRegionPart.get());
      if (!regionToResize.isEmpty()
          && (!request.isConstrainedResize() || !regionToResize.contains(resizePropagator))) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));

        if (stackDirection == PositionConstants.NORTH_SOUTH) {
          req.setSizeDelta(new Dimension(sizeDelta.width, 0));
          req.setMoveDelta(new Point(0, -moveDelta.y));
        } else if (stackDirection == PositionConstants.EAST_WEST) {
          req.setSizeDelta(new Dimension(0, sizeDelta.height));
          req.setMoveDelta(new Point(-moveDelta.x, 0));
        }
        constrainedRequests.add(req);
        regionToResize.clear();
      }
    } else if (query.isResizeFromBottom() && stackDirection == PositionConstants.NORTH_SOUTH
        || query.isResizeFromRight() && stackDirection == PositionConstants.EAST_WEST) {
      // Resize the last region.
      Option<AbstractDiagramElementContainerEditPart> lastRegionPart = getLastRegionPart();
      if (lastRegionPart.some()
          && (!request.isConstrainedResize() || resizePropagator != lastRegionPart.get())) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(lastRegionPart.get());
        req.setSizeDelta(sizeDelta.getCopy());
        constrainedRequests.add(req);
        regionToResize.remove(lastRegionPart.get());
      }
    }

    // Handle horizontal resize for vstacks and vertical resize for hstacks.
    if (request.isConstrainedResize() && resizePropagator != null) {
      regionToResize.remove(resizePropagator);
    }
    if (!regionToResize.isEmpty()) {
      if (stackDirection == PositionConstants.NORTH_SOUTH
          && (query.isResizeFromLeft() || query.isResizeFromRight())
          && sizeDelta.width != 0) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));
        req.setSizeDelta(new Dimension(sizeDelta.width, 0));
        constrainedRequests.add(req);
      } else if (stackDirection == PositionConstants.EAST_WEST
          && (query.isResizeFromTop() || query.isResizeFromBottom())
          && sizeDelta.height != 0) {
        ChangeBoundsRequest req = initConstrainedRequest(request);
        req.setEditParts(Lists.newArrayList(regionToResize));
        req.setSizeDelta(new Dimension(0, sizeDelta.height));
        constrainedRequests.add(req);
      }
    }

    return constrainedRequests;
  }