2,2c2,2 < * @(#)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 7a17,18 > import CH.ifa.draw.util.Undoable; > import CH.ifa.draw.util.UndoableAdapter; 8,8c19,19 < import java.awt.*; --- > import java.awt.*; 14a23,24 > * > * @version <$CURRENT_VERSION$> 18,19d27 < private Point fRadius; < private RoundRectangleFigure fOwner; 23a32,34 > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(owner())); > ((RadiusHandle.UndoActivity)getUndoActivity()).setOldRadius(owner.getArc()); 24,30d31 < fOwner = owner; < } < < public void invokeStart(int x, int y, DrawingView view) { < fRadius = fOwner.getArc(); < fRadius.x = fRadius.x/2; < fRadius.y = fRadius.y/2; 35a40,40 > RoundRectangleFigure owner = (RoundRectangleFigure)owner(); 36a42,43 > Point originalRadius = ((RadiusHandle.UndoActivity)getUndoActivity()).getOldRadius(); > int rx = Geom.range(0, r.width, 2*(originalRadius.x/2 + dx)); 36,36c41,41 < Rectangle r = fOwner.displayBox(); --- > Rectangle r = owner.displayBox(); 37,37d41 < int rx = Geom.range(0, r.width, 2*(fRadius.x + dx)); 38,38c44,44 < int ry = Geom.range(0, r.height, 2*(fRadius.y + dy)); --- > int ry = Geom.range(0, r.height, 2*(originalRadius.y/2 + dy)); 39,39c45,45 < fOwner.setArc(rx, ry); --- > owner.setArc(rx, ry); 39a46,54 > } > > 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); > } 42a58,59 > RoundRectangleFigure owner = (RoundRectangleFigure)owner(); > Point radius = owner.getArc(); 43,43d57 < Point radius = fOwner.getArc(); 44,44c60,60 < Rectangle r = fOwner.displayBox(); --- > 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; > } > } > }