2,2c2,2 < * @(#)PasteCommand.java 5.2 --- > * @(#)PasteCommand.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,9d14 < import java.util.*; < import java.awt.*; 10a16,17 > import java.util.Enumeration; > import java.awt.*; 10,10c15,15 < import CH.ifa.draw.util.*; --- > import CH.ifa.draw.util.*; 14a21,21 > * 15a23,24 > * > * @version <$CURRENT_VERSION$> 30,30c39,39 < Point lastClick = fView.lastClick(); --- > Point lastClick = view().lastClick(); 32a42,44 > setUndoActivity(createUndoActivity()); > > if (view().selectionCount() <= 0) { 33,34d41 < Vector figures = (Vector)selection.getData(FigureSelection.TYPE); < if (figures.size() == 0) 35a46,46 > } 37,38d47 < Rectangle r = bounds(figures.elements()); < fView.clearSelection(); 39a48,52 > getUndoActivity().setAffectedFigures(view().selectionElements()); > Rectangle r = bounds(getUndoActivity().getAffectedFigures()); > view().clearSelection(); > > // get a new enumeration 39a56,56 > view().checkDamage(); 40,40c53,53 < insertFigures(figures, lastClick.x-r.x, lastClick.y-r.y); --- > FigureEnumeration fe = insertFigures(getUndoActivity().getAffectedFigures(), lastClick.x-r.x, lastClick.y-r.y); 40a54,54 > getUndoActivity().setAffectedFigures(fe); 41,41d53 < fView.checkDamage(); 47,47c62,62 < while (k.hasMoreElements()) --- > while (k.hasMoreElements()) { 48a64,64 > } 50a67,72 > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > return new PasteCommand.UndoActivity(view()); 52a75,81 > public static class UndoActivity extends UndoableAdapter { > > public UndoActivity(DrawingView newDrawingView) { > super(newDrawingView); > setUndoable(true); > setRedoable(true); > } 53a83,111 > public boolean undo() { > if (!super.undo()) { > return false; > } > > FigureEnumeration fe = getAffectedFigures(); > while (fe.hasMoreElements()) { > getDrawingView().drawing().orphan(fe.nextFigure()); > } > > getDrawingView().clearSelection(); > > return true; > } > > public boolean redo() { > // do not call execute directly as the selection might has changed > if (!isRedoable()) { > return false; > } > > getDrawingView().clearSelection(); > setAffectedFigures(getDrawingView().insertFigures( > getAffectedFigures(), 0, 0, false)); > > return true; > } > } > }