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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/effects/TrillEditor.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.effects.TGEffectTrill;
 
19
 
 
20
public class TrillEditor extends SelectionAdapter{
 
21
        
 
22
        public static final int WIDTH = 400;
 
23
        
 
24
        public static final int HEIGHT = 0;
 
25
        
 
26
        private Spinner fretSpinner;
 
27
        private Button sixtyFourthButton;
 
28
        private Button thirtySecondButton;
 
29
        private Button sixTeenthButton;
 
30
        
 
31
        protected TGEffectTrill result;
 
32
        
 
33
        public TrillEditor(){
 
34
                super();
 
35
        }
 
36
        
 
37
        public TGEffectTrill show(final TGNote note){
 
38
                final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
39
                
 
40
                dialog.setLayout(new GridLayout());
 
41
                dialog.setText(TuxGuitar.getProperty("effects.trill-editor"));
 
42
                
 
43
                
 
44
                Composite composite = new Composite(dialog,SWT.NONE);
 
45
                composite.setLayout(new GridLayout());
 
46
                composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
47
                
 
48
                int horizontalSpan = 2;
 
49
                
 
50
                //-----defaults-------------------------------------------------
 
51
                int fret = note.getValue();
 
52
                int duration = TGDuration.SIXTEENTH;
 
53
                //Duration duration = new Duration(Duration.SIXTEENTH);
 
54
                if(note.getEffect().isTrill()){
 
55
                        fret = note.getEffect().getTrill().getFret();
 
56
                        duration = note.getEffect().getTrill().getDuration().getValue();
 
57
                }
 
58
                //---------------------------------------------------
 
59
                //------------------NOTE-----------------------------
 
60
                //---------------------------------------------------
 
61
                Group noteGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("note"));
 
62
                noteGroup.setLayout(new GridLayout(2,false));
 
63
                
 
64
                Label fretLabel = new Label(noteGroup,SWT.NONE);
 
65
                
 
66
                fretLabel.setText(TuxGuitar.getProperty("fret") + ": ");
 
67
                //fretLabel.setLayoutData(makeGridData(1));
 
68
                
 
69
                this.fretSpinner = new Spinner(noteGroup,SWT.BORDER);
 
70
                this.fretSpinner.setLayoutData(makeGridData(1));
 
71
                this.fretSpinner.setSelection(fret);
 
72
                
 
73
                //---------------------------------------------------
 
74
                //------------------DURATION-------------------------
 
75
                //---------------------------------------------------
 
76
                Group durationGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("duration"));
 
77
                durationGroup.setLayout(new GridLayout(3,false));
 
78
                
 
79
                this.sixtyFourthButton = new Button(durationGroup,SWT.RADIO);
 
80
                this.sixtyFourthButton.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTY_FOURTH));
 
81
                this.sixtyFourthButton.setLayoutData(makeGridData(1));
 
82
                this.sixtyFourthButton.setSelection(duration == TGDuration.SIXTY_FOURTH);
 
83
                
 
84
                this.thirtySecondButton = new Button(durationGroup,SWT.RADIO);
 
85
                this.thirtySecondButton.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.THIRTY_SECOND));
 
86
                this.thirtySecondButton.setLayoutData(makeGridData(1));
 
87
                this.thirtySecondButton.setSelection(duration == TGDuration.THIRTY_SECOND);
 
88
                
 
89
                this.sixTeenthButton = new Button(durationGroup,SWT.RADIO);
 
90
                this.sixTeenthButton.setImage(TuxGuitar.instance().getIconManager().getDuration(TGDuration.SIXTEENTH));
 
91
                this.sixTeenthButton.setLayoutData(makeGridData(1));
 
92
                this.sixTeenthButton.setSelection(duration == TGDuration.SIXTEENTH);
 
93
                
 
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));
 
100
                
 
101
                final Button buttonOK = new Button(buttons, SWT.PUSH);
 
102
                buttonOK.setText(TuxGuitar.getProperty("ok"));
 
103
                buttonOK.setLayoutData(getButtonData());
 
104
                buttonOK.addSelectionListener(new SelectionAdapter() {
 
105
                        public void widgetSelected(SelectionEvent arg0) {
 
106
                                TrillEditor.this.result = getTrill();
 
107
                                dialog.dispose();
 
108
                        }
 
109
                });
 
110
                
 
111
                Button buttonClean = new Button(buttons, SWT.PUSH);
 
112
                buttonClean.setText(TuxGuitar.getProperty("clean"));
 
113
                buttonClean.setLayoutData(getButtonData());
 
114
                buttonClean.addSelectionListener(new SelectionAdapter() {
 
115
                        public void widgetSelected(SelectionEvent arg0) {
 
116
                                TrillEditor.this.result = null;
 
117
                                dialog.dispose();
 
118
                        }
 
119
                });
 
120
                
 
121
                Button buttonCancel = new Button(buttons, SWT.PUSH);
 
122
                buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
123
                buttonCancel.setLayoutData(getButtonData());
 
124
                buttonCancel.addSelectionListener(new SelectionAdapter() {
 
125
                        public void widgetSelected(SelectionEvent arg0) {
 
126
                                TrillEditor.this.result = note.getEffect().getTrill();
 
127
                                dialog.dispose();
 
128
                        }
 
129
                });
 
130
                
 
131
                dialog.setDefaultButton( buttonOK );
 
132
                
 
133
                DialogUtils.openDialog(dialog, DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
134
                return this.result;
 
135
        }
 
136
        
 
137
        private Group makeGroup(Composite parent,int horizontalSpan,String text){
 
138
                Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
 
139
                group.setLayoutData(makeGridData(horizontalSpan));
 
140
                group.setText(text);
 
141
                
 
142
                return group;
 
143
        }
 
144
        
 
145
        private GridData getButtonData(){
 
146
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
147
                data.minimumWidth = 80;
 
148
                data.minimumHeight = 25;
 
149
                return data;
 
150
        }
 
151
        
 
152
        private GridData makeGridData(int horizontalSpan){
 
153
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
154
                data.horizontalSpan = horizontalSpan;
 
155
                return data;
 
156
        }
 
157
        
 
158
        public TGEffectTrill getTrill(){
 
159
                TGEffectTrill effect = TuxGuitar.instance().getSongManager().getFactory().newEffectTrill();
 
160
                effect.setFret(this.fretSpinner.getSelection());
 
161
                if(this.sixtyFourthButton.getSelection()){
 
162
                        effect.getDuration().setValue(TGDuration.SIXTY_FOURTH);
 
163
                }else if(this.thirtySecondButton.getSelection()){
 
164
                        effect.getDuration().setValue(TGDuration.THIRTY_SECOND);
 
165
                }else if(this.sixTeenthButton.getSelection()){
 
166
                        effect.getDuration().setValue(TGDuration.SIXTEENTH);
 
167
                }else{
 
168
                        return null;
 
169
                }
 
170
                return effect;
 
171
        }
 
172
}