1
package org.herac.tuxguitar.gui.undo.undoables.custom;
3
import org.herac.tuxguitar.gui.TuxGuitar;
4
import org.herac.tuxguitar.gui.marker.MarkerList;
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.TGMarker;
11
public class UndoableChangeMarker implements UndoableEdit{
13
private UndoableCaretHelper undoCaret;
14
private UndoableCaretHelper redoCaret;
15
private TGMarker undoMarker;
16
private TGMarker redoMarker;
18
private UndoableChangeMarker(){
22
public void redo() throws CannotRedoException {
24
throw new CannotRedoException();
26
if(this.redoMarker != null){
27
TuxGuitar.instance().getSongManager().updateMarker(this.redoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
28
MarkerList.instance().update(true);
29
}else if(this.undoMarker != null){
30
TuxGuitar.instance().getSongManager().removeMarker(this.undoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
31
MarkerList.instance().update(false);
33
this.redoCaret.update();
34
this.doAction = UNDO_ACTION;
37
public void undo() throws CannotUndoException {
39
throw new CannotUndoException();
41
if(this.undoMarker != null){
42
TuxGuitar.instance().getSongManager().updateMarker(this.undoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
43
MarkerList.instance().update(true);
44
}else if(this.redoMarker != null){
45
TuxGuitar.instance().getSongManager().removeMarker(this.redoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
46
MarkerList.instance().update(false);
48
this.undoCaret.update();
49
this.doAction = REDO_ACTION;
52
public boolean canRedo() {
53
return (this.doAction == REDO_ACTION);
56
public boolean canUndo() {
57
return (this.doAction == UNDO_ACTION);
60
public static UndoableChangeMarker startUndo(TGMarker marker){
61
UndoableChangeMarker undoable = new UndoableChangeMarker();
62
undoable.doAction = UNDO_ACTION;
63
undoable.undoCaret = new UndoableCaretHelper();
64
undoable.undoMarker = (marker == null)?null:(TGMarker)marker.clone(TuxGuitar.instance().getSongManager().getFactory());
69
public UndoableChangeMarker endUndo(TGMarker marker){
70
this.redoCaret = new UndoableCaretHelper();
71
this.redoMarker = (marker == null)?null:(TGMarker)marker.clone(TuxGuitar.instance().getSongManager().getFactory());