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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2007-02-04 01:41:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070204014123-9pv7okph0iaiqkvw
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

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