1
package org.herac.tuxguitar.gui.effects;
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;
21
public class GraceEditor extends SelectionAdapter{
23
public static final int WIDTH = 400;
25
public static final int HEIGHT = 0;
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;
47
private GraceEffect result;
53
private static final int LAYOUT_COLUMNS = 2;
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);
59
dialog.setLayout(new GridLayout());
60
dialog.setText(TuxGuitar.getProperty("effects.grace-editor"));
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));
67
int horizontalSpan = 2;
69
//-----defaults-------------------------------------------------
71
boolean onBeat = false;
72
int fret = note.getValue();
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();
84
//---------------------------------------------------
85
//------------------NOTE-----------------------------
86
//---------------------------------------------------
87
Group noteGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("note"));
88
noteGroup.setLayout(new GridLayout(2,false));
90
Label fretLabel = new Label(noteGroup,SWT.NONE);
92
fretLabel.setText(TuxGuitar.getProperty("fret") + ": ");
93
//fretLabel.setLayoutData(makeGridData(1));
95
fretSpinner = new Spinner(noteGroup,SWT.BORDER);
96
fretSpinner.setLayoutData(makeGridData(1));
97
fretSpinner.setSelection(fret);
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());
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);
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));
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);
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);
134
durationButton3 = new Button(durationGroup,SWT.RADIO);
135
durationButton3.setImage(SystemImages.getDuration(Duration.SIXTEENTH));
136
durationButton3.setLayoutData(makeGridData(1));
137
durationButton3.setSelection(duration == 3);
140
//---------------------------------------------------
141
//------------------DYNAMIC--------------------------
142
//---------------------------------------------------
143
Group dynamicGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("dynamic"));
144
dynamicGroup.setLayout(new GridLayout(2,false));
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);
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);
156
ppButton = new Button(dynamicGroup,SWT.RADIO);
157
ppButton.setImage(SystemImages.DYNAMIC_PIANISSIMO);
158
ppButton.setLayoutData(makeGridData(1));
159
ppButton.setSelection(dynamic == VelocityValues.PIANISSIMO);
161
fButton = new Button(dynamicGroup,SWT.RADIO);
162
fButton.setImage(SystemImages.DYNAMIC_FORTE);
163
fButton.setLayoutData(makeGridData(1));
164
fButton.setSelection(dynamic == VelocityValues.FORTE);
166
pButton = new Button(dynamicGroup,SWT.RADIO);
167
pButton.setImage(SystemImages.DYNAMIC_PIANO);
168
pButton.setLayoutData(makeGridData(1));
169
pButton.setSelection(dynamic == VelocityValues.PIANO);
171
ffButton = new Button(dynamicGroup,SWT.RADIO);
172
ffButton.setImage(SystemImages.DYNAMIC_FORTISSIMO);
173
ffButton.setLayoutData(makeGridData(1));
174
ffButton.setSelection(dynamic == VelocityValues.FORTISSIMO);
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);
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());
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);
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);
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);
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));
217
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
218
data.minimumWidth = 80;
219
data.minimumHeight = 25;
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) {
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) {
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();
251
dialog.setMinimumSize(360,360);
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);
259
while (!dialog.isDisposed()) {
260
if (!dialog.getDisplay().readAndDispatch()) {
261
dialog.getDisplay().sleep();
268
private GridData resizeData(GridData data,int minWidth){
269
data.minimumWidth = minWidth;
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));
283
private GridData makeGridData(int horizontalSpan){
284
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
285
data.horizontalSpan = horizontalSpan;
289
public GraceEffect getGrace(){
290
int fret = fretSpinner.getSelection();
291
boolean dead = deadButton.getSelection();
292
boolean onBeat = onBeatButton.getSelection();
296
if(durationButton1.getSelection()){
298
}else if(durationButton2.getSelection()){
300
}if(durationButton3.getSelection()){
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;
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;
334
return new GraceEffect(fret,duration,dynamic,transition,onBeat,dead);