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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/duration/ChangeTupletoDurationAction.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
/*
 
2
 * Created on 17-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.gui.actions.duration;
 
8
 
 
9
import org.eclipse.swt.events.KeyEvent;
 
10
import org.eclipse.swt.events.TypedEvent;
 
11
import org.herac.tuxguitar.gui.TuxGuitar;
 
12
import org.herac.tuxguitar.gui.actions.Action;
 
13
import org.herac.tuxguitar.gui.editors.tab.Caret;
 
14
import org.herac.tuxguitar.gui.undo.undoables.measure.UndoableMeasureGeneric;
 
15
import org.herac.tuxguitar.song.models.TGDuration;
 
16
import org.herac.tuxguitar.song.models.TGTupleto;
 
17
 
 
18
/**
 
19
 * @author julian
 
20
 *
 
21
 * TODO To change the template for this generated type comment go to
 
22
 * Window - Preferences - Java - Code Style - Code Templates
 
23
 */
 
24
public class ChangeTupletoDurationAction extends Action{
 
25
        public static final String NAME = "action.note.duration.change-tupleto";
 
26
        
 
27
        public ChangeTupletoDurationAction() {
 
28
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
 
29
        }
 
30
        
 
31
        protected int execute(TypedEvent e){
 
32
                //comienza el undoable
 
33
                UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
 
34
                
 
35
                boolean isKeyEvent = false;
 
36
                if(e instanceof KeyEvent){
 
37
                        isKeyEvent = true;
 
38
                }
 
39
                if(!isKeyEvent){
 
40
                        TGTupleto tupleto = defaultTupleto();
 
41
                        if(e.widget.getData() != null && e.widget.getData() instanceof TGTupleto){
 
42
                                tupleto = (TGTupleto)e.widget.getData();
 
43
                        }
 
44
                        
 
45
                        if(getSelectedDuration().getTupleto().isEqual(tupleto)){
 
46
                                setTupleto(noTupleto());
 
47
                        }else{
 
48
                                setTupleto(tupleto);
 
49
                        }
 
50
                }
 
51
                else{
 
52
                        if(getSelectedDuration().getTupleto().isEqual(TGTupleto.NORMAL)){
 
53
                                setTupleto(defaultTupleto());
 
54
                        }else{
 
55
                                setTupleto(noTupleto());
 
56
                        }
 
57
                }
 
58
                setDurations();
 
59
                
 
60
                //termia el undoable
 
61
                addUndoableEdit(undoable.endUndo());
 
62
                
 
63
                return 0;
 
64
        }
 
65
        
 
66
        private TGTupleto noTupleto(){
 
67
                TGTupleto tupleto = getSongManager().getFactory().newTupleto();
 
68
                tupleto.setEnters(1);
 
69
                tupleto.setTimes(1);
 
70
                return tupleto;
 
71
        }
 
72
        
 
73
        private TGTupleto defaultTupleto(){
 
74
                TGTupleto tupleto = getSongManager().getFactory().newTupleto();
 
75
                tupleto.setEnters(3);
 
76
                tupleto.setTimes(2);
 
77
                return tupleto;
 
78
        }
 
79
        
 
80
        private void setTupleto(TGTupleto tupleto){
 
81
                getSelectedDuration().getTupleto().setEnters(tupleto.getEnters());
 
82
                getSelectedDuration().getTupleto().setTimes(tupleto.getTimes());
 
83
        }
 
84
        
 
85
        private void setDurations() {
 
86
                Caret caret = getEditor().getTablature().getCaret();
 
87
                caret.changeDuration(getSelectedDuration().clone(getSongManager().getFactory()));
 
88
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
89
                fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());
 
90
        }
 
91
        
 
92
        public TGDuration getSelectedDuration(){
 
93
                return getEditor().getTablature().getCaret().getDuration();
 
94
        }
 
95
}