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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/effects/TremoloPickingEditor.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

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.Shell;
12
 
import org.herac.tuxguitar.gui.SystemImages;
13
 
import org.herac.tuxguitar.gui.TuxGuitar;
14
 
import org.herac.tuxguitar.song.models.Duration;
15
 
import org.herac.tuxguitar.song.models.Note;
16
 
import org.herac.tuxguitar.song.models.effects.TremoloPickingEffect;
17
 
 
18
 
public class TremoloPickingEditor extends SelectionAdapter{
19
 
 
20
 
        public static final int WIDTH = 400;
21
 
        
22
 
        public static final int HEIGHT = 0;
23
 
                        
24
 
        private Button thirtySecondButton;
25
 
        private Button sixTeenthButton;
26
 
        private Button eighthButton;
27
 
        
28
 
        private TremoloPickingEffect result;
29
 
        
30
 
        public TremoloPickingEditor(){
31
 
                
32
 
        }
33
 
 
34
 
        public TremoloPickingEffect show(final Note note){
35
 
                final Shell shell = TuxGuitar.instance().getShell();
36
 
                final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
37
 
 
38
 
        dialog.setLayout(new GridLayout());
39
 
        dialog.setText(TuxGuitar.getProperty("effects.tremolo-picking-editor"));
40
 
        
41
 
        
42
 
        Composite composite = new Composite(dialog,SWT.NONE);
43
 
        composite.setLayout(new GridLayout());
44
 
        composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
45
 
        
46
 
        int horizontalSpan = 2;
47
 
        
48
 
        //-----defaults-------------------------------------------------
49
 
                Duration duration = new Duration(Duration.EIGHTH);
50
 
        if(note.getEffect().isTremoloPicking()){                
51
 
                duration = note.getEffect().getTremoloPicking().getDuration();
52
 
        }        
53
 
 
54
 
        //---------------------------------------------------
55
 
        //------------------DURATION-------------------------
56
 
        //---------------------------------------------------
57
 
        Group durationGroup = makeGroup(composite,horizontalSpan, TuxGuitar.getProperty("duration"));
58
 
        durationGroup.setLayout(new GridLayout(3,false));
59
 
                
60
 
        thirtySecondButton = new Button(durationGroup,SWT.RADIO);
61
 
        thirtySecondButton.setImage(SystemImages.getDuration(Duration.THIRTY_SECOND));
62
 
        thirtySecondButton.setLayoutData(makeGridData(1));
63
 
        thirtySecondButton.setSelection(duration.getValue() == Duration.THIRTY_SECOND);
64
 
        
65
 
        sixTeenthButton = new Button(durationGroup,SWT.RADIO);
66
 
        sixTeenthButton.setImage(SystemImages.getDuration(Duration.SIXTEENTH));
67
 
        sixTeenthButton.setLayoutData(makeGridData(1));        
68
 
        sixTeenthButton.setSelection(duration.getValue() == Duration.SIXTEENTH);
69
 
        
70
 
        eighthButton = new Button(durationGroup,SWT.RADIO);
71
 
        eighthButton.setImage(SystemImages.getDuration(Duration.EIGHTH));
72
 
        eighthButton.setLayoutData(makeGridData(1));
73
 
        eighthButton.setSelection(duration.getValue() == Duration.EIGHTH);
74
 
        //---------------------------------------------------
75
 
        //------------------BUTTONS--------------------------
76
 
        //---------------------------------------------------
77
 
        Composite buttons = new Composite(dialog, SWT.NONE);
78
 
        buttons.setLayout(new GridLayout(3,false));
79
 
        buttons.setLayoutData(new GridData(SWT.END,SWT.BOTTOM,true,true));      
80
 
        
81
 
        GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
82
 
        data.minimumWidth = 80;
83
 
        data.minimumHeight = 25;     
84
 
        
85
 
        final Button buttonOK = new Button(buttons, SWT.PUSH);
86
 
        buttonOK.setText(TuxGuitar.getProperty("ok"));        
87
 
        buttonOK.setLayoutData(data);
88
 
        buttonOK.addSelectionListener(new SelectionAdapter() {
89
 
            public void widgetSelected(SelectionEvent arg0) {   
90
 
                result = getTremoloPicking();
91
 
                dialog.dispose();
92
 
            }
93
 
        });
94
 
 
95
 
        Button buttonClean = new Button(buttons, SWT.PUSH);
96
 
        buttonClean.setText(TuxGuitar.getProperty("clean"));
97
 
        buttonClean.setLayoutData(data);
98
 
        buttonClean.addSelectionListener(new SelectionAdapter() {
99
 
            public void widgetSelected(SelectionEvent arg0) {
100
 
                result = null;
101
 
                dialog.dispose();
102
 
            }
103
 
        });        
104
 
        
105
 
        Button buttonCancel = new Button(buttons, SWT.PUSH);
106
 
        buttonCancel.setText(TuxGuitar.getProperty("cancel"));
107
 
        buttonCancel.setLayoutData(data);
108
 
        buttonCancel.addSelectionListener(new SelectionAdapter() {
109
 
            public void widgetSelected(SelectionEvent arg0) {
110
 
                result = note.getEffect().getTremoloPicking();
111
 
                dialog.dispose();
112
 
            }
113
 
        });
114
 
 
115
 
        
116
 
        dialog.pack();
117
 
        dialog.open();
118
 
 
119
 
        int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
120
 
        int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
121
 
        dialog.setLocation(x, y);
122
 
        
123
 
                while (!dialog.isDisposed()) {
124
 
            if (!dialog.getDisplay().readAndDispatch()) {
125
 
                dialog.getDisplay().sleep();
126
 
            }
127
 
        }               
128
 
        
129
 
                return result;
130
 
        }
131
 
        
132
 
        private GridData resizeData(GridData data,int minWidth){
133
 
                data.minimumWidth = minWidth;
134
 
                
135
 
                return data;
136
 
        }
137
 
        
138
 
        private Group makeGroup(Composite parent,int horizontalSpan,String text){
139
 
        Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
140
 
        group.setLayoutData(makeGridData(horizontalSpan));
141
 
        group.setText(text);
142
 
        
143
 
        return group;
144
 
        }
145
 
        
146
 
        
147
 
        private GridData makeGridData(int horizontalSpan){
148
 
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);              
149
 
                data.horizontalSpan = horizontalSpan;           
150
 
                return data;
151
 
        }       
152
 
        
153
 
        public TremoloPickingEffect getTremoloPicking(){                                
154
 
                if(thirtySecondButton.getSelection()){
155
 
                        return new TremoloPickingEffect(new Duration(Duration.THIRTY_SECOND));
156
 
                }else if(sixTeenthButton.getSelection()){
157
 
                        return new TremoloPickingEffect(new Duration(Duration.SIXTEENTH));
158
 
                }if(eighthButton.getSelection()){
159
 
                        return new TremoloPickingEffect(new Duration(Duration.EIGHTH));
160
 
                }               
161
 
                return null;
162
 
        }       
163
 
        
164
 
 
165
 
}