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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/chord/ChordSettingsDialog.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.chord;
 
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.eclipse.swt.widgets.Spinner;
 
15
import org.herac.tuxguitar.gui.TuxGuitar;
 
16
import org.herac.tuxguitar.gui.util.DialogUtils;
 
17
 
 
18
/**
 
19
 * Dialog for customizing chord criteria parameters
 
20
 * 
 
21
 * @author Nikola Kolarovic
 
22
 *
 
23
 */
 
24
public class ChordSettingsDialog {
 
25
        
 
26
        private boolean updated;
 
27
        private Shell dialog;
 
28
        private Button emptyStringChords = null;
 
29
        private Spinner chordsToDisplay = null;
 
30
        private Combo typeCombo = null;
 
31
        private Spinner minFret = null;
 
32
        private Spinner maxFret = null;
 
33
        
 
34
        public ChordSettingsDialog() {
 
35
                super();
 
36
        }
 
37
        
 
38
        public boolean open(Shell parent){
 
39
                this.updated = false;
 
40
                
 
41
                this.dialog = DialogUtils.newDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
42
                this.dialog.setLayout(new GridLayout());
 
43
                this.dialog.setText(TuxGuitar.getProperty("settings"));
 
44
                this.init();
 
45
                DialogUtils.openDialog(this.dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
46
                
 
47
                return this.updated;
 
48
        }
 
49
        
 
50
        protected void init() {
 
51
                Group group = new Group(this.dialog,SWT.SHADOW_ETCHED_IN);
 
52
                group.setLayout(new GridLayout());
 
53
                group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
54
                group.setText(TuxGuitar.getProperty("chord.settings.tip"));
 
55
                
 
56
                Composite composite = new Composite(group,SWT.NONE);
 
57
                composite.setLayout(new GridLayout(2,false));
 
58
                composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
59
                
 
60
                initTypeCombo(composite);
 
61
                initChordsToDisplay(composite);
 
62
                initEmptyStringChords(composite);
 
63
                initFretSearch(composite);
 
64
                
 
65
                //------------------BUTTONS--------------------------
 
66
                Composite buttons = new Composite(this.dialog, SWT.NONE);
 
67
                buttons.setLayout(new GridLayout(2,false));
 
68
                buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
 
69
                
 
70
                final Button buttonOK = new Button(buttons, SWT.PUSH);
 
71
                buttonOK.setText(TuxGuitar.getProperty("ok"));
 
72
                buttonOK.setLayoutData(getButtonData());
 
73
                buttonOK.addSelectionListener(new SelectionAdapter() {
 
74
                        public void widgetSelected(SelectionEvent arg0) {
 
75
                                dispose(true);
 
76
                        }
 
77
                });
 
78
                
 
79
                Button buttonCancel = new Button(buttons, SWT.PUSH);
 
80
                buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
81
                buttonCancel.setLayoutData(getButtonData());
 
82
                buttonCancel.addSelectionListener(new SelectionAdapter() {
 
83
                        public void widgetSelected(SelectionEvent arg0) {
 
84
                                dispose(false);
 
85
                        }
 
86
                });
 
87
                
 
88
                this.dialog.setDefaultButton( buttonOK );
 
89
        }
 
90
        
 
91
        private GridData getGridData(int minimumWidth, int minimumHeight){
 
92
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
93
                data.minimumWidth = minimumWidth;
 
94
                data.minimumHeight = minimumHeight;
 
95
                return data;
 
96
        }
 
97
        
 
98
        private GridData getGridData(){
 
99
                return getGridData(125,0);
 
100
        }
 
101
        
 
102
        private GridData getButtonData(){
 
103
                return getGridData(80,25);
 
104
        }
 
105
        
 
106
        private Spinner makeSpinner(Composite parent,String label,int value, int min, int max){
 
107
                this.newLabel(parent,label);
 
108
                Spinner spinner = new Spinner(parent,SWT.BORDER);
 
109
                spinner.setMinimum(min);
 
110
                spinner.setMaximum(max);
 
111
                spinner.setSelection(value);
 
112
                spinner.setLayoutData(getGridData());
 
113
                return spinner;
 
114
        }
 
115
        
 
116
        private Label newLabel(Composite parent,String text){
 
117
                Label label = new Label(parent,SWT.HORIZONTAL);
 
118
                label.setText(text);
 
119
                return label;
 
120
        }
 
121
        
 
122
        private void initTypeCombo(Composite parent) {
 
123
                this.newLabel(parent, TuxGuitar.getProperty("chord.settings.type"));
 
124
                this.typeCombo = new Combo(parent,SWT.DROP_DOWN | SWT.READ_ONLY);
 
125
                this.typeCombo.setLayoutData(getGridData());
 
126
                this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.most-common"));
 
127
                this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.inversions"));
 
128
                this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.close-voiced"));
 
129
                this.typeCombo.add(TuxGuitar.getProperty("chord.settings.type.open-voiced"));
 
130
                this.typeCombo.select(ChordSettings.instance().getChordTypeIndex());
 
131
        }
 
132
        
 
133
        private void initChordsToDisplay(Composite parent) {
 
134
                this.chordsToDisplay = makeSpinner(parent,TuxGuitar.getProperty("chord.settings.chords-to-display"),ChordSettings.instance().getChordsToDisplay(),1,100);
 
135
        }
 
136
        
 
137
        private void initEmptyStringChords(Composite parent) {
 
138
                this.emptyStringChords = new Button(parent,SWT.CHECK);
 
139
                this.emptyStringChords.setSelection(ChordSettings.instance().isEmptyStringChords());
 
140
                this.emptyStringChords.setText(TuxGuitar.getProperty("chord.settings.open-chords"));
 
141
                this.emptyStringChords.setSize(100,20);
 
142
                this.emptyStringChords.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,1));
 
143
        }
 
