~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/undo/undoables/JoinedUndoable.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 JoinedUndoable implements UndoableEdit{
11
 
        private int doAction;
12
 
        private UndoableCaretHelper undoCaret;
13
 
        private UndoableCaretHelper redoCaret;          
14
 
        private List undoables;
15
 
        
16
 
        public JoinedUndoable(){
17
 
                this.doAction = UNDO_ACTION;
18
 
                this.undoCaret = new UndoableCaretHelper();
19
 
                this.undoables = new ArrayList();
20
 
        }
21
 
        
22
 
        public void addUndoableEdit(UndoableEdit undoable){
23
 
                this.undoables.add(undoable);
24
 
        }
25
 
 
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
 
 
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
 
 
46
 
    public boolean canRedo() {
47
 
        return (doAction == REDO_ACTION);
48
 
    }
49
 
 
50
 
    public boolean canUndo() {
51
 
        return (doAction == UNDO_ACTION);
52
 
    }
53
 
    
54
 
    public JoinedUndoable endUndo(){
55
 
        this.redoCaret = new UndoableCaretHelper();
56
 
        return this;
57
 
    }
58
 
}