1
package org.herac.tuxguitar.gui.undo.undoables.track;
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;
11
public class UndoableAddTrack implements UndoableEdit{
13
private UndoableCaretHelper undoCaret;
14
private UndoableCaretHelper redoCaret;
15
private SongTrack redoableTrack;
17
private UndoableAddTrack(){
21
public void redo() throws CannotRedoException {
23
throw new CannotRedoException();
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();
30
this.doAction = UNDO_ACTION;
33
public void undo() throws CannotUndoException {
35
throw new CannotUndoException();
37
TuxGuitar.instance().getSongManager().removeTrack(this.redoableTrack);
38
TuxGuitar.instance().fireUpdate();
39
TuxGuitar.instance().getMixer().update();
40
this.undoCaret.update();
42
this.doAction = REDO_ACTION;
45
public boolean canRedo() {
46
return (doAction == REDO_ACTION);
49
public boolean canUndo() {
50
return (doAction == UNDO_ACTION);
53
public static UndoableAddTrack startUndo(){
54
UndoableAddTrack undoable = new UndoableAddTrack();
55
Caret caret = getCaret();
56
undoable.doAction = UNDO_ACTION;
57
undoable.undoCaret = new UndoableCaretHelper();
62
public UndoableAddTrack endUndo(SongTrack track){
63
this.redoCaret = new UndoableCaretHelper();
64
this.redoableTrack = (SongTrack)track.clone(TuxGuitar.instance().getSongManager().getMeasureHeaders());
68
private static Caret getCaret(){
69
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();