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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/effects/GraceEditor.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.editors.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.TuxGuitar;
 
15
import org.herac.tuxguitar.gui.util.DialogUtils;
 
16
import org.herac.tuxguitar.song.models.TGDuration;
 
17
import org.herac.tuxguitar.song.models.TGNote;
 
18
import org.herac.tuxguitar.song.models.TGVelocities;
 
19
import org.herac.tuxguitar.song.models.effects.TGEffectGrace;
 
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
        protected TGEffectGrace result;
 
48
        
 
49
        public GraceEditor(){
 
50
                super();
 
51
        }
 
52
        
 
53
        private static final int LAYOUT_COLUMNS = 2;
 
54
        
 
55
        public TGEffectGrace show(final TGNote note){
 
56
                final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
57
                
 
58
                dialog.setLayout(new GridLayout());
 
59
                dialog.setText(TuxGuitar.getProperty("effects.grace-editor"));
 
60
                dialog.setMinimumSize(360,360);
 
61
                
 
62
                Composite composite = new Composite(dialog,SWT.NONE);
 
63
                composite.setLayout(new GridLayout(LAYOUT_COLUMNS,false));
 
64
                composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
65
                
 
66
                int horizontalSpan = 2;
 
67
                
 
68
                //-----defaults-------------------------------------------------
 
69
                boolean dead = false;
 
70
                boolean onBeat = false;
 
71
                int fret = note.getValue();
 
72
                int duration = 1;
 
73
                int dynamic = TGVelocities.DEFAULT;
 
74
                int transition = TGEffectGrace.TRANSITION_NONE;
 
75
                if(note.getEffect().isGrace()){
 
76
                        dead = note.getEffect().getGrace().isDead();
 
77
                        fret = note.getEffect().getGrace().getFret();
 
78
                        onBeat = note.getEffect().getGrace().isOnBeat();
 
79
                        duration = note.getEffect().getGrace().getDuration();
 
80
                        dynamic = note.getEffect().getGrace().getDynamic();
 
81
                        transition = note.getEffect().getGrace().getTransition();
 
82
                }
 
83
                //---------------------------------------------------
 
84
                //------------------NOTE-----------------------------
 
85
                //---------------------------------------------------
 
86
                Group noteGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("note"));
 
87
                noteGroup.setLayout(new GridLayout(2,false));
 
88
                
 
89
                Label fretLabel = new Label(noteGroup,SWT.NONE);
 
90
                
 
91
                fretLabel.setText(TuxGuitar.getProperty("fret") + ": ");
 
92
                //fretLabel.setLayoutData(makeGridData(1));
 
93
                
 
94
                this.fretSpinner = new Spinner(noteGroup,SWT.BORDER);
 
95
                this.fretSpinner.setLayoutData(makeGridData(1));
 
96
                this.fretSpinner.setSelection(fret);
 
97
                
 
98
                this.deadButton = new Button(noteGroup,SWT.CHECK);
 
99
                this.deadButton.setText(TuxGuitar.getProperty("note.deadnote"));
 
100
                this.deadButton.setLayoutData(makeGridData(2));
 
101
                this.deadButton.setSelection(dead);
 
102
                //---------------------------------------------------
 
103
                //------------------POSITION-------------------------
 
104
                //---------------------------------------------------
 
105
                Group positionGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("position"));
 
106
                positionGroup.setLayout(new GridLayout());
 
107
                
 
108
                this.beforeBeatButton = new Button(positionGroup,SWT.RADIO);
 
109
                this.beforeBeatButton.setText(TuxGuitar.getProperty("effects.grace.before-beat"));
 
110
                this.beforeBeatButton.setLayoutData(makeGridData(1));
 
111
                this.beforeBeatButton.setSelection(!onBeat);
 
112
                
 
113
                this.onBeatButton = new Button(positionGroup,SWT.RADIO);
 
114
                this.onBeatButton.setText(TuxGuitar.getProperty("effects.grace.on-beat"));
 
