1 package jimm.datavision.gui.cmd; 2 import java.util.ArrayList ; 3 import java.util.Iterator ; 4 import java.util.ListIterator ; 6 12 public class CompoundCommand extends CommandAdapter { 13 14 protected ArrayList commands; 15 16 public CompoundCommand(String name) { 17 super(name); 18 commands = new ArrayList (); 19 } 20 21 public void add(Command c) { 22 commands.add(c); 23 } 24 25 public int numCommands() { return commands.size(); } 26 27 public void perform() { 28 for (Iterator iter = commands.iterator(); iter.hasNext(); ) 29 ((Command)iter.next()).perform(); 30 } 31 32 public void undo() { 33 for (ListIterator iter = commands.listIterator(commands.size()); 34 iter.hasPrevious(); ) 35 ((Command)iter.previous()).undo(); 36 } 37 38 public void redo() { 39 for (Iterator iter = commands.iterator(); iter.hasNext(); ) 40 ((Command)iter.next()).redo(); 41 } 42 43 } 44 | Popular Tags |