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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/undo/undoables/custom/UndoableChangeMarker.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.custom;
 
2
 
 
3
import org.herac.tuxguitar.gui.TuxGuitar;
 
4
import org.herac.tuxguitar.gui.marker.MarkerList;
 
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.models.TGMarker;
 
10
 
 
11
public class UndoableChangeMarker implements UndoableEdit{
 
12
        private int doAction;
 
13
        private UndoableCaretHelper undoCaret;
 
14
        private UndoableCaretHelper redoCaret;
 
15
        private TGMarker undoMarker;
 
16
        private TGMarker redoMarker;
 
17
        
 
18
        private UndoableChangeMarker(){
 
19
                super();
 
20
        }
 
21
        
 
22
        public void redo() throws CannotRedoException {
 
23
                if(!canRedo()){
 
24
                        throw new CannotRedoException();
 
25
                }
 
26
                if(this.redoMarker != null){
 
27
                        TuxGuitar.instance().getSongManager().updateMarker(this.redoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
 
28
                        MarkerList.instance().update(true);
 
29
                }else if(this.undoMarker != null){
 
30
                        TuxGuitar.instance().getSongManager().removeMarker(this.undoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
 
31
                        MarkerList.instance().update(false);
 
32
                }
 
33
                this.redoCaret.update();
 
34
                this.doAction = UNDO_ACTION;
 
35
        }
 
36
        
 
37
        public void undo() throws CannotUndoException {
 
38
                if(!canUndo()){
 
39
                        throw new CannotUndoException();
 
40
                }
 
41
                if(this.undoMarker != null){
 
42
                        TuxGuitar.instance().getSongManager().updateMarker(this.undoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
 
43
                        MarkerList.instance().update(true);
 
44
                }else if(this.redoMarker != null){
 
45
                        TuxGuitar.instance().getSongManager().removeMarker(this.redoMarker.clone(TuxGuitar.instance().getSongManager().getFactory()));
 
46
                        MarkerList.instance().update(false);
 
47
                }
 
48
                this.undoCaret.update();
 
49
                this.doAction = REDO_ACTION;
 
50
        }
 
51
        
 
52
        public boolean canRedo() {
 
53
                return (this.doAction == REDO_ACTION);
 
54
        }
 
55
        
 
56
        public boolean canUndo() {
 
57
                return (this.doAction == UNDO_ACTION);
 
58
        }
 
59
        
 
60
        public static UndoableChangeMarker startUndo(TGMarker marker){
 
61
                UndoableChangeMarker undoable = new UndoableChangeMarker();
 
62
                undoable.doAction = UNDO_ACTION;
 
63
                undoable.undoCaret = new UndoableCaretHelper();
 
64
                undoable.undoMarker = (marker == null)?null:(TGMarker)marker.clone(TuxGuitar.instance().getSongManager().getFactory());
 
65
                
 
66
                return undoable;
 
67
        }
 
68
        
 
69
        public UndoableChangeMarker endUndo(TGMarker marker){
 
70
                this.redoCaret = new UndoableCaretHelper();
 
71
                this.redoMarker = (marker == null)?null:(TGMarker)marker.clone(TuxGuitar.instance().getSongManager().getFactory());
 
72
                return this;
 
73
        }
 
74
}