1 | /* AbstractTableModel.java --
|
---|
2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
6 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA.
|
---|
20 |
|
---|
21 | Linking this library statically or dynamically with other modules is
|
---|
22 | making a combined work based on this library. Thus, the terms and
|
---|
23 | conditions of the GNU General Public License cover the whole
|
---|
24 | combination.
|
---|
25 |
|
---|
26 | As a special exception, the copyright holders of this library give you
|
---|
27 | permission to link this library with independent modules to produce an
|
---|
28 | executable, regardless of the license terms of these independent
|
---|
29 | modules, and to copy and distribute the resulting executable under
|
---|
30 | terms of your choice, provided that you also meet, for each linked
|
---|
31 | independent module, the terms and conditions of the license of that
|
---|
32 | module. An independent module is a module which is not derived from
|
---|
33 | or based on this library. If you modify this library, you may extend
|
---|
34 | this exception to your version of the library, but you are not
|
---|
35 | obligated to do so. If you do not wish to do so, delete this
|
---|
36 | exception statement from your version. */
|
---|
37 |
|
---|
38 | package javax.swing.undo;
|
---|
39 |
|
---|
40 | // Imports
|
---|
41 | import java.util.Vector;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * CompoundEdit
|
---|
45 | * @author Andrew Selkirk
|
---|
46 | */
|
---|
47 | public class CompoundEdit extends AbstractUndoableEdit {
|
---|
48 |
|
---|
49 | //-------------------------------------------------------------
|
---|
50 | // Variables --------------------------------------------------
|
---|
51 | //-------------------------------------------------------------
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * The collection of UndoableEdits undone/redone en
|
---|
55 | * masse by this CompoundEdit
|
---|
56 | */
|
---|
57 | protected Vector edits = new Vector();
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * TODO
|
---|
61 | */
|
---|
62 | private boolean inProgress = false;
|
---|
63 |
|
---|
64 |
|
---|
65 | //-------------------------------------------------------------
|
---|
66 | // Initialization ---------------------------------------------
|
---|
67 | //-------------------------------------------------------------
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Create new Compound Edit
|
---|
71 | */
|
---|
72 | public CompoundEdit() {
|
---|
73 | } // CompoundEdit()
|
---|
74 |
|
---|
75 |
|
---|
76 | //-------------------------------------------------------------
|
---|
77 | // Interface: UndoableEdit ------------------------------------
|
---|
78 | //-------------------------------------------------------------
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * addEdit
|
---|
82 | * @param anEdit TODO
|
---|
83 | * @returns TODO
|
---|
84 | */
|
---|
85 | public boolean addEdit(UndoableEdit anEdit) {
|
---|
86 |
|
---|
87 | // Variables
|
---|
88 | UndoableEdit lastEdit;
|
---|
89 |
|
---|
90 | if (inProgress == true) {
|
---|
91 |
|
---|
92 | // Get Last Edit
|
---|
93 | lastEdit = lastEdit();
|
---|
94 |
|
---|
95 | // Check for null
|
---|
96 | if (lastEdit != null) {
|
---|
97 |
|
---|
98 | if (lastEdit.addEdit(anEdit) == false) {
|
---|
99 | if (lastEdit.replaceEdit(anEdit) == false) {
|
---|
100 | edits.add(anEdit);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | } // if: lastEdit
|
---|
105 |
|
---|
106 | return true;
|
---|
107 |
|
---|
108 | } else {
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 | } // addEdit()
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * canRedo
|
---|
115 | * @returns TODO
|
---|
116 | */
|
---|
117 | public boolean canRedo() {
|
---|
118 | if (isInProgress() == true || super.canRedo() == false) {
|
---|
119 | return false;
|
---|
120 | }
|
---|
121 | return true;
|
---|
122 | } // canRedo()
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * canUndo
|
---|
126 | * @returns TODO
|
---|
127 | */
|
---|
128 | public boolean canUndo() {
|
---|
129 | if (isInProgress() == true || super.canUndo() == false) {
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 | return true;
|
---|
133 | } // canUndo()
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * die
|
---|
137 | */
|
---|
138 | public void die() {
|
---|
139 |
|
---|
140 | // Variables
|
---|
141 | int index;
|
---|
142 | UndoableEdit current;
|
---|
143 |
|
---|
144 | // Loop through all contained UndoableEdits
|
---|
145 | for (index = edits.size() - 1; index >= 0; index--) {
|
---|
146 | current = (UndoableEdit) edits.elementAt(index);
|
---|
147 | current.die();
|
---|
148 | } // for: index
|
---|
149 |
|
---|
150 | } // die()
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * end
|
---|
154 | */
|
---|
155 | public void end() {
|
---|
156 | inProgress = false;
|
---|
157 | } // end()
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * getPresentationName
|
---|
161 | * @returns TODO
|
---|
162 | */
|
---|
163 | public String getPresentationName() {
|
---|
164 | if (edits.size() == 0) {
|
---|
165 | return super.getPresentationName();
|
---|
166 | } else {
|
---|
167 | return lastEdit().getPresentationName();
|
---|
168 | }
|
---|
169 | } // getPresentationName()
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * getRedoPresentationName
|
---|
173 | * @returns TODO
|
---|
174 | */
|
---|
175 | public String getRedoPresentationName() {
|
---|
176 | if (edits.size() == 0) {
|
---|
177 | return super.getRedoPresentationName();
|
---|
178 | } else {
|
---|
179 | return lastEdit().getRedoPresentationName();
|
---|
180 | }
|
---|
181 | } // getRedoPresentationName()
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * getUndoPresentationName
|
---|
185 | * @returns TODO
|
---|
186 | */
|
---|
187 | public String getUndoPresentationName() {
|
---|
188 | if (edits.size() == 0) {
|
---|
189 | return super.getUndoPresentationName();
|
---|
190 | } else {
|
---|
191 | return lastEdit().getUndoPresentationName();
|
---|
192 | }
|
---|
193 | } // getUndoPresentationName()
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * isInProgress
|
---|
197 | * @returns TODO
|
---|
198 | */
|
---|
199 | public boolean isInProgress() {
|
---|
200 | return inProgress;
|
---|
201 | } // isInProgress()
|
---|
202 |
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * isSignigicant
|
---|
206 | * @returns TODO
|
---|
207 | */
|
---|
208 | public boolean isSignificant() {
|
---|
209 |
|
---|
210 | // Variables
|
---|
211 | int index;
|
---|
212 | UndoableEdit current;
|
---|
213 |
|
---|
214 | // Check each edit
|
---|
215 | for (index = 0; index < edits.size(); index++) {
|
---|
216 | current = (UndoableEdit) edits.elementAt(index);
|
---|
217 | if (current.isSignificant() == true) {
|
---|
218 | return true;
|
---|
219 | }
|
---|
220 | } // for: index
|
---|
221 |
|
---|
222 | return false;
|
---|
223 |
|
---|
224 | } // isSignificant()
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * lastEdit
|
---|
228 | * @returns TODO
|
---|
229 | */
|
---|
230 | protected UndoableEdit lastEdit() {
|
---|
231 | if (edits.size() == 0) {
|
---|
232 | return null;
|
---|
233 | }
|
---|
234 | return (UndoableEdit) edits.elementAt(edits.size() - 1);
|
---|
235 | } // lastEdit()
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * redo
|
---|
239 | * @throws CannotRedoException TODO
|
---|
240 | */
|
---|
241 | public void redo() throws CannotRedoException {
|
---|
242 |
|
---|
243 | // Variables
|
---|
244 | int index;
|
---|
245 | UndoableEdit current;
|
---|
246 |
|
---|
247 | // Loop through all contained UndoableEdits
|
---|
248 | for (index = 0; index < edits.size(); index++) {
|
---|
249 | current = (UndoableEdit) edits.elementAt(index);
|
---|
250 | current.redo();
|
---|
251 | } // for: index
|
---|
252 |
|
---|
253 | } // redo()
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * String representation
|
---|
257 | * @returns String representation
|
---|
258 | */
|
---|
259 | public String toString() {
|
---|
260 | return null; // TODO
|
---|
261 | } // toString()
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * undo
|
---|
265 | * @throws CannotUndoException TODO
|
---|
266 | */
|
---|
267 | public void undo() throws CannotUndoException {
|
---|
268 |
|
---|
269 | // Variables
|
---|
270 | int index;
|
---|
271 | UndoableEdit current;
|
---|
272 |
|
---|
273 | // Loop through all contained UndoableEdits
|
---|
274 | for (index = edits.size() - 1; index >= 0; index--) {
|
---|
275 | current = (UndoableEdit) edits.elementAt(index);
|
---|
276 | current.undo();
|
---|
277 | } // for: index
|
---|
278 |
|
---|
279 | } // undo()
|
---|
280 |
|
---|
281 |
|
---|
282 | } // CompoundEdit
|
---|