115
                this.onBeatButton.setLayoutData(makeGridData(1));
 
116
                this.onBeatButton.setSelection(onBeat);
 
117
                //---------------------------------------------------
 
118
                //------------------DURATION-------------------------
 
119
                //---------------------------------------------------
 
120
                Group durationGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("duration"));
 
121
                durationGroup.setLayout(new GridLayout(3,false));
 
122
                
 
123
                this.durationButton1 = new Button(durationGroup,SWT.RADIO);
 
124
                this.durationButton1.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTY_FOURTH));
 
125
                this.durationButton1.setLayoutData(makeGridData(1));
 
126
                this.durationButton1.setSelection(duration == 1);
 
127
                
 
128
                this.durationButton2 = new Button(durationGroup,SWT.RADIO);
 
129
                this.durationButton2.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.THIRTY_SECOND));
 
130
                this.durationButton2.setLayoutData(makeGridData(1));
 
131
                this.durationButton2.setSelection(duration == 2);
 
132
                
 
133
                this.durationButton3 = new Button(durationGroup,SWT.RADIO);
 
134
                this.durationButton3.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTEENTH));
 
135
                this.durationButton3.setLayoutData(makeGridData(1));
 
136
                this.durationButton3.setSelection(duration == 3);
 
137
                
 
138
                horizontalSpan = 1;
 
139
                //---------------------------------------------------
 
140
                //------------------DYNAMIC--------------------------
 
141
                //---------------------------------------------------
 
142
                Group dynamicGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("dynamic"));
 
143
                dynamicGroup.setLayout(new GridLayout(2,false));
 
144
                
 
145
                this.pppButton = new Button(dynamicGroup,SWT.RADIO);
 
146
                this.pppButton.setImage(TuxGuitar.instance().getIconManager().getDynamicPPP());
 
147
                this.pppButton.setLayoutData(makeGridData(1));
 
148
                this.pppButton.setSelection(dynamic == TGVelocities.PIANO_PIANISSIMO);
 
149
                
 
150
                this.mfButton = new Button(dynamicGroup,SWT.RADIO);
 
151
                this.mfButton.setImage(TuxGuitar.instance().getIconManager().getDynamicMF());
 
152
                this.mfButton.setLayoutData(makeGridData(1));
 
153
                this.mfButton.setSelection(dynamic == TGVelocities.MEZZO_FORTE);
 
154
                
 
155
                this.ppButton = new Button(dynamicGroup,SWT.RADIO);
 
156
                this.ppButton.setImage(TuxGuitar.instance().getIconManager().getDynamicPP());
 
157
                this.ppButton.setLayoutData(makeGridData(1));
 
158
                this.ppButton.setSelection(dynamic == TGVelocities.PIANISSIMO);
 
159
                
 
160
                this.fButton = new Button(dynamicGroup,SWT.RADIO);
 
161
                this.fButton.setImage(TuxGuitar.instance().getIconManager().getDynamicF());
 
162
                this.fButton.setLayoutData(makeGridData(1));
 
163
                this.fButton.setSelection(dynamic == TGVelocities.FORTE);
 
164
                
 
165
                this.pButton = new Button(dynamicGroup,SWT.RADIO);
 
166
                this.pButton.setImage(TuxGuitar.instance().getIconManager().getDynamicP());
 
167
                this.pButton.setLayoutData(makeGridData(1));
 
168
                this.pButton.setSelection(dynamic == TGVelocities.PIANO);
 
169
                
 
170
                this.ffButton = new Button(dynamicGroup,SWT.RADIO);
 
171
                this.ffButton.setImage(TuxGuitar.instance().getIconManager().getDynamicFF());
 
172
                this.ffButton.setLayoutData(makeGridData(1));
 
173
                this.ffButton.setSelection(dynamic == TGVelocities.FORTISSIMO);
 
174
                
 
175
                this.mpButton = new Button(dynamicGroup,SWT.RADIO);
 
