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 java.util.ArrayList;
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.List;
18
import org.herac.tuxguitar.song.models.Chord;
23
* TODO To change the template for this generated type comment go to
24
* Window - Preferences - Java - Code Style - Code Templates
26
public class ChordSelector extends Composite{
27
private ChordEditor editor;
28
private ChordList list;
29
private int[] tunning;
30
private List tonicList;
31
private List chordList;
32
private List alterationList;
34
public ChordSelector(Composite parent,int style) {
36
this.setLayout(new GridLayout(2,false));
37
this.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
43
Composite leftComposite = new Composite(this,SWT.NONE);
44
Composite rightComposite = new Composite(this,SWT.NONE);
45
leftComposite.setLayout(new GridLayout());
46
rightComposite.setLayout(new GridLayout());
48
leftComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
49
rightComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
51
this.tonicList = new List(leftComposite,SWT.BORDER);
52
this.tonicList.setLayoutData(makeGridData());
53
String[] tonicNames = getTonicNames();
54
for(int i = 0;i < tonicNames.length;i++){
55
this.tonicList.add(tonicNames[i]);
57
this.tonicList.setSelection(0);
59
this.chordList = new List(rightComposite,SWT.BORDER);
60
this.chordList.setLayoutData(makeGridData());
61
String[] chordNames = getChordNames();
62
for(int i = 0;i < chordNames.length;i++){
63
this.chordList.add(chordNames[i]);
65
this.chordList.setSelection(0);
67
this.alterationList = new List(rightComposite,SWT.BORDER);
68
this.alterationList.setLayoutData(makeGridData());
69
String[] alterationNames = getAlterationNames();
70
for(int i = 0;i < alterationNames.length;i++){
71
this.alterationList.add(alterationNames[i]);
73
this.alterationList.setSelection(0);
75
this.tonicList.addSelectionListener(new SelectionAdapter() {
76
public void widgetSelected(SelectionEvent e) {
77
if(editor != null && list != null){
78
showChord(tonicList.getSelectionIndex() + 1,chordList.getSelectionIndex() + 1,alterationList.getSelectionIndex() + 1);
84
this.chordList.addSelectionListener(new SelectionAdapter() {
85
public void widgetSelected(SelectionEvent e) {
86
if(editor != null && list != null){
87
showChord(tonicList.getSelectionIndex() + 1,chordList.getSelectionIndex() + 1,alterationList.getSelectionIndex() + 1);
93
this.alterationList.addSelectionListener(new SelectionAdapter() {
94
public void widgetSelected(SelectionEvent e) {
95
if(editor != null && list != null){
96
showChord(tonicList.getSelectionIndex() + 1,chordList.getSelectionIndex() + 1,alterationList.getSelectionIndex() + 1);
103
private GridData makeGridData(){
104
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
105
data.minimumWidth = 50;
110
public void setEditor(ChordEditor editor){
111
this.editor = editor;
114
public void setList(ChordList list){
118
public void setTunning(int[] tunning){
119
this.tunning = tunning;
122
private String[] getTonicNames(){
123
String[] names = new String[12];
141
private String[] getChordNames(){
142
String[] names = new String[4];
152
private String[] getAlterationNames(){
153
String[] names = new String[5];
164
private void showChord(int tonic,int chordType,int alterationType){
165
int requiredNotes[] = getRequiredNotes(chordType,alterationType);
167
//entre cegillas 1 y 4
171
java.util.List chords = new ArrayList();
172
ChordCreatorUtil chordCreator = null;
173
for(int i = 0;i < 10;i++){
174
chordCreator = new ChordCreatorUtil(this.tunning,requiredNotes,tonic,fret1 + i,fret2 + i);
175
Chord chord = chordCreator.getChord();
180
this.list.setChords(chords);
183
private int[] getRequiredNotes(int chordType,int alterationType){
184
int requiredNotes[] = null;
186
int alterationRequired = getAlterationRequired(alterationType);
187
int moveLength = (alterationRequired > 0)?1:0;
191
requiredNotes = new int[3 + moveLength];
192
requiredNotes[0 + moveLength] = 1;
193
requiredNotes[1 + moveLength] = 5;
194
requiredNotes[2 + moveLength] = 8;
197
requiredNotes = new int[3 + moveLength];
198
requiredNotes[0 + moveLength] = 1;
199
requiredNotes[1 + moveLength] = 4;
200
requiredNotes[2 + moveLength] = 8;
203
requiredNotes = new int[4 + moveLength];
204
requiredNotes[0 + moveLength] = 3;
205
requiredNotes[1 + moveLength] = 1;
206
requiredNotes[2 + moveLength] = 5;
207
requiredNotes[3 + moveLength] = 8;
210
requiredNotes = new int[4 + moveLength];
211
requiredNotes[0 + moveLength] = 6;
212
requiredNotes[1 + moveLength] = 1;
213
requiredNotes[2 + moveLength] = 8;
214
requiredNotes[3 + moveLength] = 5;
217
if(alterationRequired > 0){
218
requiredNotes[0] = alterationRequired;
221
return requiredNotes;
224
private int getAlterationRequired(int alterationType){
225
int requiredNote = 0;
227
switch(alterationType){