01: // The UMLet source code is distributed under the terms of the GPL; see license.txt
02: package com.umlet.control;
03:
04: import java.util.*;
05:
06: public class Macro extends Command {
07: private Vector _commands;
08:
09: public Vector getCommands() {
10: return _commands;
11: }
12:
13: public Macro(Vector v) {
14: _commands = v;
15: }
16:
17: public void execute() {
18: super .execute();
19: for (int i = 0; i < _commands.size(); i++) {
20: Command c = (Command) _commands.elementAt(i);
21: c.execute();
22: }
23: }
24:
25: public void undo() {
26: super .undo();
27: for (int i = 0; i < _commands.size(); i++) {
28: Command c = (Command) _commands.elementAt(i);
29: c.undo();
30: }
31: }
32:
33: public boolean isMergeableTo(Command c) {
34: if (!(c instanceof Macro))
35: return false;
36: Macro m = (Macro) c;
37: Vector v = m.getCommands();
38: if (this .getCommands().size() != v.size())
39: return false;
40: for (int i = 0; i < this .getCommands().size(); i++) {
41: Command c1 = (Command) this .getCommands().elementAt(i);
42: Command c2 = (Command) v.elementAt(i);
43: if (!(c1.isMergeableTo(c2)))
44: return false;
45: }
46: return true;
47: }
48:
49: public Command mergeTo(Command c) {
50: Macro m = (Macro) c;
51: Vector v = m.getCommands();
52:
53: Vector<Command> vectorOfCommands = new Vector<Command>();
54: Command ret = new Macro(vectorOfCommands);
55:
56: for (int i = 0; i < this .getCommands().size(); i++) {
57: Command c1 = (Command) this .getCommands().elementAt(i);
58: Command c2 = (Command) v.elementAt(i);
59: Command c3 = c1.mergeTo(c2);
60: vectorOfCommands.add(c3);
61: }
62: return ret;
63: }
64: }
|