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.editors.tab.SongTrackCoords;
6
import org.herac.tuxguitar.gui.undo.CannotRedoException;
7
import org.herac.tuxguitar.gui.undo.CannotUndoException;
8
import org.herac.tuxguitar.gui.undo.UndoableEdit;
9
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
10
import org.herac.tuxguitar.song.models.Measure;
11
import org.herac.tuxguitar.song.models.MeasureHeader;
13
public class UndoableMeasureGeneric implements UndoableEdit{
15
private int trackNumber;
16
private UndoableCaretHelper undoCaret;
17
private UndoableCaretHelper redoCaret;
18
private Measure undoMeasure;
19
private Measure redoMeasure;
21
private UndoableMeasureGeneric(){
25
public void redo() throws CannotRedoException {
27
throw new CannotRedoException();
29
this.replace(this.redoMeasure);
30
this.redoCaret.update();
31
this.doAction = UNDO_ACTION;
34
public void undo() throws CannotUndoException {
36
throw new CannotUndoException();
38
this.replace(this.undoMeasure);
39
this.undoCaret.update();
40
this.doAction = REDO_ACTION;
43
public boolean canRedo() {
44
return (doAction == REDO_ACTION);
47
public boolean canUndo() {
48
return (doAction == UNDO_ACTION);
51
private void replace(Measure replace){
52
SongTrackCoords track = getCaret().getSongCoords().getTrack(trackNumber);
53
if(track != null && replace != null){
54
MeasureHeader header = TuxGuitar.instance().getSongManager().getMeasureHeader(replace.getNumber());
55
Measure measure = (Measure)replace.clone(header);
56
measure = TuxGuitar.instance().getSongManager().getTrackManager().replaceMeasure(track.getTrack(),measure);
57
TuxGuitar.instance().getTablatureEditor().getTablature().getViewLayout().fireUpdate(measure.getNumber(),false);
61
public static UndoableMeasureGeneric startUndo(){
62
UndoableMeasureGeneric undoable = new UndoableMeasureGeneric();
63
Caret caret = getCaret();
64
undoable.doAction = UNDO_ACTION;
65
undoable.trackNumber = caret.getSongTrackCoords().getTrack().getNumber();
66
undoable.undoCaret = new UndoableCaretHelper();
67
undoable.undoMeasure = (Measure)caret.getMeasureCoords().getMeasure().clone((MeasureHeader)caret.getMeasureCoords().getMeasure().getHeader().clone());
71
public UndoableMeasureGeneric endUndo(){
72
Caret caret = getCaret();
73
this.redoCaret = new UndoableCaretHelper();
74
this.redoMeasure = (Measure)caret.getMeasureCoords().getMeasure().clone((MeasureHeader)caret.getMeasureCoords().getMeasure().getHeader().clone());
79
private static Caret getCaret(){
80
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();