001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.model;
034:
035: import javax.swing.undo.AbstractUndoableEdit;
036: import javax.swing.undo.UndoableEdit;
037:
038: /**
039: * An action that can be rolled back. Similar to an UndoableEdit, but assumes
040: * that the action is yet to be executed, whereas an UndoableEdit assumes that
041: * the action has already been executed (i.e. it has a #redo method but not a
042: * #do method).
043: *
044: * @see javax.swing.undo.UndoableEdit
045: */
046: public abstract class UndoableCommand {
047: private String name;
048:
049: public UndoableCommand(String name) {
050: this .name = name;
051: }
052:
053: /** Releases resources. */
054: protected void dispose() {
055: }
056:
057: /**
058: * If there is an exception that leaves this UndoableCommand execution
059: * partially complete and non-unexecutable, be sure to call #reportIrreversibleChange()
060: * on the UndoableEditReceiver (which can be obtained from the LayerManager).
061: * @see UndoableEditReceiver#reportIrreversibleChange()
062: */
063: public abstract void execute();
064:
065: public abstract void unexecute();
066:
067: public UndoableEdit toUndoableEdit() {
068: return new AbstractUndoableEdit() {
069: public String getPresentationName() {
070: return name;
071: }
072:
073: public void redo() {
074: execute();
075: super .redo();
076: }
077:
078: public void die() {
079: dispose();
080: super .die();
081: }
082:
083: public void undo() {
084: super .undo();
085: unexecute();
086: }
087: };
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: public static final UndoableCommand DUMMY = new UndoableCommand(
095: "Dummy") {
096: public void execute() {
097: }
098:
099: public void unexecute() {
100: }
101: };
102:
103: }
|