2,2c2,2 < * @(#)DragTracker.java 5.2 --- > * @(#)DragTracker.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 11,11c14,14 < import CH.ifa.draw.framework.*; --- > import CH.ifa.draw.framework.*; 11a15,16 > import CH.ifa.draw.util.UndoableAdapter; > import CH.ifa.draw.util.Undoable; 17a26,27 > * > * @version <$CURRENT_VERSION$> 37a48,48 > } 38,38c49,49 < } else if (!view().selection().contains(fAnchorFigure)) { --- > else if (!view().isFigureSelected(fAnchorFigure)) { 48a60,60 > FigureEnumeration figures = getUndoActivity().getAffectedFigures(); 49,49d59 < FigureEnumeration figures = view().selectionElements(); 50,50c61,61 < while (figures.hasMoreElements()) --- > while (figures.hasMoreElements()) { 52a64,64 > } 55a68,147 > > public void activate() { > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures(view().selectionElements()); > } > > public void deactivate() { > if (fMoved) { > ((DragTracker.UndoActivity)getUndoActivity()).setBackupPoint(new Point(fLastX, fLastY)); > } > else { > setUndoActivity(null); > } > } > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > return new DragTracker.UndoActivity(view(), new Point(fLastX, fLastY)); > } > > public static class UndoActivity extends UndoableAdapter { > private Point myOriginalPoint; > private Point myBackupPoint; > > public UndoActivity(DrawingView newDrawingView, Point newOriginalPoint) { > super(newDrawingView); > setOriginalPoint(newOriginalPoint); > setUndoable(true); > setRedoable(true); > } > > /* > * Undo the activity > * @return true if the activity could be undone, false otherwise > */ > public boolean undo() { > if (!super.undo()) { > return false; > } > moveAffectedFigures(getBackupPoint(), getOriginalPoint()); > return true; > } > > /* > * Redo the activity > * @return true if the activity could be redone, false otherwise > */ > public boolean redo() { > if (!super.redo()) { > return false; > } > moveAffectedFigures(getOriginalPoint(), getBackupPoint()); > return true; > } > public void setBackupPoint(Point newBackupPoint) { > myBackupPoint = newBackupPoint; > } > > public Point getBackupPoint() { > return myBackupPoint; > } > > public void setOriginalPoint(Point newOriginalPoint) { > myOriginalPoint = newOriginalPoint; > } > > public Point getOriginalPoint() { > return myOriginalPoint; > } > > public void moveAffectedFigures(Point startPoint, Point endPoint) { > FigureEnumeration figures = getAffectedFigures(); > while (figures.hasMoreElements()) { > figures.nextFigure().moveBy(endPoint.x - startPoint.x, > endPoint.y - startPoint.y); > } > } > }