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

« back to all changes in this revision

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