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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/undo/undoables/custom/UndoableChangeAlternativeRepeat.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.custom;
 
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
import org.herac.tuxguitar.song.managers.TGSongManager;
 
10
import org.herac.tuxguitar.song.models.TGMeasure;
 
11
 
 
12
public class UndoableChangeAlternativeRepeat implements UndoableEdit{
 
13
        private int doAction;
 
14
        private UndoableCaretHelper undoCaret;
 
15
        private UndoableCaretHelper redoCaret;
 
16
        private long position;
 
17
        private int undoRepeatAlternative;
 
18
        private int redoRepeatAlternative;
 
19
        
 
20
        private UndoableChangeAlternativeRepeat(){
 
21
                super();
 
22
        }
 
23
        
 
24
        public void redo() throws CannotRedoException {
 
25
                if(!canRedo()){
 
26
                        throw new CannotRedoException();
 
27
                }
 
28
                TGSongManager manager = TuxGuitar.instance().getSongManager();
 
29
                manager.changeAlternativeRepeat(this.position,this.redoRepeatAlternative);
 
30
                TGMeasure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),this.position);
 
31
                TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber());
 
32
                this.redoCaret.update();
 
33
                
 
34
                this.doAction = UNDO_ACTION;
 
35
        }
 
36
        
 
37
        public void undo() throws CannotUndoException {
 
38
                if(!canUndo()){
 
39
                        throw new CannotUndoException();
 
40
                }
 
41
                TGSongManager manager = TuxGuitar.instance().getSongManager();
 
42
                manager.changeAlternativeRepeat(this.position,this.undoRepeatAlternative);
 
43
                TGMeasure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),this.position);
 
44
                TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber());
 
45
                this.undoCaret.update();
 
46
                
 
47
                this.doAction = REDO_ACTION;
 
48
        }
 
49
        
 
50
        public boolean canRedo() {
 
51
                return (this.doAction == REDO_ACTION);
 
52
        }
 
53
        
 
54
        public boolean canUndo() {
 
55
                return (this.doAction == UNDO_ACTION);
 
56
        }
 
57
        
 
58
        public static UndoableChangeAlternativeRepeat startUndo(){
 
59
                UndoableChangeAlternativeRepeat undoable = new UndoableChangeAlternativeRepeat();
 
60
                Caret caret = getCaret();
 
61
                undoable.doAction = UNDO_ACTION;
 
62
                undoable.undoCaret = new UndoableCaretHelper();
 
63
                undoable.position = caret.getPosition();
 
64
                undoable.undoRepeatAlternative = caret.getMeasure().getHeader().getRepeatAlternative();
 
65
                
 
66
                return undoable;
 
67
        }
 
68
        
 
69
        public UndoableChangeAlternativeRepeat endUndo(int redoRepeatAlternative){
 
70
                this.redoCaret = new UndoableCaretHelper();
 
71
                this.redoRepeatAlternative = redoRepeatAlternative;
 
72
                return this;
 
73
        }
 
74
        
 
75
        private static Caret getCaret(){
 
76
                return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
 
77
        }
 
78
        
 
79
}