176
                this.mpButton.setImage(TuxGuitar.instance().getIconManager().getDynamicMP());
 
177
                this.mpButton.setLayoutData(makeGridData(1));
 
178
                this.mpButton.setSelection(dynamic == TGVelocities.MEZZO_PIANO);
 
179
                
 
180
                this.fffButton = new Button(dynamicGroup,SWT.RADIO);
 
181
                this.fffButton.setImage(TuxGuitar.instance().getIconManager().getDynamicFFF());
 
182
                this.fffButton.setLayoutData(makeGridData(1));
 
183
                this.fffButton.setSelection(dynamic == TGVelocities.FORTE_FORTISSIMO);
 
184
                //---------------------------------------------------
 
185
                //------------------TRANSITION-----------------------
 
186
                //---------------------------------------------------
 
187
                Group transitionGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("effects.grace.transition"));
 
188
                transitionGroup.setLayout(new GridLayout());
 
189
                
 
190
                this.noneButton = new Button(transitionGroup,SWT.RADIO);
 
191
                this.noneButton.setText(TuxGuitar.getProperty("effects.grace.transition-none"));
 
192
                this.noneButton.setLayoutData(makeGridData(1));
 
193
                this.noneButton.setSelection(transition == TGEffectGrace.TRANSITION_NONE);
 
194
                
 
195
                this.bendButton = new Button(transitionGroup,SWT.RADIO);
 
196
                this.bendButton.setText(TuxGuitar.getProperty("effects.grace.transition-bend"));
 
197
                this.bendButton.setLayoutData(makeGridData(1));
 
198
                this.bendButton.setSelection(transition == TGEffectGrace.TRANSITION_BEND);
 
199
                
 
200
                this.slideButton = new Button(transitionGroup,SWT.RADIO);
 
201
                this.slideButton.setText(TuxGuitar.getProperty("effects.grace.transition-slide"));
 
202
                this.slideButton.setLayoutData(makeGridData(1));
 
203
                this.slideButton.setSelection(transition == TGEffectGrace.TRANSITION_SLIDE);
 
204
                
 
205
                this.hammerButton = new Button(transitionGroup,SWT.RADIO);
 
206
                this.hammerButton.setText(TuxGuitar.getProperty("effects.grace.transition-hammer"));
 
207
                this.hammerButton.setLayoutData(makeGridData(1));
 
208
                this.hammerButton.setSelection(transition == TGEffectGrace.TRANSITION_HAMMER);
 
209
                //---------------------------------------------------
 
210
                //------------------BUTTONS--------------------------
 
211
                //---------------------------------------------------
 
212
                Composite buttons = new Composite(dialog, SWT.NONE);
 
213
                buttons.setLayout(new GridLayout(3,false));
 
214
                buttons.setLayoutData(new GridData(SWT.END,SWT.BOTTOM,true,true));
 
215
                
 
216
                final Button buttonOK = new Button(buttons, SWT.PUSH);
 
217
                buttonOK.setText(TuxGuitar.getProperty("ok"));
 
218
                buttonOK.setLayoutData(getButtonData());
 
219
                buttonOK.addSelectionListener(new SelectionAdapter() {
 
220
                        public void widgetSelected(SelectionEvent arg0) {
 
221
                                GraceEditor.this.result = getGrace();
 
222
                                dialog.dispose();
 
223
                        }
 
224
                });
 
225
                
 
226
                Button buttonClean = new Button(buttons, SWT.PUSH);
 
227
                buttonClean.setText(TuxGuitar.getProperty("clean"));
 
228
                buttonClean.setLayoutData(getButtonData());
 
229
                buttonClean.addSelectionListener(new SelectionAdapter() {
 
230
                        public void widgetSelected(SelectionEvent arg0) {
 
231
                                GraceEditor.this.result = null;
 
232
                                dialog.dispose();
 
233
                        }
 
234
                });
 
