/** Execution of the command */ @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { View view = getView(); List<Edge> sourceList = ViewUtil.getSourceConnections(view); List<Edge> targetList = ViewUtil.getTargetConnections(view); for (Edge edge : sourceList) { IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor(); if (anchor != null) { anchor.setId(getNewIdStr(anchor)); } } for (Edge edge : targetList) { IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor(); if (anchor != null) { anchor.setId(getNewIdStr(anchor)); } } return CommandResult.newOKCommandResult(); }
/** * Used inside the getSizeDeltaToFitAnchors operation. It's goal is to modify a SizeDelta in order * to keep fitting an anchor within the figureBounds * * @param anchor The anchor whose position will be kept * @param sizeDelta * @param preserveAxis * @param figureBounds */ protected static void modifySizeDeltaToFitAnchor( IdentityAnchor anchor, Dimension sizeDelta, int preserveAxis, Rectangle figureBounds) { if (anchor == null) { return; } PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(anchor.getId()); int margin = 6; if (preserveAxis == PRESERVE_Y || preserveAxis == PRESERVE_XY) { int anchorYPos = (int) Math.round(figureBounds.height * pp.preciseY); int newHeight = figureBounds.height + sizeDelta.height; if (anchorYPos + margin > newHeight) { sizeDelta.height = (anchorYPos - figureBounds.height) + margin; } } if (preserveAxis == PRESERVE_X || preserveAxis == PRESERVE_XY) { int anchorXPos = (int) Math.round(figureBounds.width * pp.preciseX); int newWidth = figureBounds.width + sizeDelta.width; if (anchorXPos + margin > newWidth) { sizeDelta.width = (anchorXPos - figureBounds.width) + margin; } } }
/** * Returns the new anchor's position to preserve it's position after * * @param anchor * @return the new IdStr */ protected String getNewIdStr(IdentityAnchor anchor) { Dimension sizeDelta = getSizeDelta(); Rectangle figureBounds = getFigureBounds(); PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(anchor.getId()); if (getPreserveAxis() == PRESERVE_Y || getPreserveAxis() == PRESERVE_XY) { int anchorYPos = (int) Math.round(figureBounds.height * pp.preciseY); pp.preciseY = (double) anchorYPos / (figureBounds.height + sizeDelta.height); // If the resize direction is NORTH, the location of the figure move, but the anchor stay // visually at the same location if (PositionConstants.NORTH == resizeDirection || PositionConstants.NORTH_EAST == resizeDirection || PositionConstants.NORTH_WEST == resizeDirection) { pp.preciseY = pp.preciseY + ((double) sizeDelta.height / (figureBounds.height + sizeDelta.height)); } if (pp.preciseY > 1.0) { pp.preciseY = 1.0; } else if (pp.preciseY < 0.0) { pp.preciseY = 0.0; } } if (getPreserveAxis() == PRESERVE_X || getPreserveAxis() == PRESERVE_XY) { int anchorXPos = (int) Math.round(figureBounds.width * pp.preciseX); pp.preciseX = (double) anchorXPos / (figureBounds.width + sizeDelta.width); // If the resize direction is WEST, the location of the figure move, but the anchor stay // visually at the same location if (PositionConstants.WEST == resizeDirection || PositionConstants.NORTH_WEST == resizeDirection || PositionConstants.SOUTH_WEST == resizeDirection) { pp.preciseX = pp.preciseX + ((double) sizeDelta.width / (figureBounds.width + sizeDelta.width)); } if (pp.preciseX > 1.0) { pp.preciseX = 1.0; } else if (pp.preciseX < 0.0) { pp.preciseX = 0.0; } } String idStr = (new BaseSlidableAnchor(null, pp)).getTerminal(); return idStr; }