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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/effects/GraceEditor.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
package org.herac.tuxguitar.gui.effects;
 
2
 
 
3
import org.eclipse.swt.SWT;
 
4
import org.eclipse.swt.events.SelectionAdapter;
 
5
import org.eclipse.swt.events.SelectionEvent;
 
6
import org.eclipse.swt.layout.GridData;
 
7
import org.eclipse.swt.layout.GridLayout;
 
8
import org.eclipse.swt.widgets.Button;
 
9
import org.eclipse.swt.widgets.Composite;
 
10
import org.eclipse.swt.widgets.Group;
 
11
import org.eclipse.swt.widgets.Label;
 
12
import org.eclipse.swt.widgets.Shell;
 
13
import org.eclipse.swt.widgets.Spinner;
 
14
import org.herac.tuxguitar.gui.SystemImages;
 
15
import org.herac.tuxguitar.gui.TuxGuitar;
 
16
import org.herac.tuxguitar.song.models.Duration;
 
17
import org.herac.tuxguitar.song.models.Note;
 
18
import org.herac.tuxguitar.song.models.VelocityValues;
 
19
import org.herac.tuxguitar.song.models.effects.GraceEffect;
 
20
 
 
21
public class GraceEditor extends SelectionAdapter{
 
22
 
 
23
        public static final int WIDTH = 400;
 
24
        
 
25
        public static final int HEIGHT = 0;
 
26
                
 
27
        private Spinner fretSpinner;
 
28
        private Button deadButton;
 
29
        private Button beforeBeatButton;
 
30
        private Button onBeatButton;
 
31
        private Button durationButton1;
 
32
        private Button durationButton2;
 
33
        private Button durationButton3;
 
34
        private Button pppButton;
 
35
        private Button ppButton;
 
36
        private Button pButton;
 
37
        private Button mpButton;
 
38
        private Button mfButton;
 
39
        private Button fButton;
 
40
        private Button ffButton;
 
41
        private Button fffButton;       
 
42
        private Button noneButton;
 
43
        private Button slideButton;
 
44
        private Button bendButton;
 
45
        private Button hammerButton;
 
46
        
 
47
        private GraceEffect result;
 
48
        
 
49
        public GraceEditor(){
 
50
                
 
51
        }
 
52
        
 
53
        private static final int LAYOUT_COLUMNS = 2;
 
54
        
 
55
        public GraceEffect show(final Note note){
 
56
                final Shell shell = TuxGuitar.instance().getShell();
 
57
                final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
58
 
 
59
        dialog.setLayout(new GridLayout());
 
60
        dialog.setText(TuxGuitar.getProperty("effects.grace-editor"));
 
61
        
 
62
        
 
63
        Composite composite = new Composite(dialog,SWT.NONE);
 
64
        composite.setLayout(new GridLayout(LAYOUT_COLUMNS,false));
 
65
        composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
66
        
 
67
        int horizontalSpan = 2;
 
68
        
 
69
        //-----defaults-------------------------------------------------
 
70
                boolean dead = false;
 
71
                boolean onBeat = false;
 
72
                int fret = note.getValue();
 
73
                int duration = 1;
 
74
                int dynamic = VelocityValues.DEFAULT;
 
75
                int transition = GraceEffect.TRANSITION_NONE;
 
76
        if(note.getEffect().isGrace()){         
 
77
                dead = note.getEffect().getGrace().isDead();
 
78
                fret = note.getEffect().getGrace().getFret();
 
79
                onBeat = note.getEffect().getGrace().isOnBeat();
 
80
                duration = note.getEffect().getGrace().getDuration();
 
81
                dynamic = note.getEffect().getGrace().getDynamic();
 
82
                transition = note.getEffect().getGrace().getTransition();
 
83
        }        
 
84
        //---------------------------------------------------
 
85
        //------------------NOTE-----------------------------
 
86
        //---------------------------------------------------
 
87
        Group noteGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("note"));        
 
88
        noteGroup.setLayout(new GridLayout(2,false));
 
89
        
 
90
        Label fretLabel = new Label(noteGroup,SWT.NONE);
 
91
        
 
92
        fretLabel.setText(TuxGuitar.getProperty("fret") + ": ");
 
93
        //fretLabel.setLayoutData(makeGridData(1));
 
94
        
 
95
        fretSpinner = new Spinner(noteGroup,SWT.BORDER);
 
96
        fretSpinner.setLayoutData(makeGridData(1));
 
97
        fretSpinner.setSelection(fret);
 
98
        
 
99
        deadButton = new Button(noteGroup,SWT.CHECK);
 
100
        deadButton.setText(TuxGuitar.getProperty("note.deadnote"));
 
101
        deadButton.setLayoutData(makeGridData(2));
 
102
        deadButton.setSelection(dead);
 
103
        //---------------------------------------------------
 
104
        //------------------POSITION--------------------------
 
105
        //---------------------------------------------------
 
106
        Group positionGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("position"));        
 
