01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.commands;
20:
21: import java.util.ArrayList;
22: import java.util.Iterator;
23:
24: import javax.swing.undo.CannotRedoException;
25:
26: import com.jeta.forms.gui.form.FormComponent;
27:
28: /**
29: * Command that runs a group of commands as one
30: *
31: * @author Jeff Tassin
32: */
33: public class CompositeCommand extends FormUndoableEdit {
34: private ArrayList m_commands = new ArrayList();
35:
36: /**
37: * ctor
38: */
39: public CompositeCommand(FormComponent form, FormUndoableEdit cmd1,
40: FormUndoableEdit cmd2) {
41: super (form);
42: if (cmd1 != null)
43: m_commands.add(cmd1);
44:
45: if (cmd2 != null)
46: m_commands.add(cmd2);
47: }
48:
49: /**
50: * UndoableEdit implementation Override should begin with a call to super.
51: */
52: public void redo() throws CannotRedoException {
53: super .redo();
54: Iterator iter = m_commands.iterator();
55: while (iter.hasNext()) {
56: FormUndoableEdit cmd = (FormUndoableEdit) iter.next();
57: cmd.redo();
58: }
59: }
60:
61: /**
62: * UndoableEdit implementation Override should begin with a call to super.
63: */
64: public void undo() throws CannotRedoException {
65: super .undo();
66: for (int index = m_commands.size() - 1; index >= 0; index--) {
67: FormUndoableEdit cmd = (FormUndoableEdit) m_commands
68: .get(index);
69: cmd.undo();
70: }
71: }
72:
73: public String toString() {
74: return "CompositeCommand newcomp: size: "
75: + m_commands.size();
76: }
77:
78: }
|