Author: bobtarling
Date: 2007-09-02 15:13:15-0700
New Revision: 13481
Added:
trunk/src_new/org/argouml/kernel/AbstractCommand.java (contents, props changed)
trunk/src_new/org/argouml/kernel/AbstractUndoableCommand.java (contents, props changed)
trunk/src_new/org/argouml/kernel/Command.java (contents, props changed)
trunk/src_new/org/argouml/kernel/UndoManager.java (contents, props changed)
trunk/src_new/org/argouml/kernel/UndoableCommand.java (contents, props changed)
trunk/src_new/org/argouml/ui/ActionRedo.java (contents, props changed)
trunk/src_new/org/argouml/ui/ActionUndo.java (contents, props changed)
trunk/src_new/org/argouml/ui/UndoableAction.java (contents, props changed)
trunk/src_new/org/argouml/uml/diagram/DiagramUndoManager.java (contents, props changed)
Removed:
trunk/src_new/org/argouml/kernel/UndoEnabler.java
Modified:
trunk/src_new/org/argouml/kernel/Project.java
trunk/src_new/org/argouml/kernel/ProjectImpl.java
trunk/src_new/org/argouml/kernel/ProjectManager.java
trunk/src_new/org/argouml/ui/ProjectActions.java
trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java
trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java
Log:
Initial move of undo from GEF to ArgoUML - with wrapping of GEF mementos in ArgoUML Commands
Added: trunk/src_new/org/argouml/kernel/AbstractCommand.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/AbstractCommand.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/kernel/AbstractCommand.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,63 @@
+// $Id$
+// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.kernel;
+
+/**
+ * The base class of all mementos. Any undoable methods should create a
+ * concrete instance that will undo (and possibly redo) that method.
+ * @author Bob Tarling
+ */
+public abstract class AbstractCommand implements Command {
+ /**
+ * Set by the undo framework to flag the first memento of a chain of
+ * mementos that represent a single user interaction with the application.
+ */
+ private boolean startChain;
+
+ /**
+ * Determine if this is the start of a chain of mementos
+ * @return true if this is the start of a memento chain
+ */
+ protected boolean isStartChain() {
+ return startChain;
+ }
+
+ /**
+ * Flag a memento as being the start of a user interaction
+ */
+ void startChain() {
+ startChain = true;
+ }
+
+ /**
+ *
+ * @see org.argouml.kernel.Command#execute()
+ */
+ public abstract void execute();
+
+ public String toString() {
+ return (isStartChain() ? "*" : " ") + this.getClass().getName();
+ }
+}
Added: trunk/src_new/org/argouml/kernel/AbstractUndoableCommand.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/AbstractUndoableCommand.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/kernel/AbstractUndoableCommand.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,35 @@
+// $Id$
+// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.kernel;
+
+/**
+ * The base class for any actions that can be undone by ActionUndo.
+ * @author Bob Tarling
+ */
+public abstract class AbstractUndoableCommand
+ extends AbstractCommand implements UndoableCommand {
+
+ public abstract void undo();
+}
Added: trunk/src_new/org/argouml/kernel/Command.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/Command.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/kernel/Command.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,38 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.kernel;
+
+/**
+ * An executable Commnd
+ *
+ * @author Bob
+ */
+public interface Command {
+
+ /**
+ * To be implemented on the concrete memento to redo an instruction
+ */
+ public abstract void execute();
+}
\ No newline at end of file
Modified: trunk/src_new/org/argouml/kernel/Project.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/Project.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/kernel/Project.java&p2=trunk/src_new/org/argouml/kernel/Project.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/kernel/Project.java (original)
+++ trunk/src_new/org/argouml/kernel/Project.java 2007-09-02 15:13:15-0700
@@ -613,4 +613,5 @@
*/
public ProjectSettings getProjectSettings();
+ public UndoManager getUndoManager();
}
\ No newline at end of file
Modified: trunk/src_new/org/argouml/kernel/ProjectImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/ProjectImpl.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/kernel/ProjectImpl.java&p2=trunk/src_new/org/argouml/kernel/ProjectImpl.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/kernel/ProjectImpl.java (original)
+++ trunk/src_new/org/argouml/kernel/ProjectImpl.java 2007-09-02 15:13:15-0700
@@ -61,8 +61,6 @@
import org.argouml.uml.diagram.DiagramFactory;
import org.argouml.uml.diagram.ProjectMemberDiagram;
import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.undo.Memento;
-import org.tigris.gef.undo.UndoManager;
/**
* The ProjectImpl is a data structure that represents the designer's
@@ -150,6 +148,8 @@
private Collection trashcan = new ArrayList();
+ private UndoManager undoManager = UndoManager.getInstance();
+
/**
* Constructor.
*
@@ -426,8 +426,8 @@
public void setAuthorname(final String s) {
final String oldAuthorName = authorname;
- Memento memento = new Memento() {
- public void redo() {
+ AbstractCommand memento = new AbstractCommand() {
+ public void execute() {
authorname = s;
}
@@ -435,10 +435,8 @@
authorname = oldAuthorName;
}
};
- if (UndoManager.getInstance().isGenerateMementos()) {
- UndoManager.getInstance().addMemento(memento);
- }
- memento.redo();
+ undoManager.addMemento(memento);
+ memento.execute();
setSaveEnabled(true);
}
@@ -450,8 +448,8 @@
public void setAuthoremail(final String s) {
final String oldAuthorEmail = authoremail;
- Memento memento = new Memento() {
- public void redo() {
+ AbstractCommand memento = new AbstractCommand() {
+ public void execute() {
authoremail = s;
}
@@ -459,10 +457,8 @@
authoremail = oldAuthorEmail;
}
};
- if (UndoManager.getInstance().isGenerateMementos()) {
- UndoManager.getInstance().addMemento(memento);
- }
- memento.redo();
+ undoManager.addMemento(memento);
+ memento.execute();
setSaveEnabled(true);
}
@@ -484,8 +480,8 @@
public void setDescription(final String s) {
final String oldDescription = description;
- Memento memento = new Memento() {
- public void redo() {
+ AbstractCommand memento = new AbstractCommand() {
+ public void execute() {
description = s;
}
@@ -493,10 +489,8 @@
description = oldDescription;
}
};
- if (UndoManager.getInstance().isGenerateMementos()) {
- UndoManager.getInstance().addMemento(memento);
- }
- memento.redo();
+ undoManager.addMemento(memento);
+ memento.execute();
setSaveEnabled(true);
}
@@ -1161,4 +1155,7 @@
return projectSettings;
}
+ public UndoManager getUndoManager() {
+ return undoManager;
+ }
}
Modified: trunk/src_new/org/argouml/kernel/ProjectManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/ProjectManager.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/kernel/ProjectManager.java&p2=trunk/src_new/org/argouml/kernel/ProjectManager.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/kernel/ProjectManager.java (original)
+++ trunk/src_new/org/argouml/kernel/ProjectManager.java 2007-09-02 15:13:15-0700
@@ -34,17 +34,15 @@
import org.apache.log4j.Logger;
import org.argouml.cognitive.Designer;
import org.argouml.i18n.Translator;
-import org.argouml.model.MementoCreationObserver;
+import org.argouml.model.ModelCommandCreationObserver;
import org.argouml.model.Model;
-import org.argouml.model.ModelMemento;
+import org.argouml.model.ModelCommand;
import org.argouml.uml.cognitive.ProjectMemberTodoList;
import org.argouml.uml.diagram.ArgoDiagram;
import org.argouml.uml.diagram.DiagramFactory;
import org.argouml.uml.diagram.static_structure.ui.UMLClassDiagram;
import org.argouml.uml.diagram.use_case.ui.UMLUseCaseDiagram;
import org.tigris.gef.graph.MutableGraphSupport;
-import org.tigris.gef.undo.Memento;
-import org.tigris.gef.undo.UndoManager;
/**
* This class manages the projects loaded in argouml,
@@ -64,7 +62,7 @@
* @author [email protected]
* @stereotype singleton
*/
-public final class ProjectManager implements MementoCreationObserver {
+public final class ProjectManager implements ModelCommandCreationObserver {
/**
* The name of the property that defines the current project.
@@ -134,7 +132,7 @@
*/
private ProjectManager() {
super();
- Model.setMementoCreationObserver(this);
+ Model.setModelCommandCreationObserver(this);
}
/**
@@ -262,10 +260,6 @@
oldProject, currentProject);
creatingCurrentProject = false;
- UndoManager.getInstance().empty();
- if (!UndoEnabler.isEnabled()) {
- UndoManager.getInstance().setUndoMax(0);
- }
Model.getPump().startPumpingEvents();
if (saveAction != null) {
@@ -345,19 +339,19 @@
* We must add this to the UndoManager.
*
* @param memento the memento.
- * @see org.argouml.model.MementoCreationObserver#mementoCreated(org.argouml.model.ModelMemento)
+ * @see org.argouml.model.ModelCommandCreationObserver#modelCommandCreated(org.argouml.model.ModelCommand)
*/
- public void mementoCreated(final ModelMemento memento) {
+ public void modelCommandCreated(final ModelCommand memento) {
if (saveAction != null) {
saveAction.setEnabled(true);
}
- Memento wrappedMemento = new Memento() {
- private ModelMemento modelMemento = memento;
+ AbstractCommand wrappedMemento = new AbstractUndoableCommand() {
+ private ModelCommand modelMemento = memento;
public void undo() {
modelMemento.undo();
}
- public void redo() {
- modelMemento.redo();
+ public void execute() {
+ modelMemento.execute();
}
public void dispose() {
modelMemento.dispose();
@@ -369,6 +363,6 @@
}
};
- UndoManager.getInstance().addMemento(wrappedMemento);
+ getCurrentProject().getUndoManager().addMemento(wrappedMemento);
}
}
Removed: trunk/src_new/org/argouml/kernel/UndoEnabler.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/UndoEnabler.java?view=auto&rev=13480
Added: trunk/src_new/org/argouml/kernel/UndoManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/UndoManager.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/kernel/UndoManager.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,258 @@
+// $Id$
+// Copyright (c) 1996-2006 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.kernel;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Manages a stacks of Commands to undo and redo.
+ * UndoManager is only temporarily singleton until changes are made to GEF.
+ * @author Bob Tarling
+ */
+public class UndoManager {
+
+ private int undoMax = 100;
+ private int undoChainCount = 0;
+ private int redoChainCount = 0;
+
+ private Collection<PropertyChangeListener> listeners =
+ new ArrayList<PropertyChangeListener>();
+
+ private boolean newChain = true;
+
+ // TODO: A UndoChainStack may produce some reasuable code for
+ // the undoStack and the redoStack/
+ private List<Command> undoStack = new ArrayList<Command>();
+ private List<Command> redoStack = new ArrayList<Command>();
+
+ private static final UndoManager INSTANCE = new UndoManager();
+
+ private UndoManager() {
+ super();
+ }
+
+ /**
+ * Get the UndoManager singleton instance.
+ * UndoManager is only temporarily singleton until changes are made to GEF.
+ * @return the singleton undo manager
+ */
+ public static UndoManager getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Adds a new command to the undo stack.
+ * @param command the command.
+ */
+ public void addMemento(Command command) {
+ if (undoMax == 0) {
+ return;
+ }
+ // Flag the command as to whether it is first in a chain
+ if (newChain) {
+ ((AbstractCommand) command).startChain();
+ // If the command is the first then consider that
+ // there is a new chain being received and clear
+ // the redos
+ emptyRedo();
+ incrementUndoChainCount();
+ newChain = false;
+ if (undoChainCount > undoMax) {
+ // TODO The undo stack is full, dispose
+ // of the oldest chain.
+ }
+ }
+ undoStack.add(command);
+ }
+
+ /**
+ * Set the maximum number of command chains the stack can hold.
+ * @param max the maximum chain count
+ */
+ public void setUndoMax(int max) {
+ undoMax = max;
+ }
+
+ /**
+ * Undo the most recent chain of mementos received by the undo stack
+ */
+ public void undo() {
+ AbstractUndoableCommand command;
+ boolean startChain = false;
+ do {
+ command = (AbstractUndoableCommand) pop(undoStack);
+ startChain = command.isStartChain();
+ undo(command);
+ } while (!startChain);
+ decrementUndoChainCount();
+ incrementRedoChainCount();
+ }
+
+ /**
+ * Undo a single command
+ * @param command the command to undo
+ */
+ protected void undo(UndoableCommand command) {
+ command.undo();
+ redoStack.add(command);
+ }
+
+ /**
+ * Redo the most recent chain of mementos received by the undo stack
+ */
+ public void redo() {
+ do {
+ Command command = pop(redoStack);
+ redo(command);
+ } while(redoStack.size() > 0
+ && !((AbstractCommand)
+ (redoStack.get(redoStack.size() - 1))).isStartChain());
+ incrementUndoChainCount();
+ decrementRedoChainCount();
+ }
+
+ /**
+ * Undo a single command
+ * @param command the command to redo
+ */
+ protected void redo(Command command) {
+ command.execute();
+ undoStack.add(command);
+ }
+
+ /**
+ * Empty all undoable items from the UndoManager
+ */
+ public void emptyUndo() {
+ if (undoChainCount > 0) {
+ emptyStack(undoStack);
+ undoChainCount = 0;
+ fireCanUndo();
+ }
+ }
+
+ /**
+ * Empty all redoable items from the UndoManager
+ */
+ private void emptyRedo() {
+ if (redoChainCount > 0) {
+ emptyStack(redoStack);
+ redoChainCount = 0;
+ fireCanRedo();
+ }
+ }
+
+ /**
+ * Empty all undoable and redoable items from the UndoManager
+ */
+ public void empty() {
+ emptyUndo();
+ emptyRedo();
+ }
+
+ /**
+ * Instructs the UndoManager that the sequence of mementos recieved up
+ * until the next call to newChain all represent one chain of mementos
+ * (ie one undoable user interaction).
+ */
+ public void startChain() {
+ newChain = true;
+ }
+
+ /**
+ * Empty a list stack disposing of all mementos.
+ * @param list the list of mementos
+ */
+ private void emptyStack(List<Command> list) {
+ // Lets only introduce dispose if we find it's required
+ // for (int i = 0; i < list.size(); ++i) {
+ // list.get(i).dispose();
+ // }
+ list.clear();
+ }
+
+ private Command pop(List<Command> stack) {
+ return stack.remove(stack.size() - 1);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ listeners.add(listener);
+ }
+
+ private void fireCanUndo() {
+ Iterator i = listeners.iterator();
+ while (i.hasNext()) {
+ PropertyChangeListener listener = (PropertyChangeListener) i.next();
+ listener.propertyChange(
+ new PropertyChangeEvent(
+ this,
+ "canUndo",
+ "",
+ Boolean.toString(undoChainCount > 0)));
+ }
+ }
+
+ private void fireCanRedo() {
+ Iterator i = listeners.iterator();
+ while (i.hasNext()) {
+ PropertyChangeListener listener = (PropertyChangeListener) i.next();
+ listener.propertyChange(
+ new PropertyChangeEvent(
+ this,
+ "canRedo",
+ "",
+ Boolean.toString(redoChainCount > 0)));
+ }
+ }
+
+ private void incrementUndoChainCount() {
+ if (++undoChainCount == 1) {
+ fireCanUndo();
+ }
+ }
+
+ private void decrementUndoChainCount() {
+ if (--undoChainCount == 0) {
+ fireCanUndo();
+ }
+ }
+
+ private void incrementRedoChainCount() {
+ if (++redoChainCount == 1) {
+ fireCanRedo();
+ }
+ }
+
+ private void decrementRedoChainCount() {
+ if (--redoChainCount == 0) {
+ fireCanRedo();
+ }
+ }
+}
Added: trunk/src_new/org/argouml/kernel/UndoableCommand.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/kernel/UndoableCommand.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/kernel/UndoableCommand.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,38 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.kernel;
+
+/**
+ * An executable Command
+ *
+ * @author Bob
+ */
+public interface UndoableCommand extends Command {
+
+ /**
+ * To be implemented on the concrete memento to redo an instruction
+ */
+ abstract void undo();
+}
\ No newline at end of file
Added: trunk/src_new/org/argouml/ui/ActionRedo.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/ActionRedo.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/ui/ActionRedo.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,86 @@
+// $Id$
+// Copyright (c) 1996-99 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+
+/**
+ * An action to redo from the undo stack.
+ *
+ * @author [email protected]
+ */
+public class ActionRedo extends AbstractAction
+ implements PropertyChangeListener {
+
+ private static final long serialVersionUID = 3921952827170089931L;
+
+ /**
+ * Construct the redo action with a display name
+ * @param name the name to display for this action
+ */
+ public ActionRedo(String name) {
+ super(name);
+ final Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().addPropertyChangeListener(this);
+ setEnabled(false);
+ }
+
+ /**
+ * Construct the redo action with a display name and icon.
+ * @param name the name to display for this action
+ * @param icon the icon to display for this action
+ */
+ public ActionRedo(String name, Icon icon) {
+ super(name, icon);
+ final Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().addPropertyChangeListener(this);
+ setEnabled(false);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ final Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().redo();
+ }
+
+ /**
+ * Listens for property change events to determine when redo changes
+ * availability
+ * @param event the event
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if ("canRedo".equals(event.getPropertyName())) {
+ setEnabled ("true".equals(event.getNewValue()));
+ }
+ }
+}
Added: trunk/src_new/org/argouml/ui/ActionUndo.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/ActionUndo.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/ui/ActionUndo.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,86 @@
+// $Id$
+// Copyright (c) 1996-99 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+
+/**
+ * An action to undo from the undo stack.
+ *
+ * @author Bob Tarling
+ */
+public class ActionUndo extends AbstractAction
+ implements PropertyChangeListener {
+
+ private static final long serialVersionUID = 6544646406482242086L;
+
+ /**
+ * Construct the undo action with a display name
+ * @param name the name for this action
+ */
+ public ActionUndo(String name) {
+ super(name);
+ Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().addPropertyChangeListener(this);
+ setEnabled(false);
+ }
+
+ /**
+ * Construct the undo action with a display name and icon.
+ * @param name the name for this action
+ * @param icon the icon to diaply for this action
+ */
+ public ActionUndo(String name, Icon icon) {
+ super(name, icon);
+ Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().addPropertyChangeListener(this);
+ setEnabled(false);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().undo();
+ }
+
+ /**
+ * Listens for property change events to determine when undo changes
+ * availability
+ * @param event the event
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent event) {
+ if ("canUndo".equals(event.getPropertyName())) {
+ setEnabled ("true".equals(event.getNewValue()));
+ }
+ }
+}
Modified: trunk/src_new/org/argouml/ui/ProjectActions.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/ProjectActions.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/ui/ProjectActions.java&p2=trunk/src_new/org/argouml/ui/ProjectActions.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/ui/ProjectActions.java (original)
+++ trunk/src_new/org/argouml/ui/ProjectActions.java 2007-09-02 15:13:15-0700
@@ -43,8 +43,6 @@
import org.tigris.gef.base.Globals;
import org.tigris.gef.graph.GraphModel;
import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.undo.RedoAction;
-import org.tigris.gef.undo.UndoAction;
/**
* Class to manage Project related actions which need to be (or historically
@@ -67,13 +65,13 @@
/**
* The action to undo the last user interaction.
*/
- private final UndoAction undoAction =
- new UndoAction(Translator.localize("action.undo"));
+ private final ActionUndo undoAction =
+ new ActionUndo(Translator.localize("action.undo"));
/**
* The action to redo the last undone action.
*/
private final AbstractAction redoAction =
- new RedoAction(Translator.localize("action.redo"));
+ new ActionRedo(Translator.localize("action.redo"));
/**
* Singleton retrieval method for the projectbrowser. Lazely instantiates
Added: trunk/src_new/org/argouml/ui/UndoableAction.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/UndoableAction.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/ui/UndoableAction.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,68 @@
+// $Id$
+// Copyright (c) 1996-99 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.ui;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+
+/**
+ * A base class for all undoable Actions. Any action that acts as the start
+ * of a user interaction should extend this and call actionPerformed before
+ * calling any mutable undoable methods.
+ */
+public abstract class UndoableAction extends AbstractAction {
+
+
+ /*
+ * @see javax.swing.AbstractAction.AbstractAction()
+ */
+ public UndoableAction() {
+ super();
+ }
+
+ /*
+ * @see javax.swing.AbstractAction.AbstractAction(java.lang.String)
+ */
+ public UndoableAction(String name) {
+ super(name);
+ }
+
+ /*
+ * @see javax.swing.AbstractAction.AbstractAction(
+ * java.lang.String, javax.swing.Icon)
+ */
+ public UndoableAction(String name, Icon icon) {
+ super(name, icon);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ final Project p = ProjectManager.getManager().getCurrentProject();
+ p.getUndoManager().startChain();
+ }
+}
Modified: trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java&p2=trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java (original)
+++ trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java 2007-09-02 15:13:15-0700
@@ -44,7 +44,6 @@
import org.argouml.application.helpers.ResourceLoaderWrapper;
import org.argouml.i18n.Translator;
-import org.argouml.kernel.UndoEnabler;
import org.argouml.model.CommandStack;
import org.argouml.model.Model;
import org.argouml.ui.ActionExportXMI;
@@ -399,17 +398,15 @@
.getUndoAction());
setMnemonic(undoItem, "Undo");
ShortcutMgr.assignAccelerator(undoItem, ShortcutMgr.ACTION_UNDO);
- undoItem.setVisible(UndoEnabler.isEnabled());
+ undoItem.setEnabled(true);
JMenuItem redoItem = edit.add(ProjectActions.getInstance()
.getRedoAction());
setMnemonic(redoItem, "Redo");
ShortcutMgr.assignAccelerator(redoItem, ShortcutMgr.ACTION_REDO);
- redoItem.setVisible(UndoEnabler.isEnabled());
+ redoItem.setEnabled(true);
- if (UndoEnabler.isEnabled()) {
- edit.addSeparator();
- }
+ edit.addSeparator();
select = new JMenu(menuLocalize("Select"));
setMnemonic(select, "Select");
Modified: trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java?view=diff&rev=13481&p1=trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java&p2=trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java&r1=13480&r2=13481
==============================================================================
--- trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java (original)
+++ trunk/src_new/org/argouml/uml/diagram/ArgoDiagramImpl.java 2007-09-02 15:13:15-0700
@@ -50,6 +50,7 @@
import org.tigris.gef.presentation.FigEdge;
import org.tigris.gef.presentation.FigGroup;
import org.tigris.gef.presentation.FigNode;
+import org.tigris.gef.undo.UndoManager;
/**
* This class represents all Diagrams within ArgoUML.
@@ -89,6 +90,12 @@
*/
public ArgoDiagramImpl() {
super();
+ if (!(UndoManager.getInstance() instanceof DiagramUndoManager)) {
+ UndoManager.setInstance(new DiagramUndoManager());
+ LOG.info("Setting Diagram undo manager");
+ } else {
+ LOG.info("Diagram undo manager already set");
+ }
// really dirty hack to remove unwanted listeners
getLayer().getGraphModel().removeGraphEventListener(getLayer());
}
@@ -108,6 +115,12 @@
public ArgoDiagramImpl(String diagramName) {
// next line patch to issue 596 (hopefully)
super(diagramName);
+ if (!(UndoManager.getInstance() instanceof DiagramUndoManager)) {
+ UndoManager.setInstance(new DiagramUndoManager());
+ LOG.info("Setting Diagram undo manager");
+ } else {
+ LOG.info("Diagram undo manager already set");
+ }
try {
setName(diagramName);
} catch (PropertyVetoException pve) { }
Added: trunk/src_new/org/argouml/uml/diagram/DiagramUndoManager.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/uml/diagram/DiagramUndoManager.java?view=auto&rev=13481
==============================================================================
--- (empty file)
+++ trunk/src_new/org/argouml/uml/diagram/DiagramUndoManager.java 2007-09-02 15:13:15-0700
@@ -0,0 +1,101 @@
+// $Id$
+// Copyright (c) 2007 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.uml.diagram;
+
+import java.beans.PropertyChangeListener;
+
+import org.apache.log4j.Logger;
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+import org.tigris.gef.undo.Memento;
+import org.tigris.gef.undo.UndoManager;
+
+/**
+ * This class is a temporary wrapper around the GEF UndoManager.
+ * This will be changed when GEF is modified to fire mementos and
+ * provide an observer interface for ArgoUML to receive them.
+ *
+ * @author Bob Tarling
+ */
+public class DiagramUndoManager extends UndoManager {
+
+ private static final Logger LOG = Logger.getLogger(UndoManager.class);
+
+ private boolean startChain;
+
+ /**
+ * Called when a new user interaction starts
+ * @see org.tigris.gef.undo.UndoManager#startChain()
+ */
+ @Override
+ public void startChain() {
+ startChain = true;
+ }
+
+ /**
+ * @param memento the GEF memento
+ * @see org.tigris.gef.undo.UndoManager#addMemento(org.tigris.gef.undo.Memento)
+ */
+ @Override
+ public void addMemento(final Memento memento) {
+ LOG.info("Diagram memento added " + memento);
+
+ Project p = ProjectManager.getManager().getCurrentProject();
+ org.argouml.kernel.UndoManager undo = p.getUndoManager();
+
+ if (startChain) {
+ undo.startChain();
+ }
+
+ undo.addMemento(new DiagramCommand(memento));
+
+ startChain = false;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ LOG.info("Adding property listener " + listener);
+ super.addPropertyChangeListener(listener);
+ }
+
+
+ private class DiagramCommand extends org.argouml.kernel.AbstractUndoableCommand {
+
+ private final Memento memento;
+
+ DiagramCommand(final Memento memento) {
+ this.memento = memento;
+ }
+
+ @Override
+ public void execute() {
+ memento.redo();
+ }
+
+ @Override
+ public void undo() {
+ memento.undo();
+ }
+ }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.