1
package org.herac.tuxguitar.gui.undo.undoables.custom;
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.managers.SongManager;
10
import org.herac.tuxguitar.song.models.Measure;
12
public class UndoableChangeOpenRepeat implements UndoableEdit{
14
private UndoableCaretHelper undoCaret;
15
private UndoableCaretHelper redoCaret;
16
private long position;
18
private UndoableChangeOpenRepeat(){
22
public void redo() throws CannotRedoException {
24
throw new CannotRedoException();
26
SongManager manager = TuxGuitar.instance().getSongManager();
27
manager.changeOpenRepeat(position);
28
Measure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),position);
29
TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber(),false);
30
this.redoCaret.update();
32
this.doAction = UNDO_ACTION;
35
public void undo() throws CannotUndoException {
37
throw new CannotUndoException();
39
SongManager manager = TuxGuitar.instance().getSongManager();
40
manager.changeOpenRepeat(position);
41
Measure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),position);
42
TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber(),false);
43
this.undoCaret.update();
45
this.doAction = REDO_ACTION;
48
public boolean canRedo() {
49
return (doAction == REDO_ACTION);
52
public boolean canUndo() {
53
return (doAction == UNDO_ACTION);
56
public static UndoableChangeOpenRepeat startUndo(){
57
UndoableChangeOpenRepeat undoable = new UndoableChangeOpenRepeat();
58
Caret caret = getCaret();
59
undoable.doAction = UNDO_ACTION;
60
undoable.undoCaret = new UndoableCaretHelper();
61
undoable.position = caret.getPosition();
66
public UndoableChangeOpenRepeat endUndo(){
67
this.redoCaret = new UndoableCaretHelper();
71
private static Caret getCaret(){
72
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();