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;
9
import org.herac.tuxguitar.song.helpers.TracksMeasures;
11
public class UndoableInsertMeasure implements UndoableEdit{
13
private UndoableCaretHelper undoCaret;
14
private UndoableCaretHelper redoCaret;
15
private TracksMeasures tracksMeasures;
16
private long insertPosition;
17
private int copyCount;
18
private int fromNumber;
21
public UndoableInsertMeasure(){
22
Caret caret = getCaret();
23
this.doAction = UNDO_ACTION;
24
this.undoCaret = new UndoableCaretHelper();
25
this.insertPosition = caret.getPosition();
28
public void redo() throws CannotRedoException {
30
throw new CannotRedoException();
32
TuxGuitar.instance().getSongManager().insertMeasures((TracksMeasures)tracksMeasures.clone(),fromNumber,theMove);
33
TuxGuitar.instance().fireUpdate();
34
this.redoCaret.update();
36
this.doAction = UNDO_ACTION;
39
public void undo() throws CannotUndoException {
41
throw new CannotUndoException();
43
for(int i = 0;i < this.copyCount;i ++){
44
TuxGuitar.instance().getSongManager().removeMeasure(insertPosition);
46
TuxGuitar.instance().fireUpdate();
47
this.undoCaret.update();
49
this.doAction = REDO_ACTION;
52
public boolean canRedo() {
53
return (doAction == REDO_ACTION);
56
public boolean canUndo() {
57
return (doAction == UNDO_ACTION);
60
public UndoableInsertMeasure endUndo(TracksMeasures tracksMeasures,int copyCount,int fromNumber,long theMove){
61
this.redoCaret = new UndoableCaretHelper();
62
this.copyCount = copyCount;
63
this.tracksMeasures = tracksMeasures;
64
this.fromNumber = fromNumber;
65
this.theMove = theMove;
69
private static Caret getCaret(){
70
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();