1
package org.herac.tuxguitar.gui.undo.undoables.measure;
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;
10
public class UndoableAddMeasure implements UndoableEdit{
12
private UndoableCaretHelper undoCaret;
13
private UndoableCaretHelper redoCaret;
16
private UndoableAddMeasure(){
20
public void redo() throws CannotRedoException {
22
throw new CannotRedoException();
24
TuxGuitar.instance().getSongManager().addNewMeasure(this.number);
25
TuxGuitar.instance().fireUpdate();
26
this.redoCaret.update();
28
this.doAction = UNDO_ACTION;
31
public void undo() throws CannotUndoException {
33
throw new CannotUndoException();
35
TuxGuitar.instance().getSongManager().removeMeasure(this.number);
36
TuxGuitar.instance().fireUpdate();
37
this.undoCaret.update();
39
this.doAction = REDO_ACTION;
42
public boolean canRedo() {
43
return (doAction == REDO_ACTION);
46
public boolean canUndo() {
47
return (doAction == UNDO_ACTION);
50
public static UndoableAddMeasure startUndo(int number){
51
UndoableAddMeasure undoable = new UndoableAddMeasure();
52
Caret caret = getCaret();
53
undoable.undoCaret = new UndoableCaretHelper();
54
undoable.doAction = UNDO_ACTION;
55
undoable.number = number;
59
public UndoableAddMeasure endUndo(){
60
this.redoCaret = new UndoableCaretHelper();
64
private static Caret getCaret(){
65
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();