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

« back to all changes in this revision

Viewing changes to 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.TracksMeasures;
10
 
 
11
 
public class UndoableInsertMeasure implements UndoableEdit{
12
 
        private int doAction;
13
 
        private UndoableCaretHelper undoCaret;
14
 
        private UndoableCaretHelper redoCaret;          
15
 
        private TracksMeasures tracksMeasures;
16
 
        private long insertPosition;
17
 
        private int copyCount;
18
 
        private int fromNumber;
19
 
        private long theMove;
20
 
 
21
 
        public UndoableInsertMeasure(){
22
 
        Caret caret = getCaret();               
23
 
        this.doAction = UNDO_ACTION;
24
 
        this.undoCaret = new UndoableCaretHelper();         
25
 
        this.insertPosition = caret.getPosition();
26
 
        }       
27
 
        
28
 
        public void redo() throws CannotRedoException { 
29
 
                if(!canRedo()){
30
 
                        throw new CannotRedoException();
31
 
                } 
32
 
                TuxGuitar.instance().getSongManager().insertMeasures((TracksMeasures)tracksMeasures.clone(),fromNumber,theMove);
33
 
                TuxGuitar.instance().fireUpdate();
34
 
                this.redoCaret.update();        
35
 
                
36
 
                this.doAction = UNDO_ACTION;
37
 
        }
38
 
 
39
 
        public void undo() throws CannotUndoException {
40
 
                if(!canUndo()){
41
 
                        throw new CannotUndoException();
42
 
                }                                                       
43
 
                for(int i = 0;i < this.copyCount;i ++){
44
 
                        TuxGuitar.instance().getSongManager().removeMeasure(insertPosition);
45
 
                }
46
 
                TuxGuitar.instance().fireUpdate();
47
 
                this.undoCaret.update();
48
 
                
49
 
                this.doAction = REDO_ACTION;
50
 
        }
51
 
 
52
 
    public boolean canRedo() {
53
 
        return (doAction == REDO_ACTION);
54
 
    }
55
 
 
56
 
    public boolean canUndo() {
57
 
        return (doAction == UNDO_ACTION);
58
 
    }
59
 
 
60
 
    public UndoableInsertMeasure endUndo(TracksMeasures tracksMeasures,int copyCount,int fromNumber,long theMove){
61
 
        this.redoCaret = new UndoableCaretHelper();
62
 
        this.copyCount = copyCount;
63
 
        this.tracksMeasures = tracksMeasures;
64
 
        this.fromNumber = fromNumber;
65
 
        this.theMove = theMove;
66
 
        return this;
67
 
    }
68
 
    
69
 
    private static Caret getCaret(){
70
 
        return TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
71
 
    }  
72
 
 
73
 
}