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.TGSongSegment;
10
import org.herac.tuxguitar.song.helpers.TGSongSegmentHelper;
12
public class UndoableInsertMeasure implements UndoableEdit{
14
private UndoableCaretHelper undoCaret;
15
private UndoableCaretHelper redoCaret;
16
private TGSongSegment tracksMeasures;
17
private long insertPosition;
19
private int copyCount;
20
private int fromNumber;
23
public UndoableInsertMeasure(int toTrack){
24
Caret caret = getCaret();
25
this.doAction = UNDO_ACTION;
26
this.toTrack = toTrack;
27
this.undoCaret = new UndoableCaretHelper();
28
this.insertPosition = caret.getPosition();
31
public void redo() throws CannotRedoException {
33
throw new CannotRedoException();
35
TGSongSegmentHelper helper = new TGSongSegmentHelper(TuxGuitar.instance().getSongManager());
36
helper.insertMeasures(this.tracksMeasures.clone(TuxGuitar.instance().getSongManager().getFactory()),this.fromNumber,this.theMove,this.toTrack);
37
TuxGuitar.instance().fireUpdate();
38
this.redoCaret.update();
40
this.doAction = UNDO_ACTION;
43
public void undo() throws CannotUndoException {
45
throw new CannotUndoException();
47
for(int i = 0;i < this.copyCount;i ++){
48
TuxGuitar.instance().getSongManager().removeMeasure(this.insertPosition);
50
TuxGuitar.instance().fireUpdate();
51
this.undoCaret.update();
53
this.doAction = REDO_ACTION;
56
public boolean canRedo() {
57
return (this.doAction == REDO_ACTION);
60
public boolean canUndo() {
61
return (this.doAction == UNDO_ACTION);
64
public UndoableInsertMeasure endUndo(TGSongSegment tracksMeasures,int copyCount,int fromNumber,long theMove){
65
this.redoCaret = new UndoableCaretHelper();
66
this.copyCount = copyCount;
67
this.tracksMeasures = tracksMeasures;
68
this.fromNumber = fromNumber;
69
this.theMove = theMove;
73
private static Caret getCaret(){
74
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();