~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/UndoableTrackLyric.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.TGLyric;
 
9
import org.herac.tuxguitar.song.models.TGTrack;
 
10
 
 
11
public class UndoableTrackLyric implements UndoableEdit{
 
12
        private int doAction;
 
13
        private int trackNumber;
 
14
        private UndoableCaretHelper undoCaret;
 
15
        private UndoableCaretHelper redoCaret;
 
16
        private TGLyric undoLyric;
 
17
        private TGLyric redoLyric;
 
18
        private int undoCaretPosition;
 
19
        private int redoCaretPosition;
 
20
        
 
21
        private UndoableTrackLyric(){
 
22
                this.undoLyric = TuxGuitar.instance().getSongManager().getFactory().newLyric();
 
23
                this.redoLyric = TuxGuitar.instance().getSongManager().getFactory().newLyric();
 
24
        }
 
25
        
 
26
        public void redo() throws CannotRedoException {
 
27
                if(!canRedo()){
 
28
                        throw new CannotRedoException();
 
29
                }
 
30
                TGTrack track = TuxGuitar.instance().getSongManager().getTrack(this.trackNumber);
 
31
                this.redoLyric.copy(track.getLyrics());
 
32
                TuxGuitar.instance().getLyricEditor().setCaretPosition(this.redoCaretPosition);
 
33
                TuxGuitar.instance().getLyricEditor().update();
 
34
                TuxGuitar.instance().updateCache(false);
 
35
                this.redoCaret.update();
 
36
                this.doAction = UNDO_ACTION;
 
37
        }
 
38
        
 
39
        public void undo() throws CannotUndoException {
 
40
                if(!canUndo()){
 
41
                        throw new CannotUndoException();
 
42
                }
 
43
                TGTrack track = TuxGuitar.instance().getSongManager().getTrack(this.trackNumber);
 
44
                this.undoLyric.copy(track.getLyrics());
 
45
                TuxGuitar.instance().getLyricEditor().setCaretPosition(this.undoCaretPosition);
 
46
                TuxGuitar.instance().getLyricEditor().update();
 
47
                TuxGuitar.instance().updateCache(false);
 
48
                this.undoCaret.update();
 
49
                this.doAction = REDO_ACTION;
 
50
        }
 
51
        
 
52
        public boolean canRedo() {
 
53
                return (this.doAction == REDO_ACTION);
 
54
        }
 
55
        
 
56
        public boolean canUndo() {
 
57
                return (this.doAction == UNDO_ACTION);
 
58
        }
 
59
        
 
60
        public static UndoableTrackLyric startUndo(TGTrack track,int undoCaretPosition){
 
61
                UndoableTrackLyric undoable = new UndoableTrackLyric();
 
62
                undoable.doAction = UNDO_ACTION;
 
63
                undoable.trackNumber = track.getNumber();
 
64
                undoable.undoCaret = new UndoableCaretHelper();
 
65
                undoable.undoCaretPosition = undoCaretPosition;
 
66
                track.getLyrics().copy( undoable.undoLyric );
 
67
                return undoable;
 
68
        }
 
69
        
 
70
        public UndoableTrackLyric endUndo(TGTrack track,int redoCaretPosition){
 
71
                this.redoCaret = new UndoableCaretHelper();
 
72
                this.redoCaretPosition = redoCaretPosition;
 
73
                track.getLyrics().copy( this.redoLyric );
 
74
                return this;
 
75
        }
 
76
        
 
77
}