235
                
 
236
                Button buttonCancel = new Button(buttons, SWT.PUSH);
 
237
                buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
238
                buttonCancel.setLayoutData(getButtonData());
 
239
                buttonCancel.addSelectionListener(new SelectionAdapter() {
 
240
                        public void widgetSelected(SelectionEvent arg0) {
 
241
                                GraceEditor.this.result = note.getEffect().getGrace();
 
242
                                dialog.dispose();
 
243
                        }
 
244
                });
 
245
                
 
246
                dialog.setDefaultButton( buttonOK );
 
247
                
 
248
                DialogUtils.openDialog(dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
249
                return this.result;
 
250
        }
 
251
        
 
252
        private Group makeGroup(Composite parent,int horizontalSpan,String text){
 
253
                Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
 
254
                group.setLayoutData(makeGridData(horizontalSpan));
 
255
                group.setText(text);
 
256
                
 
257
                return group;
 
258
        }
 
259
        
 
260
        private GridData getButtonData(){
 
261
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
262
                data.minimumWidth = 80;
 
263
                data.minimumHeight = 25;
 
264
                return data;
 
265
        }
 
266
        
 
267
        private GridData makeGridData(int horizontalSpan){
 
268
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
269
                data.horizontalSpan = horizontalSpan;
 
270
                return data;
 
271
        }
 
272
        
 
273
        public TGEffectGrace getGrace(){
 
274
                TGEffectGrace effect = TuxGuitar.instance().getSongManager().getFactory().newEffectGrace();
 
275
                
 
276
                effect.setFret(this.fretSpinner.getSelection());
 
277
                effect.setDead(this.deadButton.getSelection());
 
278
                effect.setOnBeat(this.onBeatButton.getSelection());
 
279
                
 
280
                //duration
 
281
                if(this.durationButton1.getSelection()){
 
282
                        effect.setDuration(1);
 
283
                }else if(this.durationButton2.getSelection()){
 
284
                        effect.setDuration(2);
 
285
                }else if(this.durationButton3.getSelection()){
 
286
                        effect.setDuration(3);
 
287
                }
 
288
                //velocity
 
289
                if(this.pppButton.getSelection()){
 
290
                        effect.setDynamic(TGVelocities.PIANO_PIANISSIMO);
 
291
                }else if(this.ppButton.getSelection()){
 
292
                        effect.setDynamic(TGVelocities.PIANISSIMO);
 
293
                }else if(this.pButton.getSelection()){
 
294
                        effect.setDynamic(TGVelocities.PIANO);
 
295
                }else if(this.mpButton.getSelection()){
 
296
                        effect.setDynamic(TGVelocities.MEZZO_PIANO);
 
297
                }else if(this.mfButton.getSelection()){
 
298
                        effect.setDynamic(TGVelocities.MEZZO_FORTE);
 
299
                }else if(this.fButton.getSelection()){
 
300
                        effect.setDynamic(TGVelocities.FORTE);
 
301
                }else if(this.ffButton.getSelection()){
 
302
                        effect.setDynamic(TGVelocities.FORTISSIMO);
 
303
                }else if(this.fffButton.getSelection()){
 
304
                        effect.setDynamic(TGVelocities.FORTE_FORTISSIMO);
 
305
                }
 
306
                
 
307
                //transition
 
308
                if(this.noneButton.getSelection()){
 
309
                        effect.setTransition(TGEffectGrace.TRANSITION_NONE);
 
310
                }else if(this.slideButton.getSelection()){
 
311
                        effect.setTransition(TGEffectGrace.TRANSITION_SLIDE);
 
312
                }else if(this.bendButton.getSelection()){
 
313
                        effect.setTransition(TGEffectGrace.TRANSITION_BEND);
 
314
                }else if(this.hammerButton.getSelection()){
 
315
                        effect.setTransition(TGEffectGrace.TRANSITION_HAMMER);
 
316
                }
 
317
                
 
318
                return effect;
 
319
        }
 
320
}