~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/UndoableChangeCloseRepeat.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 UndoableChangeCloseRepeat implements UndoableEdit{
 
13
        private int doAction;
 
14
        private UndoableCaretHelper undoCaret;
 
15
        private UndoableCaretHelper redoCaret;
 
16
        private long position;
 
17
        private int undoRepeatClose;
 
18
        private int redoRepeatClose;
 
19
        
 
20
        private UndoableChangeCloseRepeat(){
 
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.changeCloseRepeat(this.position,this.redoRepeatClose);
 
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.changeCloseRepeat(this.position,this.undoRepeatClose);
 
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 UndoableChangeCloseRepeat startUndo(){
 
59
                Caret caret = getCaret();
 
60
                return startUndo(caret.getPosition(),caret.getMeasure().getRepeatClose());
 
61
        }
 
62
        
 
63
        public static UndoableChangeCloseRepeat startUndo(long position,int repeatClose){
 
64
                UndoableChangeCloseRepeat undoable = new UndoableChangeCloseRepeat();
 
65
                undoable.doAction = UNDO_ACTION;
 
66
                undoable.undoCaret = new UndoableCaretHelper();
 
67
                undoable.position = position;
 
68
                undoable.undoRepeatClose = repeatClose;
 
69
                
 
70
                return undoable;
 
71
        }
 
72
        
 
73
        public UndoableChangeCloseRepeat endUndo(int redoRepeatClose){
 
74
                this.redoCaret = new UndoableCaretHelper();
 
75
                this.redoRepeatClose = redoRepeatClose;
 
76
                return this;
 
77
        }
 
78
        
 
79
        private static Caret getCaret(){
 
80
                return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
 
81
        }
 
82
}