From: <sh...@us...> - 2009-02-23 13:22:53
|
Revision: 14227 http://cdk.svn.sourceforge.net/cdk/?rev=14227&view=rev Author: shk3 Date: 2009-02-23 13:22:48 +0000 (Mon, 23 Feb 2009) Log Message: ----------- more actions undoable Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/RemoveModule.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/ChangeChargeEdit.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/IUndoRedoFactory.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/MoveAtomEdit.java Added Paths: ----------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/RemoveAtomsAndBondsEdit.java Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/RemoveModule.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/RemoveModule.java 2009-02-23 12:16:15 UTC (rev 14226) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/RemoveModule.java 2009-02-23 13:22:48 UTC (rev 14227) @@ -1,6 +1,7 @@ /* $Revision: 7636 $ $Author: nielsout $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $ * * Copyright (C) 2007 Niels Out <nie...@us...> + * Copyright (C) 2008 Stefan Kuhn (undo/redo) * * Contact: cdk...@li... * @@ -24,10 +25,15 @@ */ package org.openscience.cdk.controller; +import java.util.Iterator; + import javax.vecmath.Point2d; +import org.openscience.cdk.controller.undoredo.IUndoRedoable; import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.tools.manipulator.ChemModelManipulator; /** @@ -68,13 +74,28 @@ } private void removeAtom(IAtom atom) { + IAtomContainer undAtomContainer = atom.getBuilder().newAtomContainer(); + undAtomContainer.addAtom(atom); + Iterator<IBond> it=ChemModelManipulator.getRelevantAtomContainer(chemModelRelay.getIChemModel(),atom).getConnectedBondsList(atom).iterator(); + while(it.hasNext()) + undAtomContainer.addBond(it.next()); chemModelRelay.removeAtom(atom); chemModelRelay.updateView(); + if(chemModelRelay.getUndoRedoFactory()!=null && chemModelRelay.getUndoRedoHandler()!=null){ + IUndoRedoable undoredo = chemModelRelay.getUndoRedoFactory().getRemoveAtomsAndBondsEdit(chemModelRelay.getIChemModel(), undAtomContainer,this.getDrawModeString()); + chemModelRelay.getUndoRedoHandler().postEdit(undoredo); + } } private void removeBond(IBond bond) { + IAtomContainer undAtomContainer = bond.getBuilder().newAtomContainer(); chemModelRelay.removeBond(bond); + undAtomContainer.addBond(bond); chemModelRelay.updateView(); + if(chemModelRelay.getUndoRedoFactory()!=null && chemModelRelay.getUndoRedoHandler()!=null){ + IUndoRedoable undoredo = chemModelRelay.getUndoRedoFactory().getRemoveAtomsAndBondsEdit(chemModelRelay.getIChemModel(), undAtomContainer,this.getDrawModeString()); + chemModelRelay.getUndoRedoHandler().postEdit(undoredo); + } } public String getDrawModeString() { Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/ChangeChargeEdit.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/ChangeChargeEdit.java 2009-02-23 12:16:15 UTC (rev 14226) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/ChangeChargeEdit.java 2009-02-23 13:22:48 UTC (rev 14227) @@ -29,6 +29,7 @@ * Undo/Redo Edit class for the ChangeCharge actions in AbstarctController2D, * containing the methods for undoing and redoing the regarding changes * + * @cdk.module control * @cdk.svnrev $Revision: 10979 $ */ public class ChangeChargeEdit implements IUndoRedoable { Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/IUndoRedoFactory.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/IUndoRedoFactory.java 2009-02-23 12:16:15 UTC (rev 14226) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/IUndoRedoFactory.java 2009-02-23 13:22:48 UTC (rev 14227) @@ -52,4 +52,5 @@ public IUndoRedoable getChangeAtomSymbolEdit(IAtom atom, String formerSymbol, String symbol, String type); public IUndoRedoable getChangeChargeEdit(IAtom atomInRange, int formerCharge, int newCharge, String type); public IUndoRedoable getMoveAtomEdit(IAtomContainer undoRedoContainer, Vector2d offset, String type); + public IUndoRedoable getRemoveAtomsAndBondsEdit(IChemModel chemModel, IAtomContainer undoRedoContainer, String type); } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/MoveAtomEdit.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/MoveAtomEdit.java 2009-02-23 12:16:15 UTC (rev 14226) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/MoveAtomEdit.java 2009-02-23 13:22:48 UTC (rev 14227) @@ -29,7 +29,7 @@ import org.openscience.cdk.interfaces.IAtomContainer; /** - * @cdk.module controlold + * @cdk.module control * @cdk.svnrev $Revision: 10979 $ */ public class MoveAtomEdit implements IUndoRedoable { Added: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/RemoveAtomsAndBondsEdit.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/RemoveAtomsAndBondsEdit.java (rev 0) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/undoredo/RemoveAtomsAndBondsEdit.java 2009-02-23 13:22:48 UTC (rev 14227) @@ -0,0 +1,107 @@ +/* $RCSfile$ + * $Author: egonw $ + * $Date: 2008-05-12 07:29:49 +0100 (Mon, 12 May 2008) $ + * $Revision: 10979 $ + * + * Copyright (C) 2005-2007 The Chemistry Development Kit (CDK) project + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.controller.undoredo; + +import java.util.Iterator; + +import org.openscience.cdk.graph.ConnectivityChecker; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemModel; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.interfaces.IMoleculeSet; +import org.openscience.cdk.tools.manipulator.ChemModelManipulator; + +/** + * @cdk.module control + * @cdk.svnrev $Revision: 10979 $ + */ +public class RemoveAtomsAndBondsEdit implements IUndoRedoable { + + private static final long serialVersionUID = -143712173063846054L; + + private String type; + + private IAtomContainer undoRedoContainer; + + private IChemModel chemModel; + + private IAtomContainer container; + + public RemoveAtomsAndBondsEdit(IChemModel chemModel, + IAtomContainer undoRedoContainer, String type) { + this.chemModel = chemModel; + this.undoRedoContainer = undoRedoContainer; + this.container = chemModel.getBuilder().newAtomContainer(); + Iterator<IAtomContainer> containers = ChemModelManipulator.getAllAtomContainers(chemModel).iterator(); + while (containers.hasNext()) { + container.add((IAtomContainer)containers.next()); + } + this.type = type; + } + + public void redo() { + for (int i = 0; i < undoRedoContainer.getBondCount(); i++) { + IBond bond = undoRedoContainer.getBond(i); + container.removeBond(bond); + } + for (int i = 0; i < undoRedoContainer.getAtomCount(); i++) { + IAtom atom = undoRedoContainer.getAtom(i); + container.removeAtom(atom); + } + IMolecule molecule = container.getBuilder().newMolecule(container); + IMoleculeSet moleculeSet = ConnectivityChecker + .partitionIntoMolecules(molecule); + chemModel.setMoleculeSet(moleculeSet); + } + + public void undo() { + for (int i = 0; i < undoRedoContainer.getBondCount(); i++) { + IBond bond = undoRedoContainer.getBond(i); + container.addBond(bond); + } + for (int i = 0; i < undoRedoContainer.getAtomCount(); i++) { + IAtom atom = undoRedoContainer.getAtom(i); + container.addAtom(atom); + } + IMolecule molecule = container.getBuilder().newMolecule(container); + IMoleculeSet moleculeSet = ConnectivityChecker + .partitionIntoMolecules(molecule); + chemModel.setMoleculeSet(moleculeSet); + } + + public boolean canRedo() { + return true; + } + + public boolean canUndo() { + return true; + } + + public String getPresentationName() { + return type; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |