1
package org.herac.tuxguitar.gui.undo.undoables.custom;
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.editors.tab.MeasureCoords;
10
import org.herac.tuxguitar.gui.editors.tab.SongCoords;
11
import org.herac.tuxguitar.gui.undo.CannotRedoException;
12
import org.herac.tuxguitar.gui.undo.CannotUndoException;
13
import org.herac.tuxguitar.gui.undo.UndoableEdit;
14
import org.herac.tuxguitar.gui.undo.undoables.UndoableCaretHelper;
16
public class UndoableChangeTripletFeel implements UndoableEdit{
18
private UndoableCaretHelper undoCaret;
19
private UndoableCaretHelper redoCaret;
20
private long position;
21
private int redoableTripletFeel;
22
private int undoableTripletFeel;
23
private List nextTripletFeelPositions;
24
private boolean toEnd;
26
private UndoableChangeTripletFeel(){
30
public void redo() throws CannotRedoException {
32
throw new CannotRedoException();
34
TuxGuitar.instance().getSongManager().changeTripletFeel(position,redoableTripletFeel,toEnd);
35
TuxGuitar.instance().fireUpdate();
36
this.redoCaret.update();
38
this.doAction = UNDO_ACTION;
41
public void undo() throws CannotUndoException {
43
throw new CannotUndoException();
45
SongCoords songCoords = getCaret().getSongCoords();
46
TuxGuitar.instance().getSongManager().changeTripletFeel(position,undoableTripletFeel,this.toEnd);
48
Iterator it = this.nextTripletFeelPositions.iterator();
50
TripletFeelPosition tfp = (TripletFeelPosition)it.next();
51
TuxGuitar.instance().getSongManager().changeTripletFeel(tfp.getPosition(),tfp.getTripletFeel(),true);
54
TuxGuitar.instance().fireUpdate();
55
this.undoCaret.update();
57
this.doAction = REDO_ACTION;
60
public boolean canRedo() {
61
return (doAction == REDO_ACTION);
64
public boolean canUndo() {
65
return (doAction == UNDO_ACTION);
68
public static UndoableChangeTripletFeel startUndo(){
69
UndoableChangeTripletFeel undoable = new UndoableChangeTripletFeel();
70
Caret caret = getCaret();
71
undoable.doAction = UNDO_ACTION;
72
undoable.undoCaret = new UndoableCaretHelper();
73
undoable.position = caret.getPosition();
74
undoable.undoableTripletFeel = caret.getMeasureCoords().getMeasure().getTripletFeel();
75
undoable.nextTripletFeelPositions = new ArrayList();
77
int prevTripletFeel = undoable.undoableTripletFeel;
78
Iterator it = caret.getSongCoords().getFirstTrack().getMeasuresCoords().iterator();
80
MeasureCoords measureCoords = (MeasureCoords)it.next();
81
if(measureCoords.getMeasure().getStart() > undoable.position){
82
int currTripletFeel = measureCoords.getMeasure().getTripletFeel();
83
if(prevTripletFeel != currTripletFeel){
84
TripletFeelPosition tfp = undoable.new TripletFeelPosition(measureCoords.getMeasure().getStart(),currTripletFeel);
85
undoable.nextTripletFeelPositions.add(tfp);
87
prevTripletFeel = currTripletFeel;
93
public UndoableChangeTripletFeel endUndo(int tripletFeel,boolean toEnd){
94
this.redoCaret = new UndoableCaretHelper();
95
this.redoableTripletFeel = tripletFeel;
100
private static Caret getCaret(){
101
return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
105
private class TripletFeelPosition{
106
private long position;
107
private int tripletFeel;
109
public TripletFeelPosition(long position,int tripletFeel) {
110
this.position = position;
111
this.tripletFeel = tripletFeel;
113
public long getPosition() {
116
public int getTripletFeel() {