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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/undo/undoables/measure/UndoableAddMeasure.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.measure;
2
 
 
3
 
import org.herac.tuxguitar.gui.TuxGuitar;
4
 
import org.herac.tuxguitar.gui.editors.tab.Caret;
5
 
import org.herac.tuxguitar.gui.undo.CannotRedoException;
6
 
import org.herac.tuxguitar.gui.undo.CannotUndoException;
7
 
import org.herac.tuxguitar.gui.undo.UndoableEdit;
8
 
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
9
 
 
10
 
public class UndoableAddMeasure implements UndoableEdit{
11
 
        private int doAction;
12
 
        private UndoableCaretHelper undoCaret;
13
 
        private UndoableCaretHelper redoCaret;
14
 
        private int number;
15
 
        
16
 
        private UndoableAddMeasure(){
17
 
                
18
 
        }
19
 
        
20
 
        public void redo() throws CannotRedoException { 
21
 
                if(!canRedo()){
22
 
                        throw new CannotRedoException();
23
 
                }        
24
 
                TuxGuitar.instance().getSongManager().addNewMeasure(this.number);
25
 
                TuxGuitar.instance().fireUpdate();
26
 
                this.redoCaret.update();
27
 
                
28
 
                this.doAction = UNDO_ACTION;
29
 
        }
30
 
 
31
 
        public void undo() throws CannotUndoException {
32
 
                if(!canUndo()){
33
 
                        throw new CannotUndoException();
34
 
                }       
35
 
                TuxGuitar.instance().getSongManager().removeMeasure(this.number);
36
 
                TuxGuitar.instance().fireUpdate();
37
 
                this.undoCaret.update();
38
 
                
39
 
                this.doAction = REDO_ACTION;
40
 
        }
41
 
 
42
 
    public boolean canRedo() {
43
 
        return (doAction == REDO_ACTION);
44
 
    }
45
 
 
46
 
    public boolean canUndo() {
47
 
        return (doAction == UNDO_ACTION);
48
 
    }
49
 
      
50
 
    public static UndoableAddMeasure startUndo(int number){
51
 
        UndoableAddMeasure undoable = new UndoableAddMeasure();
52
 
        Caret caret = getCaret();               
53
 
        undoable.undoCaret = new UndoableCaretHelper();
54
 
        undoable.doAction = UNDO_ACTION;        
55
 
        undoable.number = number;
56
 
        return undoable;
57
 
    }
58
 
    
59
 
    public UndoableAddMeasure endUndo(){
60
 
        this.redoCaret = new UndoableCaretHelper();
61
 
        return this;
62
 
    }
63
 
    
64
 
    private static Caret getCaret(){
65
 
        return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
66
 
    }  
67
 
 
68
 
}