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.Group;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.List;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Text;
21
import org.herac.tuxguitar.gui.TuxGuitar;
22
import org.herac.tuxguitar.gui.util.DialogUtils;
23
import org.herac.tuxguitar.gui.util.MessageDialog;
24
import org.herac.tuxguitar.song.models.TGChord;
29
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
31
public class ChordCustomList extends Composite {
33
private ChordDialog dialog;
36
public ChordCustomList(ChordDialog dialog,Composite parent,int style,int height) {
38
this.setLayout(dialog.gridLayout(1,false,0,0));
39
this.setLayoutData(makeGridData(height));
44
public GridData makeGridData(int height){
45
GridData data = new GridData(SWT.FILL,SWT.TOP,true,true);
46
data.heightHint = height;
52
Composite composite = new Composite(this,SWT.NONE);
53
composite.setLayout(new GridLayout());
54
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
56
this.chords = new List(composite,SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
57
this.chords.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
58
this.chords.addSelectionListener(new SelectionAdapter() {
59
public void widgetSelected(SelectionEvent e) {
60
if(getDialog().getEditor() != null){
61
showChord(getChords().getSelectionIndex());
66
//-------------BUTTONS-----------------------------
67
Composite buttons = new Composite(this,SWT.NONE);
68
buttons.setLayout(new GridLayout(3,false));
70
Button add = new Button(buttons,SWT.PUSH);
71
add.setText(TuxGuitar.getProperty("add"));
72
add.addSelectionListener(new SelectionAdapter(){
73
public void widgetSelected(SelectionEvent e) {
78
Button rename = new Button(buttons,SWT.PUSH);
79
rename.setText(TuxGuitar.getProperty("rename"));
80
rename.addSelectionListener(new SelectionAdapter(){
81
public void widgetSelected(SelectionEvent e) {
82
renameCustomChord(getChords().getSelectionIndex());
86
Button remove = new Button(buttons,SWT.PUSH);
87
remove.setText(TuxGuitar.getProperty("remove"));
88
remove.addSelectionListener(new SelectionAdapter(){
89
public void widgetSelected(SelectionEvent e) {
90
removeCustomChord(getChords().getSelectionIndex());
97
private void loadChords(){
98
int selectionIndex = this.chords.getSelectionIndex();
99
this.chords.removeAll();
101
for(int i = 0;i < TuxGuitar.instance().getCustomChordManager().countChords();i ++){
102
TGChord chord = TuxGuitar.instance().getCustomChordManager().getChord(i);
104
this.chords.add(chord.getName());
108
if(selectionIndex >= 0 && selectionIndex < this.chords.getItemCount()){
109
this.chords.select(selectionIndex);
110
}else if(selectionIndex > 0 && (selectionIndex - 1) < this.chords.getItemCount()){
111
this.chords.select((selectionIndex - 1));
115
protected void showChord(int index) {
116
TGChord chord = TuxGuitar.instance().getCustomChordManager().getChord(index);
118
this.dialog.getEditor().setChord(chord);
122
protected void addCustomChord(){
123
TGChord chord = this.dialog.getEditor().getChord();
125
NameDialog nDialog = new NameDialog();
126
nDialog.name = this.dialog.getEditor().getChordName().getText().trim();
127
String name = nDialog.open();
129
if(name.length() == 0){
130
MessageDialog.errorMessage(getShell(),TuxGuitar.getProperty("chord.custom.name-empty-error"));
133
if(TuxGuitar.instance().getCustomChordManager().existOtherEqualCustomChord(name,-1)){
134
MessageDialog.errorMessage(getShell(),TuxGuitar.getProperty("chord.custom.name-exist-error"));
138
TuxGuitar.instance().getCustomChordManager().addChord(chord);
144
protected void renameCustomChord(int index){
145
TGChord chord = TuxGuitar.instance().getCustomChordManager().getChord(index);
147
String name = new NameDialog(chord.getName()).open();
149
if(name.length() == 0){
150
MessageDialog.errorMessage(getShell(),TuxGuitar.getProperty("chord.custom.name-empty-error"));
153
if(TuxGuitar.instance().getCustomChordManager().existOtherEqualCustomChord(name,index)){
154
MessageDialog.errorMessage(getShell(),TuxGuitar.getProperty("chord.custom.name-exist-error"));
157
TuxGuitar.instance().getCustomChordManager().renameChord(index,name);
163
protected void removeCustomChord(int index){
164
if (index >= 0 && index < TuxGuitar.instance().getCustomChordManager().countChords()) {
165
TuxGuitar.instance().getCustomChordManager().removeChord(index);
170
protected ChordDialog getDialog(){
174
protected List getChords(){
178
private class NameDialog{
179
protected String name;
181
public NameDialog(String name){
189
public String open(){
190
final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
191
dialog.setLayout(new GridLayout());
192
dialog.setText(TuxGuitar.getProperty("chord.custom"));
194
Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
195
group.setLayout(new GridLayout());
196
group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
197
group.setText(TuxGuitar.getProperty("chord.custom"));
199
Composite composite = new Composite(group, SWT.NONE);
200
composite.setLayout(new GridLayout(2,false));
201
composite.setLayoutData(getMainData());
203
final Label label = new Label(composite,SWT.LEFT);
204
label.setText(TuxGuitar.getProperty("chord.name") + ":");
205
label.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,false,true));
207
final Text text = new Text(composite,SWT.BORDER | SWT.SINGLE);
208
text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
209
text.setText(this.name);
211
//------------------BUTTONS--------------------------
212
Composite buttons = new Composite(dialog, SWT.NONE);
213
buttons.setLayout(new GridLayout(2,false));
214
buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.FILL,true,true));
216
final Button buttonOK = new Button(buttons, SWT.PUSH);
217
buttonOK.setText(TuxGuitar.getProperty("ok"));
218
buttonOK.setLayoutData(getButtonData());
219
buttonOK.addSelectionListener(new SelectionAdapter() {
220
public void widgetSelected(SelectionEvent arg0) {
221
NameDialog.this.name = text.getText();
226
Button buttonCancel = new Button(buttons, SWT.PUSH);
227
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
228
buttonCancel.setLayoutData(getButtonData());
229
buttonCancel.addSelectionListener(new SelectionAdapter() {
230
public void widgetSelected(SelectionEvent arg0) {
231
NameDialog.this.name = null;
236
dialog.setDefaultButton( buttonOK );
238
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
243
private GridData getMainData(){
244
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
245
data.minimumWidth = 300;
249
private GridData getButtonData(){
250
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
251
data.minimumWidth = 80;
252
data.minimumHeight = 25;
b'\\ No newline at end of file'