1
package org.herac.tuxguitar.gui.editors.chord;
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;
19
* Dialog for customizing chord criteria parameters
21
* @author Nikola Kolarovic
24
public class ChordSettingsDialog {
26
private boolean updated;
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;
34
public ChordSettingsDialog() {
38
public boolean open(Shell parent){
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"));
45
DialogUtils.openDialog(this.dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
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"));
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));
60
initTypeCombo(composite);
61
initChordsToDisplay(composite);
62
initEmptyStringChords(composite);
63
initFretSearch(composite);
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));
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) {
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) {
88
this.dialog.setDefaultButton( buttonOK );
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;
98
private GridData getGridData(){
99
return getGridData(125,0);
102
private GridData getButtonData(){
103
return getGridData(80,25);
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());
116
private Label newLabel(Composite parent,String text){
117
Label label = new Label(parent,SWT.HORIZONTAL);
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());
133
private void initChordsToDisplay(Composite parent) {
134
this.chordsToDisplay = makeSpinner(parent,TuxGuitar.getProperty("chord.settings.chords-to-display"),ChordSettings.instance().getChordsToDisplay(),1,100);
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));
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();
157
this.maxFret.addSelectionListener(new SelectionAdapter() {
158
public void widgetSelected(SelectionEvent e) {
159
checkMaximunFretValue();
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);
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);
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());
188
protected void dispose(boolean updated){
189
this.updated = updated;
193
this.dialog.dispose();