Java Code Examples for org.eclipse.gef.requests.ChangeBoundsRequest#setConstrainedResize()
The following examples show how to use
org.eclipse.gef.requests.ChangeBoundsRequest#setConstrainedResize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FiguresHelper.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static void resizeActivitiesFigure(final IGraphicalEditPart parentEp, final String text) { final int lineNumber = text.length() / LINE_LENGTH; final ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); final int currentWidth = parentEp.getFigure().getSize().width; final int defaultWidth = parentEp.getFigure().getPreferredSize().width; final int withDeltaFromDefault = currentWidth - defaultWidth; final int currentHeight = parentEp.getFigure().getSize().height; final int defaultHeight = parentEp.getFigure().getPreferredSize().height; final int heightDeltaFromDefault = currentHeight - defaultHeight; req.setSizeDelta(new Dimension(20 * lineNumber - withDeltaFromDefault, 10 * lineNumber - heightDeltaFromDefault)); req.setConstrainedResize(true); req.setCenteredResize(true); req.setResizeDirection(PositionConstants.CENTER); req.setEditParts(parentEp); // avoid to perform request on element creation (figure have no size) if (currentWidth > 0 && currentHeight > 0 && req.getSizeDelta().width > 0 && req.getSizeDelta().height > 0) { final Command cmd = parentEp.getCommand(req); if (cmd != null) { parentEp.getDiagramEditDomain().getDiagramCommandStack().execute(cmd); } } }
Example 2
Source File: CustomResizeHandle.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override protected DragTracker createDragTracker() { return new ResizeTracker(getOwner(), cursorDirection){ @Override protected void updateSourceRequest() { ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest(); Dimension d = getDragMoveDelta(); Point location = new Point(getLocation()); Point moveDelta = new Point(0, 0); Dimension resizeDelta = new Dimension(0, 0); if (getOwner() != null) { if(isContrained){ request.setConstrainedResize(true); int origHeight = getOwner().getFigure().getBounds().height; int origWidth = getOwner().getFigure().getBounds().width; float ratio = 1; if (origWidth != 0 && origHeight != 0) ratio = ((float) origHeight / (float) origWidth); if (getResizeDirection() == PositionConstants.SOUTH_EAST) { if (d.height > (d.width * ratio)) d.width = (int) (d.height / ratio); else d.height = (int) (d.width * ratio); } else if (getResizeDirection() == PositionConstants.NORTH_WEST) { if (d.height < (d.width * ratio)) d.width = (int) (d.height / ratio); else d.height = (int) (d.width * ratio); } else if (getResizeDirection() == PositionConstants.NORTH_EAST) { if (-(d.height) > (d.width * ratio)) d.width = -(int) (d.height / ratio); else d.height = -(int) (d.width * ratio); } else if (getResizeDirection() == PositionConstants.SOUTH_WEST) { if (-(d.height) < (d.width * ratio)) d.width = -(int) (d.height / ratio); else d.height = -(int) (d.width * ratio); } } }else{ request.setConstrainedResize(false); } request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1)); if ((getResizeDirection() & PositionConstants.NORTH) != 0) { if (getCurrentInput().isControlKeyDown()) { resizeDelta.height -= d.height; } moveDelta.y += d.height; resizeDelta.height -= d.height; } if ((getResizeDirection() & PositionConstants.SOUTH) != 0) { if (getCurrentInput().isControlKeyDown()) { moveDelta.y -= d.height; resizeDelta.height += d.height; } resizeDelta.height += d.height; } if ((getResizeDirection() & PositionConstants.WEST) != 0) { if (getCurrentInput().isControlKeyDown()) { resizeDelta.width -= d.width; } moveDelta.x += d.width; resizeDelta.width -= d.width; } if ((getResizeDirection() & PositionConstants.EAST) != 0) { if (getCurrentInput().isControlKeyDown()) { moveDelta.x -= d.width; resizeDelta.width += d.width; } resizeDelta.width += d.width; } request.setMoveDelta(moveDelta); request.setSizeDelta(resizeDelta); request.setLocation(location); request.setEditParts(getOperationSet()); request.getExtendedData().clear(); } @Override protected List<IGraphicalEditPart> createOperationSet() { ArrayList<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>(); for (Object selection : getCurrentViewer().getSelectedEditParts()) { if (isResizable((IGraphicalEditPart)selection)) { res.add((IGraphicalEditPart)selection); } } return res; } }; }