107
        positionGroup.setLayout(new GridLayout());
 
108
        
 
109
        beforeBeatButton = new Button(positionGroup,SWT.RADIO);
 
110
        beforeBeatButton.setText(TuxGuitar.getProperty("effects.grace.before-beat"));
 
111
        beforeBeatButton.setLayoutData(makeGridData(1));
 
112
        beforeBeatButton.setSelection(!onBeat);
 
113
        
 
114
        onBeatButton = new Button(positionGroup,SWT.RADIO);
 
115
        onBeatButton.setText(TuxGuitar.getProperty("effects.grace.on-beat"));
 
116
        onBeatButton.setLayoutData(makeGridData(1));
 
117
        onBeatButton.setSelection(onBeat);
 
118
        //---------------------------------------------------
 
119
        //------------------DURATION-------------------------
 
120
        //---------------------------------------------------
 
121
        Group durationGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("duration"));
 
122
        durationGroup.setLayout(new GridLayout(3,false));
 
123
        
 
124
        durationButton1 = new Button(durationGroup,SWT.RADIO);
 
125
        durationButton1.setImage(SystemImages.getDuration(Duration.SIXTY_FOURTH));
 
126
        durationButton1.setLayoutData(makeGridData(1));
 
127
        durationButton1.setSelection(duration == 1);
 
128
        
 
129
        durationButton2 = new Button(durationGroup,SWT.RADIO);
 
130
        durationButton2.setImage(SystemImages.getDuration(Duration.THIRTY_SECOND));
 
131
        durationButton2.setLayoutData(makeGridData(1));
 
132
        durationButton2.setSelection(duration == 2);
 
133
        
 
134
        durationButton3 = new Button(durationGroup,SWT.RADIO);
 
135
        durationButton3.setImage(SystemImages.getDuration(Duration.SIXTEENTH));
 
136
        durationButton3.setLayoutData(makeGridData(1));        
 
137
        durationButton3.setSelection(duration == 3);
 
138
        
 
139
        horizontalSpan = 1;
 
140
        //---------------------------------------------------
 
141
        //------------------DYNAMIC--------------------------
 
142
        //---------------------------------------------------
 
143
        Group dynamicGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("dynamic"));        
 
144
        dynamicGroup.setLayout(new GridLayout(2,false));
 
145
        
 
146
        pppButton = new Button(dynamicGroup,SWT.RADIO);
 
147
        pppButton.setImage(SystemImages.DYNAMIC_PIANO_PIANISSIMO);
 
148
        pppButton.setLayoutData(makeGridData(1));
 
149
        pppButton.setSelection(dynamic == VelocityValues.PIANO_PIANISSIMO);
 
150
        
 
151
        mfButton = new Button(dynamicGroup,SWT.RADIO);
 
152
        mfButton.setImage(SystemImages.DYNAMIC_MEZZO_FORTE);
 
153
        mfButton.setLayoutData(makeGridData(1));
 
154
        mfButton.setSelection(dynamic == VelocityValues.MEZZO_FORTE);
 
155
        
 
156
        ppButton = new Button(dynamicGroup,SWT.RADIO);
 
157
        ppButton.setImage(SystemImages.DYNAMIC_PIANISSIMO);
 
158
        ppButton.setLayoutData(makeGridData(1));
 
159
        ppButton.setSelection(dynamic == VelocityValues.PIANISSIMO);
 
160
        
 
161
        fButton = new Button(dynamicGroup,SWT.RADIO);
 
162
        fButton.setImage(SystemImages.DYNAMIC_FORTE);
 
163
        fButton.setLayoutData(makeGridData(1));
 
164
        fButton.setSelection(dynamic == VelocityValues.FORTE);
 
