2
* Created on 02-ene-2006
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.editors.chord;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.SelectionAdapter;
11
import org.eclipse.swt.events.SelectionEvent;
12
import org.eclipse.swt.layout.GridData;
13
import org.eclipse.swt.layout.GridLayout;
14
import org.eclipse.swt.widgets.Button;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Label;
17
import org.eclipse.swt.widgets.List;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.swt.widgets.Text;
20
import org.herac.tuxguitar.gui.TuxGuitar;
21
import org.herac.tuxguitar.gui.util.MessageDialog;
22
import org.herac.tuxguitar.song.models.Chord;
27
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
29
public class ChordCustomList extends Composite {
30
private ChordEditor editor;
33
public ChordCustomList(Composite parent,int style,int height,ChordEditor editor) {
35
this.setLayout(new GridLayout());
36
this.setLayoutData(makeGridData(height));
41
public GridData makeGridData(int height){
42
GridData data = new GridData(SWT.FILL,SWT.TOP,true,true);
43
data.heightHint = height;
49
Composite composite = new Composite(this,SWT.NONE);
50
composite.setLayout(new GridLayout());
51
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
53
this.chords = new List(composite,SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
54
this.chords.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
55
this.chords.addSelectionListener(new SelectionAdapter() {
56
public void widgetSelected(SelectionEvent e) {
58
showChord(chords.getSelectionIndex());
64
//-------------BUTTONS-----------------------------
65
Composite buttons = new Composite(this,SWT.NONE);
66
buttons.setLayout(new GridLayout(3,false));
68
Button add = new Button(buttons,SWT.PUSH);
69
add.setText(TuxGuitar.getProperty("add"));
70
add.addSelectionListener(new SelectionAdapter(){
71
public void widgetSelected(SelectionEvent e) {
76
Button rename = new Button(buttons,SWT.PUSH);
77
rename.setText(TuxGuitar.getProperty("rename"));
78
rename.addSelectionListener(new SelectionAdapter(){
79
public void widgetSelected(SelectionEvent e) {
80
renameCustomChord(chords.getSelectionIndex());
84
Button remove = new Button(buttons,SWT.PUSH);
85
remove.setText(TuxGuitar.getProperty("remove"));
86
remove.addSelectionListener(new SelectionAdapter(){
87
public void widgetSelected(SelectionEvent e) {
88
removeCustomChord(chords.getSelectionIndex());
96
private void loadChords(){
97
int selectionIndex = chords.getSelectionIndex();
98
this.chords.removeAll();
100
for(int i = 0;i < TuxGuitar.instance().getCustomChordManager().countChords();i ++){
101
Chord chord = TuxGuitar.instance().getCustomChordManager().getChord(i);
103
this.chords.add(chord.getName());
107
if(selectionIndex >= 0 && selectionIndex < this.chords.getItemCount()){
108
this.chords.select(selectionIndex);
109
}else if(selectionIndex > 0 && (selectionIndex - 1) < this.chords.getItemCount()){
110
this.chords.select((selectionIndex - 1));
114
private void showChord(int index) {
115
Chord chord = TuxGuitar.instance().getCustomChordManager().getChord(index);
118
for (int i = 0; i < chord.getStrings().length; i++) {
119
int fretValue = chord.getFretValue(i);
120
if (firstFret < 0 || (fretValue < firstFret && fretValue >= 0)) {
121
firstFret = fretValue;
124
editor.setFret((short)((firstFret<=0?1:firstFret)));
125
for (int i = 0; i < chord.getStrings().length; i++) {
126
int fretValue = chord.getFretValue(i);
127
editor.addValue(fretValue, i + 1);
134
private void addCustomChord(){
135
Chord chord = editor.getCurrentChord();
137
String name = new NameDialog().open();
139
if(name.length() == 0){
140
String title = TuxGuitar.getProperty("error");
141
String message = TuxGuitar.getProperty("chord.custom.name-empty-error");
142
new MessageDialog(title,message,SWT.ICON_ERROR).show(getShell());
145
if(TuxGuitar.instance().getCustomChordManager().existOtherEqualCustomChord(name,-1)){
146
String title = TuxGuitar.getProperty("error");
147
String message = TuxGuitar.getProperty("chord.custom.name-exist-error");
148
new MessageDialog(title,message,SWT.ICON_ERROR).show(getShell());
152
TuxGuitar.instance().getCustomChordManager().addChord(chord);
158
private void renameCustomChord(int index){
159
Chord chord = TuxGuitar.instance().getCustomChordManager().getChord(index);
161
String name = new NameDialog(chord.getName()).open();
163
if(name.length() == 0){
164
String title = TuxGuitar.getProperty("error");
165
String message = TuxGuitar.getProperty("chord.custom.name-empty-error");
166
new MessageDialog(title,message,SWT.ICON_ERROR).show(getShell());
169
if(TuxGuitar.instance().getCustomChordManager().existOtherEqualCustomChord(name,index)){
170
String title = TuxGuitar.getProperty("error");
171
String message = TuxGuitar.getProperty("chord.custom.name-exist-error");
172
new MessageDialog(title,message,SWT.ICON_ERROR).show(getShell());
175
TuxGuitar.instance().getCustomChordManager().renameChord(index,name);
181
private void removeCustomChord(int index){
182
if (index >= 0 && index < TuxGuitar.instance().getCustomChordManager().countChords()) {
183
TuxGuitar.instance().getCustomChordManager().removeChord(index);
188
private class NameDialog{
191
public NameDialog(String name){
199
public String open(){
200
final Shell dialog = new Shell(getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
202
dialog.setLayout(new GridLayout());
203
dialog.setText(TuxGuitar.getProperty("chord.name"));
205
//-----------------NAME------------------------
206
Composite composite = new Composite(dialog, SWT.NONE);
207
composite.setLayout(new GridLayout(2,false));
208
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
210
Label label = new Label(composite, SWT.NULL);
211
label.setText(TuxGuitar.getProperty("chord.name"));
213
final Text text = new Text(composite, SWT.BORDER);
214
GridData textData = new GridData(SWT.FILL,SWT.FILL,true,true);
215
textData.minimumWidth = 150;
216
text.setLayoutData(textData);
217
text.setText(this.name);
218
//------------------BUTTONS--------------------------
219
Composite buttons = new Composite(dialog, SWT.NONE);
220
buttons.setLayout(new GridLayout(2,false));
221
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
223
GridData buttonData = new GridData(SWT.FILL,SWT.FILL,true,true);
224
buttonData.minimumWidth = 80;
225
buttonData.minimumHeight = 25;
227
final Button buttonOK = new Button(buttons, SWT.PUSH);
228
buttonOK.setText(TuxGuitar.getProperty("ok"));
229
buttonOK.setLayoutData(buttonData);
230
buttonOK.addSelectionListener(new SelectionAdapter() {
231
public void widgetSelected(SelectionEvent arg0) {
232
name = text.getText();
237
Button buttonCancel = new Button(buttons, SWT.PUSH);
238
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
239
buttonCancel.setLayoutData(buttonData);
240
buttonCancel.addSelectionListener(new SelectionAdapter() {
241
public void widgetSelected(SelectionEvent arg0) {
250
int x = getShell().getBounds().x + (getShell().getBounds().width - dialog.getSize().x) / 2;
251
int y = getShell().getBounds().y + (getShell().getBounds().height - dialog.getSize().y) / 2;
252
dialog.setLocation(x, y);
254
while (!dialog.isDisposed()) {
255
if (!dialog.getDisplay().readAndDispatch()) {
256
dialog.getDisplay().sleep();
b'\\ No newline at end of file'