~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/undo/undoables/measure/UndoableInsertMeasure.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.gui.undo.undoables.measure;
 
2
 
 
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;
 
11
 
 
12
public class UndoableInsertMeasure implements UndoableEdit{
 
13
        private int doAction;
 
14
        private UndoableCaretHelper undoCaret;
 
15
        private UndoableCaretHelper redoCaret;
 
16
        private TGSongSegment tracksMeasures;
 
17
        private long insertPosition;
 
18
        private int toTrack;
 
19
        private int copyCount;
 
20
        private int fromNumber;
 
21
        private long theMove;
 
22
        
 
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();
 
29
        }
 
30
        
 
31
        public void redo() throws CannotRedoException {
 
32
                if(!canRedo()){
 
33
                        throw new CannotRedoException();
 
34
                }
 
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();
 
39
                
 
40
                this.doAction = UNDO_ACTION;
 
41
        }
 
42
        
 
43
        public void undo() throws CannotUndoException {
 
44
                if(!canUndo()){
 
45
                        throw new CannotUndoException();
 
46
                }
 
47
                for(int i = 0;i < this.copyCount;i ++){
 
48
                        TuxGuitar.instance().getSongManager().removeMeasure(this.insertPosition);
 
49
                }
 
50
                TuxGuitar.instance().fireUpdate();
 
51
                this.undoCaret.update();
 
52
                
 
53
                this.doAction = REDO_ACTION;
 
54
        }
 
55
        
 
56
        public boolean canRedo() {
 
57
                return (this.doAction == REDO_ACTION);
 
58
        }
 
59
        
 
60
        public boolean canUndo() {
 
61
                return (this.doAction == UNDO_ACTION);
 
62
        }
 
63
        
 
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;
 
70
                return this;
 
71
        }
 
72
        
 
73
        private static Caret getCaret(){
 
74
                return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
 
75
        }
 
76
        
 
77
}