2c2 < * @(#)RadiusHandle.java 5.2 --- > * @(#)RadiusHandle.java 3a4,9 > * Project: JHotdraw - a GUI framework for technical drawings > * http://www.jhotdraw.org > * http://jhotdraw.sourceforge.net > * Copyright: © by the original author(s) and all contributors > * License: Lesser GNU Public License (LGPL) > * http://www.opensource.org/licenses/lgpl-license.html 8d13 < import java.awt.*; 11a17,19 > import CH.ifa.draw.util.Undoable; > import CH.ifa.draw.util.UndoableAdapter; > import java.awt.*; 14a23,24 > * > * @version <$CURRENT_VERSION$> 18,19d27 < private Point fRadius; < private RoundRectangleFigure fOwner; 24,30c32,34 < fOwner = owner; < } < < public void invokeStart(int x, int y, DrawingView view) { < fRadius = fOwner.getArc(); < fRadius.x = fRadius.x/2; < fRadius.y = fRadius.y/2; --- > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(owner())); > ((RadiusHandle.UndoActivity)getUndoActivity()).setOldRadius(owner.getArc()); 36,39c40,54 < Rectangle r = fOwner.displayBox(); < int rx = Geom.range(0, r.width, 2*(fRadius.x + dx)); < int ry = Geom.range(0, r.height, 2*(fRadius.y + dy)); < fOwner.setArc(rx, ry); --- > RoundRectangleFigure owner = (RoundRectangleFigure)owner(); > Rectangle r = owner.displayBox(); > Point originalRadius = ((RadiusHandle.UndoActivity)getUndoActivity()).getOldRadius(); > int rx = Geom.range(0, r.width, 2*(originalRadius.x/2 + dx)); > int ry = Geom.range(0, r.height, 2*(originalRadius.y/2 + dy)); > owner.setArc(rx, ry); > } > > public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { > Point currentRadius = ((RoundRectangleFigure)owner()).getArc(); > Point originalRadius = ((RadiusHandle.UndoActivity)getUndoActivity()).getOldRadius(); > // there has been no change so there is nothing to undo > if ((currentRadius.x == originalRadius.x) && (currentRadius.y == originalRadius.y)) { > setUndoActivity(null); > } 43,44c58,60 < Point radius = fOwner.getArc(); < Rectangle r = fOwner.displayBox(); --- > RoundRectangleFigure owner = (RoundRectangleFigure)owner(); > Point radius = owner.getArc(); > Rectangle r = owner.displayBox(); 56a73,104 > > /** > * Factory method for undo activity. To be overriden by subclasses. > */ > protected Undoable createUndoActivity() { > return new RadiusHandle.UndoActivity(); > } > > public static class UndoActivity extends UndoableAdapter { > private Point myOldRadius; > > public UndoActivity() { > super(null); > setUndoable(true); > setRedoable(true); > } > > public boolean undo() { > if (!super.undo()) { > return false; > } > > return resetRadius(); > } > > public boolean redo() { > // do not call execute directly as the selection might has changed > if (!isRedoable()) { > return false; > } > > return resetRadius(); 58a107,127 > protected boolean resetRadius() { > FigureEnumeration fe = getAffectedFigures(); > if (!fe.hasMoreElements()) { > return false; > } > RoundRectangleFigure currentFigure = (RoundRectangleFigure)fe.nextFigure(); > Point figureRadius = currentFigure.getArc(); > currentFigure.setArc(getOldRadius().x, getOldRadius().y); > setOldRadius(figureRadius); > return true; > } > > protected void setOldRadius(Point newOldRadius) { > myOldRadius = newOldRadius; > } > > public Point getOldRadius() { > return myOldRadius; > } > } > }