1 package org.herac.tuxguitar.gui.undo.undoables; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.herac.tuxguitar.gui.undo.CannotRedoException; 7 import org.herac.tuxguitar.gui.undo.CannotUndoException; 8 import org.herac.tuxguitar.gui.undo.UndoableEdit; 9 10 public class UndoableJoined implements UndoableEdit{ 11 private int doAction; 12 private UndoableCaretHelper undoCaret; 13 private UndoableCaretHelper redoCaret; 14 private List undoables; 15 UndoableJoined()16 public UndoableJoined(){ 17 this.doAction = UNDO_ACTION; 18 this.undoCaret = new UndoableCaretHelper(); 19 this.undoables = new ArrayList(); 20 } 21 addUndoableEdit(UndoableEdit undoable)22 public void addUndoableEdit(UndoableEdit undoable){ 23 this.undoables.add(undoable); 24 } 25 redo()26 public void redo() throws CannotRedoException { 27 int count = this.undoables.size(); 28 for(int i = 0;i < count;i++){ 29 UndoableEdit undoable = (UndoableEdit)this.undoables.get(i); 30 undoable.redo(); 31 } 32 this.redoCaret.update(); 33 this.doAction = UNDO_ACTION; 34 } 35 undo()36 public void undo() throws CannotUndoException { 37 int count = this.undoables.size(); 38 for(int i = (count - 1);i >= 0;i--){ 39 UndoableEdit undoable = (UndoableEdit)this.undoables.get(i); 40 undoable.undo(); 41 } 42 this.undoCaret.update(); 43 this.doAction = REDO_ACTION; 44 } 45 canRedo()46 public boolean canRedo() { 47 return (this.doAction == REDO_ACTION); 48 } 49 canUndo()50 public boolean canUndo() { 51 return (this.doAction == UNDO_ACTION); 52 } 53 endUndo()54 public UndoableJoined endUndo(){ 55 this.redoCaret = new UndoableCaretHelper(); 56 return this; 57 } 58 isEmpty()59 public boolean isEmpty(){ 60 return this.undoables.isEmpty(); 61 } 62 } 63