165
        
 
166
        pButton = new Button(dynamicGroup,SWT.RADIO);
 
167
        pButton.setImage(SystemImages.DYNAMIC_PIANO);
 
168
        pButton.setLayoutData(makeGridData(1));        
 
169
        pButton.setSelection(dynamic == VelocityValues.PIANO);
 
170
        
 
171
        ffButton = new Button(dynamicGroup,SWT.RADIO);
 
172
        ffButton.setImage(SystemImages.DYNAMIC_FORTISSIMO);
 
173
        ffButton.setLayoutData(makeGridData(1));
 
174
        ffButton.setSelection(dynamic == VelocityValues.FORTISSIMO);
 
175
        
 
176
        mpButton = new Button(dynamicGroup,SWT.RADIO);
 
177
        mpButton.setImage(SystemImages.DYNAMIC_MEZZO_PIANO);
 
178
        mpButton.setLayoutData(makeGridData(1));    
 
179
        mpButton.setSelection(dynamic == VelocityValues.MEZZO_PIANO);
 
180
        
 
181
        fffButton = new Button(dynamicGroup,SWT.RADIO);
 
182
        fffButton.setImage(SystemImages.DYNAMIC_FORTE_FORTISSIMO);
 
183
        fffButton.setLayoutData(makeGridData(1));      
 
184
        fffButton.setSelection(dynamic == VelocityValues.FORTE_FORTISSIMO);
 
185
        //---------------------------------------------------
 
186
        //------------------TRANSITION-----------------------
 
187
        //---------------------------------------------------
 
188
        Group transitionGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("effects.grace.transition"));        
 
189
        transitionGroup.setLayout(new GridLayout());
 
190
        
 
191
        noneButton = new Button(transitionGroup,SWT.RADIO);
 
192
        noneButton.setText(TuxGuitar.getProperty("effects.grace.transition-none"));
 
193
        noneButton.setLayoutData(makeGridData(1));
 
194
        noneButton.setSelection(transition == GraceEffect.TRANSITION_NONE);
 
195
        
 
196
        bendButton = new Button(transitionGroup,SWT.RADIO);
 
197
        bendButton.setText(TuxGuitar.getProperty("effects.grace.transition-bend"));
 
198
        bendButton.setLayoutData(makeGridData(1));              
 
199
        bendButton.setSelection(transition == GraceEffect.TRANSITION_BEND);
 
200
        
 
201
        slideButton = new Button(transitionGroup,SWT.RADIO);
 
202
        slideButton.setText(TuxGuitar.getProperty("effects.grace.transition-slide"));
 
203
        slideButton.setLayoutData(makeGridData(1));        
 
204
        slideButton.setSelection(transition == GraceEffect.TRANSITION_SLIDE);
 
205
        
 
206
        hammerButton = new Button(transitionGroup,SWT.RADIO);
 
207
        hammerButton.setText(TuxGuitar.getProperty("effects.grace.transition-hammer"));
 
208
        hammerButton.setLayoutData(makeGridData(1));                
 
209
        hammerButton.setSelection(transition == GraceEffect.TRANSITION_HAMMER);
 
210
        //---------------------------------------------------
 
211
        //------------------BUTTONS--------------------------
 
212
        //---------------------------------------------------
 
213
        Composite buttons = new Composite(dialog, SWT.NONE);
 
214
        buttons.setLayout(new GridLayout(3,false));
 
215
        buttons.setLayoutData(new GridData(SWT.END,SWT.BOTTOM,true,true));      
 
216
        
 
217
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
 
218
        data.minimumWidth = 80;
 
219
        data.minimumHeight = 25;     
 
220
        
 
221
        final Button buttonOK = new Button(buttons, SWT.PUSH);
 
222
        buttonOK.setText(TuxGuitar.getProperty("ok"));        
 
223
        buttonOK.setLayoutData(data);
 
224
        buttonOK.addSelectionListener(new SelectionAdapter() {
 
225
            public void widgetSelected(SelectionEvent arg0) {   
 
226
                result = getGrace();
 
227
                dialog.dispose();
 
228
            }
 
229
        });
 
230
 
 
231
        Button buttonClean = new Button(buttons, SWT.PUSH);
 
232
        buttonClean.setText(TuxGuitar.getProperty("clean"));
 
233
        buttonClean.setLayoutData(data);
 
