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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/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.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.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;
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
 
        private TrillEffect result;
32
 
        
33
 
        public TrillEditor(){
34
 
                
35
 
        }
36
 
 
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);
40
 
 
41
 
        dialog.setLayout(new GridLayout());
42
 
        dialog.setText(TuxGuitar.getProperty("effects.trill-editor"));
43
 
        
44
 
        
45
 
        Composite composite = new Composite(dialog,SWT.NONE);
46
 
        composite.setLayout(new GridLayout());
47
 
        composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
48
 
        
49
 
        int horizontalSpan = 2;
50
 
        
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();
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
 
        fretSpinner = new Spinner(noteGroup,SWT.BORDER);
70
 
        fretSpinner.setLayoutData(makeGridData(1));
71
 
        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
 
        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);
83
 
        
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);
88
 
        
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);
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
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
102
 
        data.minimumWidth = 80;
103
 
        data.minimumHeight = 25;     
104
 
        
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) {   
110
 
                result = getTrill();
111
 
                dialog.dispose();
112
 
            }
113
 
        });
114
 
 
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) {
120
 
                result = null;
121
 
                dialog.dispose();
122
 
            }
123
 
        });        
124
 
        
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();
131
 
                dialog.dispose();
132
 
            }
133
 
        });
134
 
 
135
 
        
136
 
        dialog.pack();
137
 
        dialog.open();
138
 
 
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);
142
 
        
143
 
                while (!dialog.isDisposed()) {
144
 
            if (!dialog.getDisplay().readAndDispatch()) {
145
 
                dialog.getDisplay().sleep();
146
 
            }
147
 
        }               
148
 
        
149
 
                return result;
150
 
        }
151
 
        
152
 
        private GridData resizeData(GridData data,int minWidth){
153
 
                data.minimumWidth = minWidth;
154
 
                
155
 
                return data;
156
 
        }
157
 
        
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));
161
 
        group.setText(text);
162
 
        
163
 
        return group;
164
 
        }
165
 
        
166
 
        
167
 
        private GridData makeGridData(int horizontalSpan){
168
 
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);              
169
 
                data.horizontalSpan = horizontalSpan;           
170
 
                return data;
171
 
        }       
172
 
        
173
 
        public TrillEffect getTrill(){                          
174
 
                int fret = fretSpinner.getSelection();                  
175
 
                                
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));
182
 
                }               
183
 
                return null;
184
 
        }       
185
 
        
186
 
 
187
 
}