1
package org.herac.tuxguitar.gui.undo.undoables.measure;
3
import java.util.ArrayList;
4
import java.util.Iterator;
7
import org.herac.tuxguitar.gui.TuxGuitar;
8
import org.herac.tuxguitar.gui.editors.tab.Caret;
9
import org.herac.tuxguitar.gui.undo.CannotRedoException;
10
import org.herac.tuxguitar.gui.undo.CannotUndoException;
11
import org.herac.tuxguitar.gui.undo.UndoableEdit;
12
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
13
import org.herac.tuxguitar.song.helpers.TracksMeasures;
14
import org.herac.tuxguitar.song.models.Marker;
16
public class UndoableReplaceMeasures implements UndoableEdit{
18
private UndoableCaretHelper undoCaret;
19
private UndoableCaretHelper redoCaret;
20
private UndoMarkers undoMarkers;
21
private TracksMeasures undoTrackMeasures;
22
private TracksMeasures redoTrackMeasures;
24
private int freeSpace;
27
public UndoableReplaceMeasures(long p1,long p2){
28
Caret caret = getCaret();
29
this.doAction = UNDO_ACTION;
30
this.undoCaret = new UndoableCaretHelper();
31
this.undoMarkers = new UndoMarkers();
32
this.undoTrackMeasures = TuxGuitar.instance().getSongManager().copyMeasures(p1,p2);
35
public void redo() throws CannotRedoException {
37
throw new CannotRedoException();
40
for(int i = freeSpace;i < count;i ++){
41
TuxGuitar.instance().getSongManager().addNewMeasureBeforeEnd();
43
TuxGuitar.instance().getSongManager().replaceMeasures((TracksMeasures)redoTrackMeasures.clone(),theMove);
45
TuxGuitar.instance().fireUpdate();
46
this.redoCaret.update();
48
this.doAction = UNDO_ACTION;
51
public void undo() throws CannotUndoException {
53
throw new CannotUndoException();
56
for(int i = freeSpace;i < count;i ++){
57
TuxGuitar.instance().getSongManager().removeLastMeasure();
59
TuxGuitar.instance().getSongManager().replaceMeasures((TracksMeasures)undoTrackMeasures.clone(),0);
61
TuxGuitar.instance().fireUpdate();
62
this.undoMarkers.undo();
63
this.undoCaret.update();
65
this.doAction = REDO_ACTION;
68
public boolean canRedo() {
69
return (doAction == REDO_ACTION);
72
public boolean canUndo() {
73
return (doAction == UNDO_ACTION);
77
private static Caret getCaret(){
78
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
81
public UndoableReplaceMeasures endUndo(TracksMeasures tracksMeasures,int count,int freeSpace,long theMove){
82
this.redoCaret = new UndoableCaretHelper();
83
this.redoTrackMeasures = tracksMeasures;
85
this.freeSpace = freeSpace;
86
this.theMove = theMove;
91
private class UndoMarkers{
95
this.markers = new ArrayList();
96
Iterator it = TuxGuitar.instance().getSongManager().getMarkers().iterator();
98
this.markers.add(((Marker)it.next()).clone());
103
TuxGuitar.instance().getSongManager().removeAllMarkers();
104
Iterator it = this.markers.iterator();
106
Marker marker = (Marker)it.next();
107
TuxGuitar.instance().getSongManager().updateMarker((Marker)marker.clone());