001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.undo;
020:
021: import javax.swing.undo.CannotRedoException;
022: import javax.swing.undo.CannotUndoException;
023: import javax.swing.undo.UndoableEdit;
024:
025: import com.jeta.forms.gui.form.FormComponent;
026: import com.jeta.forms.gui.form.GridView;
027: import com.jeta.swingbuilder.gui.commands.FormUndoableEdit;
028:
029: /**
030: * This class acts as a front end to a FormUndoableEdit. It behaves in exactly
031: * the same way as the delegate however, we add the concept of a locked state.
032: * Since we share edit objects between opened editors, we can put the locked
033: * flag in the delegate.
034: *
035: * We need to lock an edit when we are editing a form in two different editors.
036: * This can happen if the form is nested. If the undo managers for the editors
037: * get out of sync (which can easily happen) then we need to lock the edits that
038: * are out of sync.
039: *
040: * @author Jeff Tassin
041: */
042: public class UndoableEditProxy extends FormUndoableEdit {
043: /**
044: * Flag that indicates if this edit has been locked. This means it cannot be
045: * redone/undone regardless of the canRedo/canUndo result of the delegate
046: */
047: private boolean m_locked;
048:
049: /**
050: * The delegate we are wrapping
051: */
052: private FormUndoableEdit m_delegate;
053:
054: /**
055: * ctor
056: */
057: public UndoableEditProxy(FormUndoableEdit delegate) {
058: super (delegate.getForm());
059: assert (!(delegate instanceof UndoableEditProxy));
060: m_delegate = delegate;
061: }
062:
063: /**
064: * UndoableEdit implementation
065: */
066: public boolean canRedo() {
067: if (m_locked)
068: return false;
069: else
070: return m_delegate.canRedo();
071: }
072:
073: /**
074: * UndoableEdit implementation
075: */
076: public boolean canUndo() {
077: if (m_locked)
078: return false;
079: else
080: return m_delegate.canUndo();
081: }
082:
083: public FormUndoableEdit getDelegate() {
084: return m_delegate;
085: }
086:
087: /**
088: * @return the form associated with this edit.
089: */
090: public FormComponent getForm() {
091: return m_delegate.getForm();
092: }
093:
094: /**
095: * @return the id of form associated with this edit.
096: */
097: public String getFormId() {
098: return m_delegate.getFormId();
099: }
100:
101: /**
102: * @return the child view associated with this form.
103: */
104: public GridView getView() {
105: return m_delegate.getView();
106: }
107:
108: /**
109: * Locks this edit so that it cannot be undone/redone.
110: */
111: public void lock(boolean lock) {
112: m_locked = lock;
113: }
114:
115: public void die() {
116: m_delegate.die();
117: }
118:
119: public void undo() throws CannotUndoException {
120: m_delegate.undo();
121: }
122:
123: public void redo() throws CannotRedoException {
124: m_delegate.redo();
125: }
126:
127: public boolean addEdit(UndoableEdit anEdit) {
128: return m_delegate.addEdit(anEdit);
129: }
130:
131: public boolean replaceEdit(UndoableEdit anEdit) {
132: return m_delegate.replaceEdit(anEdit);
133: }
134:
135: public boolean isSignificant() {
136: return m_delegate.isSignificant();
137: }
138:
139: public String toString() {
140: return m_delegate.toString();
141: }
142: }
|