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.Combo;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Group;
12
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.swt.widgets.Shell;
14
import org.herac.tuxguitar.gui.TuxGuitar;
15
import org.herac.tuxguitar.song.models.Note;
16
import org.herac.tuxguitar.song.models.effects.HarmonicEffect;
18
public class HarmonicEditor extends SelectionAdapter{
20
public static final int WIDTH = 400;
22
public static final int HEIGHT = 0;
24
private Button natural;
26
private Button artificial;
28
private Button tapped;
34
private Label artificialLabel;
35
private Combo artificialKey;
37
private Label tappedLeftHand;
38
private Label tappedLeftHandSelection;
39
private Label tappedRightHand;
40
private Combo tappedSelection;
42
private HarmonicEffect result;
44
public HarmonicEditor(){
48
public HarmonicEffect show(final Note note){
49
final Shell shell = TuxGuitar.instance().getShell();
50
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
52
dialog.setLayout(new GridLayout());
53
dialog.setText(TuxGuitar.getProperty("effects.harmonic-editor"));
55
Group group = new Group(dialog, SWT.SHADOW_ETCHED_IN);
56
group.setLayout(new GridLayout());
57
group.setLayoutData(resizeData(new GridData(SWT.FILL,SWT.FILL,true,true),WIDTH));
58
group.setText(TuxGuitar.getProperty("effects.harmonic.type-of-harmonic"));
60
//---------------------------------------------------------------------
61
//------------NATURAL--------------------------------------------------
62
//---------------------------------------------------------------------
63
this.natural = new Button(group,SWT.RADIO);
64
this.natural.setText("[" + HarmonicEffect.KEY_NATURAL + "] " + TuxGuitar.getProperty("effects.harmonic.natural"));
65
this.natural.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true));
66
this.natural.addSelectionListener(this);
67
this.natural.setSelection(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isNatural());
69
//---------------------------------------------------------------------
70
//------------ARTIFICIAL-----------------------------------------------
71
//---------------------------------------------------------------------
72
this.artificial = new Button(group,SWT.RADIO);
73
this.artificial.setText("[" + HarmonicEffect.KEY_ARTIFICIAL + "] " + TuxGuitar.getProperty("effects.harmonic.artificial"));
74
this.artificial.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true));
75
this.artificial.addSelectionListener(this);
76
this.artificial.setSelection(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isArtificial());
78
Composite aComposite = new Composite(group,SWT.NONE);
79
aComposite.setLayout(new GridLayout(2,false));
80
aComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
82
this.artificialLabel = new Label(aComposite,SWT.NONE);
83
this.artificialLabel.setText(TuxGuitar.getProperty("effects.harmonic.artificial.key-offset"));
84
this.artificialLabel.setLayoutData(new GridData(SWT.NONE,SWT.CENTER,false,true));
86
this.artificialKey = new Combo(aComposite,SWT.DROP_DOWN | SWT.READ_ONLY);
87
this.artificialKey.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
88
for(int i = HarmonicEffect.MIN_ARTIFICIAL_OFFSET;i <= HarmonicEffect.MAX_ARTIFICIAL_OFFSET;i ++){
89
this.artificialKey.add(Integer.toString(i));
91
if(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isArtificial()){
92
this.artificialKey.select(note.getEffect().getHarmonic().getData() - HarmonicEffect.MIN_ARTIFICIAL_OFFSET);
94
this.artificialKey.select(-HarmonicEffect.MIN_ARTIFICIAL_OFFSET);
96
//---------------------------------------------------------------------
97
//------------TAPPED---------------------------------------------------
98
//---------------------------------------------------------------------
99
this.tapped = new Button(group,SWT.RADIO);
100
this.tapped.setText("[" + HarmonicEffect.KEY_TAPPED + "] " + TuxGuitar.getProperty("effects.harmonic.tapped"));
101
this.tapped.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true));
102
this.tapped.addSelectionListener(this);
103
this.tapped.setSelection(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isTapped());
105
Composite tComposite = new Composite(group,SWT.NONE);
106
tComposite.setLayout(new GridLayout(2,false));
107
tComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
109
this.tappedLeftHand = new Label(tComposite,SWT.NONE);
110
this.tappedLeftHand.setText(TuxGuitar.getProperty("effects.harmonic.tapped.left-hand") + ":");
111
this.tappedLeftHand.setLayoutData(new GridData(SWT.NONE,SWT.CENTER,false,true));
113
this.tappedLeftHandSelection = new Label(tComposite,SWT.NONE);
114
this.tappedLeftHandSelection.setLayoutData(new GridData(SWT.LEFT,SWT.CENTER,true,true));
115
this.tappedLeftHandSelection.setText(" 1");
117
this.tappedRightHand = new Label(tComposite,SWT.NONE);
118
this.tappedRightHand.setText(TuxGuitar.getProperty("effects.harmonic.tapped.right-hand") + ":");
119
this.tappedRightHand.setLayoutData(new GridData(SWT.NONE,SWT.CENTER,false,true));
121
this.tappedSelection = new Combo(tComposite,SWT.DROP_DOWN | SWT.READ_ONLY);
122
this.tappedSelection.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
123
for(int i = note.getValue();i <= HarmonicEffect.MAX_TAPPED_OFFSET;i ++){
124
this.tappedSelection.add(Integer.toString(i));
126
if(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isTapped()){
127
this.tappedSelection.select(note.getEffect().getHarmonic().getData());
129
this.tappedSelection.select(0);
132
//--------------------------------------------------------------------
133
//------------PINCH---------------------------------------------------
134
//--------------------------------------------------------------------
135
this.pinch = new Button(group,SWT.RADIO);
136
this.pinch.setText("[" + HarmonicEffect.KEY_PINCH + "] " + TuxGuitar.getProperty("effects.harmonic.pinch"));
137
this.pinch.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true));
138
this.pinch.addSelectionListener(this);
139
this.pinch.setSelection(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isPinch());
141
//-------------------------------------------------------------------
142
//------------SEMI---------------------------------------------------
143
//-------------------------------------------------------------------
144
this.semi = new Button(group,SWT.RADIO);
145
this.semi.setText("[" + HarmonicEffect.KEY_SEMI + "] " + TuxGuitar.getProperty("effects.harmonic.semi"));
146
this.semi.setLayoutData(new GridData(SWT.LEFT,SWT.FILL,true,true));
147
this.semi.addSelectionListener(this);
148
this.semi.setSelection(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isSemi());
150
//---------------------------------------------------
151
//------------------BUTTONS--------------------------
152
//---------------------------------------------------
153
Composite buttons = new Composite(dialog, SWT.NONE);
154
buttons.setLayout(new GridLayout(3,false));
155
buttons.setLayoutData(new GridData(SWT.END,SWT.BOTTOM,true,true));
157
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
158
data.minimumWidth = 80;
159
data.minimumHeight = 25;
161
final Button buttonOK = new Button(buttons, SWT.PUSH);
162
buttonOK.setText(TuxGuitar.getProperty("ok"));
163
buttonOK.setLayoutData(data);
164
buttonOK.addSelectionListener(new SelectionAdapter() {
165
public void widgetSelected(SelectionEvent arg0) {
166
result = getHarmonic();
171
Button buttonClean = new Button(buttons, SWT.PUSH);
172
buttonClean.setText(TuxGuitar.getProperty("clean"));
173
buttonClean.setLayoutData(data);
174
buttonClean.addSelectionListener(new SelectionAdapter() {
175
public void widgetSelected(SelectionEvent arg0) {
181
Button buttonCancel = new Button(buttons, SWT.PUSH);
182
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
183
buttonCancel.setLayoutData(data);
184
buttonCancel.addSelectionListener(new SelectionAdapter() {
185
public void widgetSelected(SelectionEvent arg0) {
186
result = note.getEffect().getHarmonic();
192
if(!note.getEffect().isHarmonic()){
193
this.natural.setSelection(true);
199
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
200
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
201
dialog.setLocation(x, y);
203
while (!dialog.isDisposed()) {
204
if (!dialog.getDisplay().readAndDispatch()) {
205
dialog.getDisplay().sleep();
212
private GridData resizeData(GridData data,int minWidth){
213
data.minimumWidth = minWidth;
217
private GridData spanData(GridData data,int horizontalSpan){
218
data.horizontalSpan = horizontalSpan;
222
public void widgetSelected(SelectionEvent e) {
226
public void updateControls(){
227
this.artificialLabel.setEnabled(this.artificial.getSelection());
228
this.artificialKey.setEnabled(this.artificial.getSelection());
229
this.tappedLeftHand.setEnabled(this.tapped.getSelection());
230
this.tappedLeftHandSelection.setEnabled(this.tapped.getSelection());
231
this.tappedRightHand.setEnabled(this.tapped.getSelection());
232
this.tappedSelection.setEnabled(this.tapped.getSelection());
236
public HarmonicEffect getHarmonic(){
237
if(natural.getSelection()){
238
return new HarmonicEffect(HarmonicEffect.TYPE_NATURAL);
240
else if(artificial.getSelection()){
241
return new HarmonicEffect(HarmonicEffect.TYPE_ARTIFICIAL,HarmonicEffect.MIN_ARTIFICIAL_OFFSET + artificialKey.getSelectionIndex());
243
else if(tapped.getSelection()){
244
return new HarmonicEffect(HarmonicEffect.TYPE_TAPPED,tappedSelection.getSelectionIndex());
246
else if(pinch.getSelection()){
247
return new HarmonicEffect(HarmonicEffect.TYPE_PINCH);
249
else if(semi.getSelection()){
250
return new HarmonicEffect(HarmonicEffect.TYPE_SEMI);