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 UndoableRemoveTrack implements UndoableEdit{
13
private UndoableCaretHelper undoCaret;
14
private UndoableCaretHelper redoCaret;
15
private SongTrack undoableTrack;
17
private UndoableRemoveTrack(){
21
public void redo() throws CannotRedoException {
23
throw new CannotRedoException();
25
TuxGuitar.instance().getSongManager().removeTrack(this.undoableTrack);
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().addTrack((SongTrack)this.undoableTrack.clone(TuxGuitar.instance().getSongManager().getMeasureHeaders()));
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 UndoableRemoveTrack startUndo(){
54
UndoableRemoveTrack undoable = new UndoableRemoveTrack();
55
Caret caret = getCaret();
56
undoable.doAction = UNDO_ACTION;
57
undoable.undoCaret = new UndoableCaretHelper();
58
undoable.undoableTrack = caret.getSongTrackCoords().getTrack();
63
public UndoableRemoveTrack endUndo(){
64
this.redoCaret = new UndoableCaretHelper();
68
private static Caret getCaret(){
69
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();