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.undo.CannotRedoException;
9
import org.herac.tuxguitar.gui.undo.CannotUndoException;
10
import org.herac.tuxguitar.gui.undo.UndoableEdit;
11
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
12
import org.herac.tuxguitar.song.helpers.TGSongSegment;
13
import org.herac.tuxguitar.song.helpers.TGSongSegmentHelper;
14
import org.herac.tuxguitar.song.models.TGMarker;
16
public class UndoableRemoveMeasure implements UndoableEdit{
18
private UndoableCaretHelper undoCaret;
19
private UndoableCaretHelper redoCaret;
20
private TGSongSegment tracksMeasures;
21
private UndoMarkers undoMarkers;
25
public UndoableRemoveMeasure(int n1,int n2){
26
this.doAction = UNDO_ACTION;
27
this.undoCaret = new UndoableCaretHelper();
30
this.tracksMeasures = new TGSongSegmentHelper(TuxGuitar.instance().getSongManager()).copyMeasures(n1,n2);
31
this.undoMarkers = new UndoMarkers();
34
public void redo() throws CannotRedoException {
36
throw new CannotRedoException();
38
TuxGuitar.instance().getSongManager().removeMeasureHeaders(this.n1,this.n2);
39
TuxGuitar.instance().fireUpdate();
41
this.redoCaret.update();
42
this.doAction = UNDO_ACTION;
45
public void undo() throws CannotUndoException {
47
throw new CannotUndoException();
49
new TGSongSegmentHelper(TuxGuitar.instance().getSongManager()).insertMeasures(this.tracksMeasures.clone(TuxGuitar.instance().getSongManager().getFactory()),this.n1,0,0);
51
TuxGuitar.instance().fireUpdate();
52
this.undoMarkers.undo();
53
this.undoCaret.update();
55
this.doAction = REDO_ACTION;
58
public boolean canRedo() {
59
return (this.doAction == REDO_ACTION);
62
public boolean canUndo() {
63
return (this.doAction == UNDO_ACTION);
66
public UndoableRemoveMeasure endUndo(){
67
this.redoCaret = new UndoableCaretHelper();
71
private class UndoMarkers{
75
this.markers = new ArrayList();
76
Iterator it = TuxGuitar.instance().getSongManager().getMarkers().iterator();
78
this.markers.add(((TGMarker)it.next()).clone(TuxGuitar.instance().getSongManager().getFactory()));
83
TuxGuitar.instance().getSongManager().removeAllMarkers();
84
Iterator it = this.markers.iterator();
86
TGMarker marker = (TGMarker)it.next();
87
TuxGuitar.instance().getSongManager().updateMarker(marker.clone(TuxGuitar.instance().getSongManager().getFactory()));