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.effects.TrillEffect;
20
public class TrillEditor extends SelectionAdapter{
22
public static final int WIDTH = 400;
24
public static final int HEIGHT = 0;
26
private Spinner fretSpinner;
27
private Button sixtyFourthButton;
28
private Button thirtySecondButton;
29
private Button sixTeenthButton;
31
private TrillEffect result;
37
public TrillEffect show(final Note note){
38
final Shell shell = TuxGuitar.instance().getShell();
39
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
41
dialog.setLayout(new GridLayout());
42
dialog.setText(TuxGuitar.getProperty("effects.trill-editor"));
45
Composite composite = new Composite(dialog,SWT.NONE);
46
composite.setLayout(new GridLayout());
47
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
49
int horizontalSpan = 2;
51
//-----defaults-------------------------------------------------
52
int fret = note.getValue();
53
Duration duration = new Duration(Duration.SIXTEENTH);
54
if(note.getEffect().isTrill()){
55
fret = note.getEffect().getTrill().getFret();
56
duration = note.getEffect().getTrill().getDuration();
58
//---------------------------------------------------
59
//------------------NOTE-----------------------------
60
//---------------------------------------------------
61
Group noteGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("note"));
62
noteGroup.setLayout(new GridLayout(2,false));
64
Label fretLabel = new Label(noteGroup,SWT.NONE);
66
fretLabel.setText(TuxGuitar.getProperty("fret") + ": ");
67
//fretLabel.setLayoutData(makeGridData(1));
69
fretSpinner = new Spinner(noteGroup,SWT.BORDER);
70
fretSpinner.setLayoutData(makeGridData(1));
71
fretSpinner.setSelection(fret);
73
//---------------------------------------------------
74
//------------------DURATION-------------------------
75
//---------------------------------------------------
76
Group durationGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("duration"));
77
durationGroup.setLayout(new GridLayout(3,false));
79
sixtyFourthButton = new Button(durationGroup,SWT.RADIO);
80
sixtyFourthButton.setImage(SystemImages.getDuration(Duration.SIXTY_FOURTH));
81
sixtyFourthButton.setLayoutData(makeGridData(1));
82
sixtyFourthButton.setSelection(duration.getValue() == Duration.SIXTY_FOURTH);
84
thirtySecondButton = new Button(durationGroup,SWT.RADIO);
85
thirtySecondButton.setImage(SystemImages.getDuration(Duration.THIRTY_SECOND));
86
thirtySecondButton.setLayoutData(makeGridData(1));
87
thirtySecondButton.setSelection(duration.getValue() == Duration.THIRTY_SECOND);
89
sixTeenthButton = new Button(durationGroup,SWT.RADIO);
90
sixTeenthButton.setImage(SystemImages.getDuration(Duration.SIXTEENTH));
91
sixTeenthButton.setLayoutData(makeGridData(1));
92
sixTeenthButton.setSelection(duration.getValue() == Duration.SIXTEENTH);
94
//---------------------------------------------------
95
//------------------BUTTONS--------------------------
96
//---------------------------------------------------
97
Composite buttons = new Composite(dialog, SWT.NONE);
98
buttons.setLayout(new GridLayout(3,false));
99
buttons.setLayoutData(new GridData(SWT.END,SWT.BOTTOM,true,true));
101
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
102
data.minimumWidth = 80;
103
data.minimumHeight = 25;
105
final Button buttonOK = new Button(buttons, SWT.PUSH);
106
buttonOK.setText(TuxGuitar.getProperty("ok"));
107
buttonOK.setLayoutData(data);
108
buttonOK.addSelectionListener(new SelectionAdapter() {
109
public void widgetSelected(SelectionEvent arg0) {
115
Button buttonClean = new Button(buttons, SWT.PUSH);
116
buttonClean.setText(TuxGuitar.getProperty("clean"));
117
buttonClean.setLayoutData(data);
118
buttonClean.addSelectionListener(new SelectionAdapter() {
119
public void widgetSelected(SelectionEvent arg0) {
125
Button buttonCancel = new Button(buttons, SWT.PUSH);
126
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
127
buttonCancel.setLayoutData(data);
128
buttonCancel.addSelectionListener(new SelectionAdapter() {
129
public void widgetSelected(SelectionEvent arg0) {
130
result = note.getEffect().getTrill();
139
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
140
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
141
dialog.setLocation(x, y);
143
while (!dialog.isDisposed()) {
144
if (!dialog.getDisplay().readAndDispatch()) {
145
dialog.getDisplay().sleep();
152
private GridData resizeData(GridData data,int minWidth){
153
data.minimumWidth = minWidth;
158
private Group makeGroup(Composite parent,int horizontalSpan,String text){
159
Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
160
group.setLayoutData(makeGridData(horizontalSpan));
167
private GridData makeGridData(int horizontalSpan){
168
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
169
data.horizontalSpan = horizontalSpan;
173
public TrillEffect getTrill(){
174
int fret = fretSpinner.getSelection();
176
if(sixtyFourthButton.getSelection()){
177
return new TrillEffect(fret,new Duration(Duration.SIXTY_FOURTH));
178
}else if(thirtySecondButton.getSelection()){
179
return new TrillEffect(fret,new Duration(Duration.THIRTY_SECOND));
180
}if(sixTeenthButton.getSelection()){
181
return new TrillEffect(fret,new Duration(Duration.SIXTEENTH));