2,2c2,2 < * @(#)PolyLineHandle.java 5.2 --- > * @(#)PolyLineHandle.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 8,8d13 < import java.awt.*; 10a16,19 > import CH.ifa.draw.standard.SingleFigureEnumerator; > import CH.ifa.draw.util.Undoable; > import CH.ifa.draw.util.UndoableAdapter; > import java.awt.*; 13a23,24 > * > * @version <$CURRENT_VERSION$> 18,18d28 < private Point fAnchor; 31a42,44 > setUndoActivity(createUndoActivity(fIndex)); > getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(owner())); > ((PolyLineHandle.UndoActivity)getUndoActivity()).setOldPoint(new Point(x,y)); 32,32d41 < fAnchor = new Point(x, y); 35a48,48 > int fIndex = ((PolyLineHandle.UndoActivity)getUndoActivity()).getPointIndex(); 38a52,57 > public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { > if ((x == anchorX) && (y == anchorY)) { > setUndoActivity(null); > } > } > 41a61,85 > > /** > * Factory method for undo activity. To be overriden by subclasses. > */ > protected Undoable createUndoActivity(int newPointIndex) { > return new PolyLineHandle.UndoActivity(newPointIndex); > } > > public static class UndoActivity extends UndoableAdapter { > private Point myOldPoint; > private int myPointIndex; > > public UndoActivity(int newPointIndex) { > super(null); > setUndoable(true); > setRedoable(true); > setPointIndex(newPointIndex); > } > > public boolean undo() { > if (!super.undo()) { > return false; > } > > return movePointToOldLocation(); 43a88,92 > public boolean redo() { > // do not call execute directly as the selection might has changed > if (!isRedoable()) { > return false; > } 44a94,126 > return movePointToOldLocation(); > } > > protected boolean movePointToOldLocation() { > FigureEnumeration fe = getAffectedFigures(); > if (!fe.hasMoreElements()) { > return false; > } > > PolyLineFigure figure = (PolyLineFigure)fe.nextFigure(); > Point backupPoint = figure.pointAt(getPointIndex()); > figure.setPointAt(getOldPoint(), getPointIndex()); > setOldPoint(backupPoint); > return true; > } > > public void setOldPoint(Point newOldPoint) { > myOldPoint = newOldPoint; > } > > public Point getOldPoint() { > return myOldPoint; > } > > public void setPointIndex(int newPointIndex) { > myPointIndex = newPointIndex; > } > > public int getPointIndex() { > return myPointIndex; > } > } > }