2,2c2,2 < * @(#)GroupCommand.java 5.2 --- > * @(#)GroupCommand.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 7a16,17 > import CH.ifa.draw.util.UndoableAdapter; > import CH.ifa.draw.util.Undoable; 8,8c18,18 < import java.util.*; --- > import java.util.*; 9,9d18 < import CH.ifa.draw.util.Command; 16a24,25 > * > * @version <$CURRENT_VERSION$> 18,18c27,27 < public class GroupCommand extends Command { --- > public class GroupCommand extends AbstractCommand { 19,20d27 < < private DrawingView fView; 28,28c35,35 < super(name); --- > super(name, view); 29,29d35 < fView = view; 32a39,43 > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures(view().selectionElements()); > ((GroupCommand.UndoActivity)getUndoActivity()).groupFigures(); > view().checkDamage(); > } 33,37d38 < Vector selected = fView.selectionZOrdered(); < Drawing drawing = fView.drawing(); < if (selected.size() > 0) { < fView.clearSelection(); < drawing.orphanAll(selected); 39,41d44 < GroupFigure group = new GroupFigure(); < group.addAll(selected); < fView.addToSelection(drawing.add(group)); 42a48,53 > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > return new GroupCommand.UndoActivity(view()); 43,43d47 < fView.checkDamage(); 45a56,60 > public static class UndoActivity extends UndoableAdapter { > public UndoActivity(DrawingView newDrawingView) { > super(newDrawingView); > setUndoable(true); > setRedoable(true); 46,46c45,45 < public boolean isExecutable() { --- > public boolean isExecutable() { 47,47c46,46 < return fView.selectionCount() > 0; --- > return view().selectionCount() > 1; 49a63,91 > public boolean undo() { > if (!super.undo()) { > return false; > } > > getDrawingView().clearSelection(); > > // duplicate before we orphan affected figures > // FigureEnumeration fe = StandardFigureSelection.duplicateFigures( > // getAffectedFigures(), getAffectedFiguresCount()); > > // orphan group figure(s) > // getDrawingView().drawing().removeAll(getAffectedFigures()); > getDrawingView().drawing().orphanAll(getAffectedFigures()); > > // create a new vector with the grouped figures as elements > Vector affectedFigures = new Vector(); > > FigureEnumeration fe =getAffectedFigures(); > while (fe.hasMoreElements()) { > Figure currentFigure = fe.nextFigure(); > // add contained figures > getDrawingView().drawing().addAll(currentFigure.figures()); > getDrawingView().addToSelectionAll(currentFigure.figures()); > > FigureEnumeration groupedFigures = currentFigure.figures(); > while (groupedFigures.hasMoreElements()) { > affectedFigures.addElement(groupedFigures.nextFigure()); > } 51a94,126 > setAffectedFigures(new FigureEnumerator(affectedFigures)); > > return true; > } > > public boolean redo() { > // do not call execute directly as the selection might has changed > if (isRedoable()) { > groupFigures(); > return true; > } > > return false; > } > > public void groupFigures() { > getDrawingView().drawing().orphanAll(getAffectedFigures()); > getDrawingView().clearSelection(); > > // add new group figure instead > GroupFigure group = new GroupFigure(); > group.addAll(getAffectedFigures()); > > Figure figure = getDrawingView().drawing().add(group); > getDrawingView().addToSelection(figure); > > // create a new vector with the new group figure as element > Vector affectedFigures = new Vector(); > affectedFigures.addElement(figure); > setAffectedFigures(new FigureEnumerator(affectedFigures)); > } > } > }