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.TGSongManager;
10
import org.herac.tuxguitar.song.models.TGMeasure;
12
public class UndoableChangeCloseRepeat implements UndoableEdit{
14
private UndoableCaretHelper undoCaret;
15
private UndoableCaretHelper redoCaret;
16
private long position;
17
private int undoRepeatClose;
18
private int redoRepeatClose;
20
private UndoableChangeCloseRepeat(){
24
public void redo() throws CannotRedoException {
26
throw new CannotRedoException();
28
TGSongManager manager = TuxGuitar.instance().getSongManager();
29
manager.changeCloseRepeat(this.position,this.redoRepeatClose);
30
TGMeasure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),this.position);
31
TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber());
32
this.redoCaret.update();
34
this.doAction = UNDO_ACTION;
37
public void undo() throws CannotUndoException {
39
throw new CannotUndoException();
41
TGSongManager manager = TuxGuitar.instance().getSongManager();
42
manager.changeCloseRepeat(this.position,this.undoRepeatClose);
43
TGMeasure measure = manager.getTrackManager().getMeasureAt(manager.getFirstTrack(),this.position);
44
TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber());
45
this.undoCaret.update();
47
this.doAction = REDO_ACTION;
50
public boolean canRedo() {
51
return (this.doAction == REDO_ACTION);
54
public boolean canUndo() {
55
return (this.doAction == UNDO_ACTION);
58
public static UndoableChangeCloseRepeat startUndo(){
59
Caret caret = getCaret();
60
return startUndo(caret.getPosition(),caret.getMeasure().getRepeatClose());
63
public static UndoableChangeCloseRepeat startUndo(long position,int repeatClose){
64
UndoableChangeCloseRepeat undoable = new UndoableChangeCloseRepeat();
65
undoable.doAction = UNDO_ACTION;
66
undoable.undoCaret = new UndoableCaretHelper();
67
undoable.position = position;
68
undoable.undoRepeatClose = repeatClose;
73
public UndoableChangeCloseRepeat endUndo(int redoRepeatClose){
74
this.redoCaret = new UndoableCaretHelper();
75
this.redoRepeatClose = redoRepeatClose;
79
private static Caret getCaret(){
80
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();