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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/effects/HarmonicEditor.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.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.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;
17
 
 
18
 
public class HarmonicEditor extends SelectionAdapter{
19
 
 
20
 
        public static final int WIDTH = 400;
21
 
        
22
 
        public static final int HEIGHT = 0;
23
 
        
24
 
        private Button natural;
25
 
        
26
 
        private Button artificial;
27
 
        
28
 
        private Button tapped;
29
 
        
30
 
        private Button pinch;
31
 
        
32
 
        private Button semi;
33
 
        
34
 
        private Label artificialLabel;
35
 
        private Combo artificialKey;            
36
 
                
37
 
        private Label tappedLeftHand;   
38
 
        private Label tappedLeftHandSelection;
39
 
        private Label tappedRightHand;  
40
 
        private Combo tappedSelection;
41
 
        
42
 
        private HarmonicEffect result;
43
 
        
44
 
        public HarmonicEditor(){
45
 
                
46
 
        }
47
 
        
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);
51
 
 
52
 
        dialog.setLayout(new GridLayout());
53
 
        dialog.setText(TuxGuitar.getProperty("effects.harmonic-editor"));
54
 
        
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"));               
59
 
 
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());
68
 
        
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());
77
 
                
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));    
81
 
                
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));
85
 
        
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));
90
 
        }   
91
 
        if(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isArtificial()){
92
 
                this.artificialKey.select(note.getEffect().getHarmonic().getData() - HarmonicEffect.MIN_ARTIFICIAL_OFFSET);
93
 
        }else{
94
 
                this.artificialKey.select(-HarmonicEffect.MIN_ARTIFICIAL_OFFSET);
95
 
        }
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());
104
 
        
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));         
108
 
 
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));  
112
 
        
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");
116
 
        
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)); 
120
 
        
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));
125
 
        }        
126
 
        if(note.getEffect().isHarmonic() && note.getEffect().getHarmonic().isTapped()){         
127
 
                this.tappedSelection.select(note.getEffect().getHarmonic().getData());
128
 
        }else{
129
 
                this.tappedSelection.select(0);
130
 
        }
131
 
 
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());
140
 
        
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());
149
 
        
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));      
156
 
        
157
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
158
 
        data.minimumWidth = 80;
159
 
        data.minimumHeight = 25;     
160
 
        
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();
167
 
                dialog.dispose();
168
 
            }
169
 
        });
170
 
 
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) {
176
 
                result = null;
177
 
                dialog.dispose();
178
 
            }
179
 
        });        
180
 
        
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();
187
 
                dialog.dispose();
188
 
            }
189
 
        });
190
 
 
191
 
        
192
 
        if(!note.getEffect().isHarmonic()){
193
 
                this.natural.setSelection(true);
194
 
        }        
195
 
        updateControls();        
196
 
        dialog.pack();
197
 
        dialog.open();
198
 
 
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);
202
 
        
203
 
                while (!dialog.isDisposed()) {
204
 
            if (!dialog.getDisplay().readAndDispatch()) {
205
 
                dialog.getDisplay().sleep();
206
 
            }
207
 
        }               
208
 
        
209
 
                return result;
210
 
        }
211
 
        
212
 
        private GridData resizeData(GridData data,int minWidth){
213
 
                data.minimumWidth = minWidth;   
214
 
                return data;
215
 
        }
216
 
        
217
 
        private GridData spanData(GridData data,int horizontalSpan){
218
 
                data.horizontalSpan = horizontalSpan;           
219
 
                return data;
220
 
        }       
221
 
        
222
 
        public void widgetSelected(SelectionEvent e) {
223
 
                updateControls();
224
 
        }
225
 
        
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());
233
 
        }
234
 
        
235
 
        
236
 
        public HarmonicEffect getHarmonic(){                            
237
 
                if(natural.getSelection()){
238
 
                        return new HarmonicEffect(HarmonicEffect.TYPE_NATURAL);
239
 
                }
240
 
                else if(artificial.getSelection()){
241
 
                        return new HarmonicEffect(HarmonicEffect.TYPE_ARTIFICIAL,HarmonicEffect.MIN_ARTIFICIAL_OFFSET + artificialKey.getSelectionIndex());
242
 
                } 
243
 
                else if(tapped.getSelection()){
244
 
                        return new HarmonicEffect(HarmonicEffect.TYPE_TAPPED,tappedSelection.getSelectionIndex());
245
 
                }
246
 
                else if(pinch.getSelection()){
247
 
                        return new HarmonicEffect(HarmonicEffect.TYPE_PINCH);
248
 
                }
249
 
                else if(semi.getSelection()){
250
 
                        return new HarmonicEffect(HarmonicEffect.TYPE_SEMI);
251
 
                }               
252
 
 
253
 
                return null;
254
 
        }       
255
 
        
256
 
 
257
 
}