@Override public UndoRedoAction skew( SVGHandle handle, Set<Element> elementsSet, Point2D centerPoint, double skewFactor, boolean isHorizontal) { Element element = elementsSet.iterator().next(); // getting the skew affine transform AffineTransform actionTransform = ShapeToolkit.getSkewAffineTransform(handle, element, centerPoint, skewFactor, isHorizontal); return applyTransform(handle, element, actionTransform, skewUndoRedoLabel); }
/** * computes the new coordinates of the element according to the transform a returns an undo/redo * action * * @param handle a svg handle * @param element the element that will be transformed * @param transform the transform to apply * @param actionUndoRedoLabel the action undo/redo label * @return an undo/redo action */ protected UndoRedoAction applyTransform( final SVGHandle handle, final Element element, AffineTransform transform, String actionUndoRedoLabel) { // getting the initial transform final AffineTransform initialTransform = handle.getSvgElementsManager().getTransform(element); // getting the new transform final AffineTransform newTransform = new AffineTransform(initialTransform); newTransform.preConcatenate(transform); // setting the new x and y attributes for the elements Runnable executeRunnable = new Runnable() { @Override public void run() { handle.getSvgElementsManager().setTransform(element, newTransform); } }; // the undo runnable Runnable undoRunnable = new Runnable() { @Override public void run() { handle.getSvgElementsManager().setTransform(element, initialTransform); } }; // executing the action and creating the undo/redo action HashSet<Element> elements = new HashSet<Element>(); elements.add(element); UndoRedoAction undoRedoAction = ShapeToolkit.getUndoRedoAction( actionUndoRedoLabel, executeRunnable, undoRunnable, elements); return undoRedoAction; }
@Override public UndoRedoAction validateAction( SVGHandle handle, int level, Set<Element> elementSet, SelectionItem item, Point2D firstPoint, Point2D lastPoint) { // the undo/redo action that will be returned UndoRedoAction undoRedoAction = null; // getting the element that will undergo the action Element element = elementSet.iterator().next(); // executing the accurate action switch (level) { case 0: // getting the resize transform AffineTransform resizeTransform = getResizeTransform(handle, element, item, firstPoint, lastPoint); // executing the resize action undoRedoAction = resize(handle, elementSet, resizeTransform); break; case 1: if (item.getType() != SelectionItem.CENTER) { // getting the center point Point2D centerPoint = getRotationSkewCenterPoint(handle, element); if (item.getType() == SelectionItem.NORTH_WEST || item.getType() == SelectionItem.NORTH_EAST || item.getType() == SelectionItem.SOUTH_EAST || item.getType() == SelectionItem.SOUTH_WEST) { // getting the angle for the rotation double angle = ShapeToolkit.getRotationAngle(centerPoint, firstPoint, lastPoint); // executing the rotation action undoRedoAction = rotate(handle, elementSet, centerPoint, angle); } else { // getting the skew factor and whether it's horizontal // or not boolean isHorizontal = (item.getType() == SelectionItem.NORTH || item.getType() == SelectionItem.SOUTH); double skewFactor = 0; if (isHorizontal) { skewFactor = lastPoint.getX() - firstPoint.getX(); } else { skewFactor = lastPoint.getY() - firstPoint.getY(); } // executing the skew action undoRedoAction = skew(handle, elementSet, centerPoint, skewFactor, isHorizontal); } rotationSkewSelectionItemCenterPoint = null; } else { rotationSkewCenterPoint = rotationSkewSelectionItemCenterPoint; rotationSkewSelectionItemCenterPoint = null; } break; } return undoRedoAction; }