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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/composition/ChangeTripletFeelAction.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.composition;
8
 
 
9
 
import org.eclipse.swt.SWT;
10
 
import org.eclipse.swt.events.SelectionAdapter;
11
 
import org.eclipse.swt.events.SelectionEvent;
12
 
import org.eclipse.swt.events.TypedEvent;
13
 
import org.eclipse.swt.layout.GridData;
14
 
import org.eclipse.swt.layout.GridLayout;
15
 
import org.eclipse.swt.widgets.Button;
16
 
import org.eclipse.swt.widgets.Composite;
17
 
import org.eclipse.swt.widgets.Shell;
18
 
import org.herac.tuxguitar.gui.TuxGuitar;
19
 
import org.herac.tuxguitar.gui.actions.Action;
20
 
import org.herac.tuxguitar.gui.editors.TablatureEditor;
21
 
import org.herac.tuxguitar.gui.editors.tab.Caret;
22
 
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
23
 
import org.herac.tuxguitar.gui.editors.tab.SongCoords;
24
 
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTripletFeel;
25
 
import org.herac.tuxguitar.song.models.MeasureHeader;
26
 
 
27
 
/**
28
 
 * @author julian
29
 
 *
30
 
 * TODO To change the template for this generated type comment go to
31
 
 * Window - Preferences - Java - Code Style - Code Templates
32
 
 */
33
 
public class ChangeTripletFeelAction extends Action{
34
 
    public static final String NAME = "action.composition.change-triplet-feel";
35
 
    
36
 
    public ChangeTripletFeelAction(TablatureEditor tablatureEditor) {
37
 
        super(NAME,tablatureEditor);       
38
 
    }
39
 
 
40
 
    public boolean doAction(TypedEvent e) {
41
 
        showDialog(getEditor().getTablature().getShell()); 
42
 
        return true;
43
 
    }
44
 
 
45
 
    
46
 
    public void showDialog(Shell shell) {
47
 
        MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
48
 
        if (measure != null) {
49
 
            final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
50
 
 
51
 
            dialog.setLayout(new GridLayout());
52
 
            dialog.setText(TuxGuitar.getProperty("composition.tripletfeel"));
53
 
            
54
 
            //-------------TIME SIGNATURE-----------------------------------------------
55
 
            Composite tripletFeel = new Composite(dialog, SWT.NONE);
56
 
            tripletFeel.setLayout(new GridLayout());
57
 
            tripletFeel.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));   
58
 
            
59
 
            
60
 
            //none
61
 
            final Button tripletFeelNone = new Button(tripletFeel, SWT.RADIO);
62
 
            tripletFeelNone.setText(TuxGuitar.getProperty("composition.tripletfeel.none"));
63
 
            tripletFeelNone.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_NONE);
64
 
            
65
 
            final Button tripletFeelEighth = new Button(tripletFeel, SWT.RADIO);
66
 
            tripletFeelEighth.setText(TuxGuitar.getProperty("composition.tripletfeel.eighth"));
67
 
            tripletFeelEighth.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_EIGHTH);
68
 
            
69
 
            final Button tripletFeelSixteenth = new Button(tripletFeel, SWT.RADIO);
70
 
            tripletFeelSixteenth.setText(TuxGuitar.getProperty("composition.tripletfeel.sixteenth"));
71
 
            tripletFeelSixteenth.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_SIXTEENTH);
72
 
            
73
 
            //--------------------To End Checkbox-------------------------------
74
 
            Composite check = new Composite(dialog, SWT.NONE);
75
 
            check.setLayout(new GridLayout());
76
 
            check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));    
77
 
           
78
 
            final Button toEnd = new Button(check, SWT.CHECK);
79
 
            toEnd.setText(TuxGuitar.getProperty("composition.tripletfeel.to-the-end"));            
80
 
            toEnd.setSelection(true);
81
 
            //------------------BUTTONS--------------------------            
82
 
            Composite buttons = new Composite(dialog, SWT.NONE);
83
 
            buttons.setLayout(new GridLayout(2,false));
84
 
            buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));            
85
 
            
86
 
            GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
87
 
            data.minimumWidth = 80;
88
 
            data.minimumHeight = 25;            
89
 
            
90
 
            
91
 
            final Button buttonOk = new Button(buttons, SWT.PUSH);
92
 
            buttonOk.setText(TuxGuitar.getProperty("ok"));
93
 
            buttonOk.setLayoutData(data);
94
 
            buttonOk.addSelectionListener(new SelectionAdapter() {
95
 
                public void widgetSelected(SelectionEvent arg0) {   
96
 
                    boolean toEndValue = toEnd.getSelection();
97
 
                    int tripletFeel = MeasureHeader.TRIPLET_FEEL_NONE;
98
 
                    if(tripletFeelNone.getSelection()){
99
 
                        tripletFeel = MeasureHeader.TRIPLET_FEEL_NONE;
100
 
                    }else if(tripletFeelEighth.getSelection()){
101
 
                        tripletFeel = MeasureHeader.TRIPLET_FEEL_EIGHTH;
102
 
                    }else if(tripletFeelSixteenth.getSelection()){
103
 
                        tripletFeel = MeasureHeader.TRIPLET_FEEL_SIXTEENTH;
104
 
                    }
105
 
                    setTripletFeel(tripletFeel,toEndValue);
106
 
                    dialog.dispose();
107
 
                }
108
 
            });
109
 
 
110
 
            Button buttonCancel = new Button(buttons, SWT.PUSH);
111
 
            buttonCancel.setLayoutData(data);
112
 
            buttonCancel.setText(TuxGuitar.getProperty("cancel"));
113
 
            buttonCancel.addSelectionListener(new SelectionAdapter() {
114
 
                public void widgetSelected(SelectionEvent arg0) {
115
 
                    dialog.dispose();
116
 
                }
117
 
            });
118
 
 
119
 
            dialog.setMinimumSize(300,0);
120
 
            dialog.pack();
121
 
            dialog.open();
122
 
 
123
 
            int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
124
 
            int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
125
 
            dialog.setLocation(x, y);
126
 
            
127
 
                while (!dialog.isDisposed()) {
128
 
                if (!dialog.getDisplay().readAndDispatch()) {
129
 
                        dialog.getDisplay().sleep();
130
 
                }
131
 
            }
132
 
        }
133
 
    }
134
 
    
135
 
    
136
 
    private void setTripletFeel(int tripletFeel,boolean toEnd){
137
 
        //comienza el undoable
138
 
        UndoableChangeTripletFeel undoable = UndoableChangeTripletFeel.startUndo(); 
139
 
        
140
 
        Caret caret = getEditor().getTablature().getCaret();
141
 
        SongCoords songCoords = caret.getSongCoords();
142
 
        MeasureCoords measure = caret.getMeasureCoords();
143
 
        
144
 
        getSongManager().changeTripletFeel(measure.getMeasure().getStart(),tripletFeel,toEnd);
145
 
        
146
 
        //actualizo la tablatura
147
 
        updateTablature();
148
 
        redraw();                
149
 
        
150
 
        //termia el undoable
151
 
        getEditor().getUndoManager().addEdit(undoable.endUndo(tripletFeel,toEnd));
152
 
    }    
153
 
 
154
 
}