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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/undo/undoables/track/UndoableTrackGeneric.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.undo.CannotRedoException;
 
5
import org.herac.tuxguitar.gui.undo.CannotUndoException;
 
6
import org.herac.tuxguitar.gui.undo.UndoableEdit;
 
7
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
 
8
import org.herac.tuxguitar.song.models.TGTrack;
 
9
 
 
10
public class UndoableTrackGeneric implements UndoableEdit{
 
11
        private int doAction;
 
12
        private UndoableCaretHelper undoCaret;
 
13
        private UndoableCaretHelper redoCaret;
 
14
        private UndoTrack undoTrack;
 
15
        private RedoTrack redoTrack;
 
16
        
 
17
        private UndoableTrackGeneric(){
 
18
                super();
 
19
        }
 
20
        
 
21
        public void redo() throws CannotRedoException {
 
22
                if(!canRedo()){
 
23
                        throw new CannotRedoException();
 
24
                }
 
25
                this.redoTrack.redo();
 
26
                this.redoCaret.update();
 
27
                this.doAction = UNDO_ACTION;
 
28
        }
 
29
        
 
30
        public void undo() throws CannotUndoException {
 
31
                if(!canUndo()){
 
32
                        throw new CannotUndoException();
 
33
                }
 
34
                this.undoTrack.undo();
 
35
                this.undoCaret.update();
 
36
                this.doAction = REDO_ACTION;
 
37
        }
 
38
        
 
39
        public boolean canRedo() {
 
40
                return (this.doAction == REDO_ACTION);
 
41
        }
 
42
        
 
43
        public boolean canUndo() {
 
44
                return (this.doAction == UNDO_ACTION);
 
45
        }
 
46
        
 
47
        
 
48
        public static UndoableTrackGeneric startUndo(TGTrack track){
 
49
                UndoableTrackGeneric undoable = new UndoableTrackGeneric();
 
50
                undoable.doAction = UNDO_ACTION;
 
51
                undoable.undoCaret = new UndoableCaretHelper();
 
52
                undoable.undoTrack = undoable.new UndoTrack(track);
 
53
                
 
54
                return undoable;
 
55
        }
 
56
        
 
57
        public UndoableTrackGeneric endUndo(TGTrack track){
 
58
                this.redoCaret = new UndoableCaretHelper();
 
59
                this.redoTrack = new RedoTrack(track);
 
60
                return this;
 
61
        }
 
62
        
 
63
        private class UndoTrack{
 
64
                private TGTrack track;
 
65
                
 
66
                public UndoTrack(TGTrack track){
 
67
                        if(track != null){
 
68
                                this.track = track.clone(TuxGuitar.instance().getSongManager().getFactory(),TuxGuitar.instance().getSongManager().getSong());
 
69
                        }
 
70
                }
 
71
                
 
72
                public void undo(){
 
73
                        if(this.track != null){
 
74
                                TuxGuitar.instance().getSongManager().replaceTrack(this.track);
 
75
                                TuxGuitar.instance().fireUpdate();
 
76
                                TuxGuitar.instance().getMixer().update();
 
77
                        }
 
78
                }
 
79
        }
 
80
        
 
81
        private class RedoTrack{
 
82
                private TGTrack track;
 
83
                
 
84
                public RedoTrack(TGTrack track){
 
85
                        if(track != null){
 
86
                                this.track = track.clone(TuxGuitar.instance().getSongManager().getFactory(),TuxGuitar.instance().getSongManager().getSong());
 
87
                        }
 
88
                }
 
89
                
 
90
                public void redo(){
 
91
                        if(this.track != null){
 
92
                                TuxGuitar.instance().getSongManager().replaceTrack(this.track);
 
93
                                TuxGuitar.instance().fireUpdate();
 
94
                                TuxGuitar.instance().getMixer().update();
 
95
                        }
 
96
                }
 
97
        }
 
98
}