144
        
 
145
        private void initFretSearch(Composite parent) {
 
146
                Group group = new Group(parent,SWT.SHADOW_ETCHED_IN);
 
147
                group.setLayout(new GridLayout(4,false));
 
148
                group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,1));
 
149
                group.setText(TuxGuitar.getProperty("chord.settings.search-frets"));
 
150
                this.minFret = makeSpinner(group,TuxGuitar.getProperty("chord.settings.minimum-fret"),ChordSettings.instance().getFindChordsMin(),0,15);
 
151
                this.maxFret = makeSpinner(group,TuxGuitar.getProperty("chord.settings.maximum-fret"),ChordSettings.instance().getFindChordsMax(),2,25);
 
152
                this.minFret.addSelectionListener(new SelectionAdapter() {
 
153
                        public void widgetSelected(SelectionEvent e) {
 
154
                                checkMinimumFretValue();
 
155
                        }
 
156
                });
 
157
                this.maxFret.addSelectionListener(new SelectionAdapter() {
 
158
                        public void widgetSelected(SelectionEvent e) {
 
159
                                checkMaximunFretValue();
 
160
                        }
 
161
                });
 
162
        }
 
163
        
 
164
        protected void checkMinimumFretValue(){
 
165
                int maxSelection = this.maxFret.getSelection();
 
166
                int minSelection = this.minFret.getSelection();
 
167
                if(maxSelection < minSelection){
 
168
                        this.maxFret.setSelection(minSelection);
 
169
                }
 
170
        }
 
171
        
 
172
        protected void checkMaximunFretValue(){
 
173
                int maxSelection = this.maxFret.getSelection();
 
174
                int minSelection = this.minFret.getSelection();
 
175
                if(maxSelection < minSelection){
 
176
                        this.maxFret.setSelection(minSelection);
 
177
                }
 
178
        }
 
179
        
 
180
        private void update(){
 
181
                ChordSettings.instance().setChordTypeIndex(this.typeCombo.getSelectionIndex());
 
182
                ChordSettings.instance().setEmptyStringChords(this.emptyStringChords.getSelection());
 
183
                ChordSettings.instance().setChordsToDisplay(this.chordsToDisplay.getSelection() );
 
184
                ChordSettings.instance().setFindChordsMax(this.maxFret.getSelection());
 
185
                ChordSettings.instance().setFindChordsMin(this.minFret.getSelection());
 
186
        }
 
187
        
 
188
        protected void dispose(boolean updated){
 
189
                this.updated = updated;
 
190
                if(this.updated){
 
191
                        this.update();
 
192
                }
 
193
                this.dialog.dispose();
 
194
        }
 
195
}