234
        buttonClean.addSelectionListener(new SelectionAdapter() {
 
235
            public void widgetSelected(SelectionEvent arg0) {
 
236
                result = null;
 
237
                dialog.dispose();
 
238
            }
 
239
        });        
 
240
        
 
241
        Button buttonCancel = new Button(buttons, SWT.PUSH);
 
242
        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
243
        buttonCancel.setLayoutData(data);
 
244
        buttonCancel.addSelectionListener(new SelectionAdapter() {
 
245
            public void widgetSelected(SelectionEvent arg0) {
 
246
                result = note.getEffect().getGrace();
 
247
                dialog.dispose();
 
248
            }
 
249
        });
 
250
 
 
251
        dialog.setMinimumSize(360,360);
 
252
        dialog.pack();
 
253
        dialog.open();
 
254
 
 
255
        int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
 
256
        int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
 
257
        dialog.setLocation(x, y);
 
258
        
 
259
                while (!dialog.isDisposed()) {
 
260
            if (!dialog.getDisplay().readAndDispatch()) {
 
261
                dialog.getDisplay().sleep();
 
262
            }
 
263
        }               
 
264
        
 
265
                return result;
 
266
        }
 
267
        
 
268
        private GridData resizeData(GridData data,int minWidth){
 
269
                data.minimumWidth = minWidth;
 
270
                
 
271
                return data;
 
272
        }
 
273
        
 
274
        private Group makeGroup(Composite parent,int horizontalSpan,String text){
 
275
        Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
 
276
        group.setLayoutData(makeGridData(horizontalSpan));
 
277
        group.setText(text);
 
278
        
 
279
        return group;
 
280
        }
 
281
        
 
282
        
 
283
        private GridData makeGridData(int horizontalSpan){
 
284
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);              
 
285
                data.horizontalSpan = horizontalSpan;           
 
286
                return data;
 
287
        }       
 
288
        
 
289
        public GraceEffect getGrace(){                          
 
290
                int fret = fretSpinner.getSelection();                  
 
291
                boolean dead = deadButton.getSelection();
 
292
                boolean onBeat = onBeatButton.getSelection();
 
293
                
 
294
                //duration
 
295
                int duration = 0;
 
296
                if(durationButton1.getSelection()){
 
297
                        duration = 1;
 
298
                }else if(durationButton2.getSelection()){
 
299
                        duration = 2;
 
300
                }if(durationButton3.getSelection()){
 
301
                        duration = 3;
 
302
                }
 
303
                //velocity
 
304
                int dynamic = 0;
 
305
                if(pppButton.getSelection()){
 
306
                        dynamic = VelocityValues.PIANO_PIANISSIMO;              
 
307
                }else if(ppButton.getSelection()){
 
308
                        dynamic = VelocityValues.PIANISSIMO;            
 
309
                }else if(pButton.getSelection()){
 
310
                        dynamic = VelocityValues.PIANO;         
 
311
                }else if(mpButton.getSelection()){
 
312
                        dynamic = VelocityValues.MEZZO_PIANO;                   
 
313
                }else if(mfButton.getSelection()){
 
314
                        dynamic = VelocityValues.MEZZO_FORTE;           
 
315
                }else if(fButton.getSelection()){
 
316
                        dynamic = VelocityValues.FORTE;         
 
317
                }else if(ffButton.getSelection()){
 
318
                        dynamic = VelocityValues.FORTISSIMO;            
 
319
                }else if(fffButton.getSelection()){
 
320
                        dynamic = VelocityValues.FORTE_FORTISSIMO;
 
321
                }
 
322
                
 
323
                int transition = 0;
 
324
                if(noneButton.getSelection()){
 
325
                        transition = GraceEffect.TRANSITION_NONE;
 
326
                }else if(slideButton.getSelection()){
 
327
                        transition = GraceEffect.TRANSITION_SLIDE;
 
328
                }else if(bendButton.getSelection()){
 
329
                        transition = GraceEffect.TRANSITION_BEND;
 
330
                }else if(hammerButton.getSelection()){
 
331
                        transition = GraceEffect.TRANSITION_HAMMER;
 
332
                }  
 
333
                
 
334
                return new GraceEffect(fret,duration,dynamic,transition,onBeat,dead);
 
335
        }       
 
336
        
 
337
 
 
338
}