/* * @(#)DuplicateCommand.java * * Project: JHotdraw - a GUI framework for technical drawings * http://www.jhotdraw.org * http://jhotdraw.sourceforge.net * Copyright: (c) by the original author(s) and all contributors * License: Lesser GNU Public License (LGPL) * http://www.opensource.org/licenses/lgpl-license.html */ package org.jhotdraw.standard; import org.jhotdraw.framework.*; import org.jhotdraw.util.*; /** * Duplicate the selection and select the duplicates. * * @version <$CURRENT_VERSION$> */ public class DuplicateCommand extends FigureTransferCommand { /** * Constructs a duplicate command. * @param name the command name * @param newDrawingEditor the DrawingEditor which manages the views */ public DuplicateCommand(String name, DrawingEditor newDrawingEditor) { super(name, newDrawingEditor); } public void execute() { super.execute(); setUndoActivity(createUndoActivity()); FigureSelection selection = view().getFigureSelection(); // create duplicate figure(s) FigureEnumeration figures = (FigureEnumeration)selection.getData(StandardFigureSelection.TYPE); getUndoActivity().setAffectedFigures(figures); view().clearSelection(); getUndoActivity().setAffectedFigures( insertFigures(getUndoActivity().getAffectedFigures(), 10, 10)); view().checkDamage(); } protected boolean isExecutableWithView() { return view().selectionCount() > 0; } /** * Factory method for undo activity */ protected Undoable createUndoActivity() { return new PasteCommand.UndoActivity(view()); } }