1
package org.herac.tuxguitar.gui.undo.undoables.track;
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;
11
public class UndoableTrackLyric implements UndoableEdit{
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;
21
private UndoableTrackLyric(){
22
this.undoLyric = TuxGuitar.instance().getSongManager().getFactory().newLyric();
23
this.redoLyric = TuxGuitar.instance().getSongManager().getFactory().newLyric();
26
public void redo() throws CannotRedoException {
28
throw new CannotRedoException();
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;
39
public void undo() throws CannotUndoException {
41
throw new CannotUndoException();
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;
52
public boolean canRedo() {
53
return (this.doAction == REDO_ACTION);
56
public boolean canUndo() {
57
return (this.doAction == UNDO_ACTION);
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 );
70
public UndoableTrackLyric endUndo(TGTrack track,int redoCaretPosition){
71
this.redoCaret = new UndoableCaretHelper();
72
this.redoCaretPosition = redoCaretPosition;
73
track.getLyrics().copy( this.redoLyric );