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.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.models.TGMeasureHeader;
13
import org.herac.tuxguitar.song.models.TGTempo;
15
public class UndoableChangeTempo implements UndoableEdit{
17
private UndoableCaretHelper undoCaret;
18
private UndoableCaretHelper redoCaret;
19
private List undoableTempos;
20
private List redoableTempos;
22
private UndoableChangeTempo(){
24
this.undoableTempos = new ArrayList();
25
this.redoableTempos = new ArrayList();
28
public void redo() throws CannotRedoException {
30
throw new CannotRedoException();
32
this.setTempos(this.redoableTempos);
33
this.redoCaret.update();
35
this.doAction = UNDO_ACTION;
38
public void undo() throws CannotUndoException {
40
throw new CannotUndoException();
42
this.setTempos(this.undoableTempos);
43
this.undoCaret.update();
45
this.doAction = REDO_ACTION;
48
public boolean canRedo() {
49
return (this.doAction == REDO_ACTION);
52
public boolean canUndo() {
53
return (this.doAction == UNDO_ACTION);
56
public static UndoableChangeTempo startUndo(){
57
UndoableChangeTempo undoable = new UndoableChangeTempo();
58
undoable.doAction = UNDO_ACTION;
59
undoable.undoCaret = new UndoableCaretHelper();
60
undoable.getTempos(undoable.undoableTempos);
64
public UndoableChangeTempo endUndo(){
65
this.redoCaret = new UndoableCaretHelper();
66
this.getTempos(this.redoableTempos);
70
private void getTempos(List list){
71
Iterator it = TuxGuitar.instance().getSongManager().getSong().getMeasureHeaders();
73
TGMeasureHeader header = (TGMeasureHeader)it.next();
74
list.add(header.getTempo().clone(TuxGuitar.instance().getSongManager().getFactory()));
78
private void setTempos(List tempos){
79
int length = tempos.size();
80
if(length != TuxGuitar.instance().getSongManager().getSong().countMeasureHeaders()){
83
for(int i =0; i < length; i ++){
84
TGTempo tempo = ((TGTempo)tempos.get(i)).clone(TuxGuitar.instance().getSongManager().getFactory());
85
TuxGuitar.instance().getSongManager().changeTempo(TuxGuitar.instance().getSongManager().getMeasureHeader(i + 1),tempo);
87
TuxGuitar.instance().fireUpdate();