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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/duration/ChangeTupletoDurationAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2007-02-04 01:41:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070204014123-9pv7okph0iaiqkvw
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

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.actions.Action;
 
12
import org.herac.tuxguitar.gui.editors.TablatureEditor;
 
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.Duration;
 
16
import org.herac.tuxguitar.song.models.Tupleto;
 
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(TablatureEditor tablatureEditor) {
 
28
        super(NAME,true,tablatureEditor);       
 
29
    }
 
30
 
 
31
    public boolean doAction(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
            Tupleto tupleto = defaultTupleto();
 
41
            if(e.widget.getData() != null && e.widget.getData() instanceof Tupleto){
 
42
                tupleto = (Tupleto)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(Duration.NO_TUPLETO)){            
 
53
                setTupleto(defaultTupleto());
 
54
            }else{
 
55
                setTupleto(noTupleto());                    
 
56
            }
 
57
        }
 
58
        setDurations();     
 
59
        
 
60
        //termia el undoable
 
61
        getEditor().getUndoManager().addEdit(undoable.endUndo()); 
 
62
        
 
63
        return true;
 
64
    }
 
65
 
 
66
    private Tupleto noTupleto(){
 
67
        return new Tupleto(1,1);
 
68
    }
 
69
    
 
70
    private Tupleto defaultTupleto(){
 
71
        return new Tupleto(3,2);
 
72
    }
 
73
    
 
74
    private void setTupleto(Tupleto tupleto){
 
75
        getSelectedDuration().getTupleto().setEnters(tupleto.getEnters());
 
76
        getSelectedDuration().getTupleto().setTimes(tupleto.getTimes());        
 
77
    }
 
78
    
 
79
    private void setDurations() {                
 
80
        Caret caret = getEditor().getTablature().getCaret();            
 
81
        caret.changeDuration((Duration)getSelectedDuration().clone());
 
82
        fireUpdate(getEditor().getTablature().getCaret().getMeasureCoords().getMeasure().getNumber());
 
83
        redraw();        
 
84
    }    
 
85
    
 
86
    public Duration getSelectedDuration(){
 
87
        return getEditor().getTablature().getCaret().getDuration();
 
88
    }    
 
89
 
 
90
}