4
* Created on 02-ene-2006
10
* TODO To change the template for this generated file go to
13
* Window - Preferences - Java - Code Style - Code Templates
18
package org.herac.tuxguitar.gui.editors.chord;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.DisposeEvent;
26
import org.eclipse.swt.events.DisposeListener;
27
import org.eclipse.swt.events.MouseAdapter;
28
import org.eclipse.swt.events.MouseEvent;
29
import org.eclipse.swt.events.PaintEvent;
30
import org.eclipse.swt.events.PaintListener;
31
import org.eclipse.swt.graphics.Color;
32
import org.eclipse.swt.graphics.Font;
33
import org.eclipse.swt.graphics.FontData;
34
import org.eclipse.swt.graphics.GC;
35
import org.eclipse.swt.graphics.Point;
36
import org.eclipse.swt.graphics.Rectangle;
37
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Event;
40
import org.eclipse.swt.widgets.Listener;
41
import org.eclipse.swt.widgets.ScrollBar;
42
import org.herac.tuxguitar.gui.editors.TGPainter;
43
import org.herac.tuxguitar.gui.editors.tab.TGChordImpl;
44
import org.herac.tuxguitar.gui.editors.tab.layout.ViewLayout;
45
import org.herac.tuxguitar.song.models.TGBeat;
46
import org.herac.tuxguitar.song.models.TGString;
50
* Component that shows the list of (alternative) chords - bottom of the screen
52
public class ChordList extends Composite {
54
private static final int MIN_HEIGHT = 160;
55
private static final int SCROLL_INCREMENT = 25;
56
private static final int CHORD_FIRST_FRET_SPACING = 12;
57
private static final int CHORD_STRING_SPACING = 8;
58
private static final int CHORD_FRET_SPACING = 10;
59
private static final int CHORD_NOTE_SIZE = 6;
61
private ChordDialog dialog;
63
private List graphicChords;
65
private TGChordImpl selectedChord;
66
private Composite composite;
69
public ChordList(ChordDialog dialog,Composite parent,TGBeat beat) {
70
super(parent, SWT.NONE);
71
this.setLayout(dialog.gridLayout(1,false,0,0));
72
this.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
73
this.graphicChords = new ArrayList();
80
this.composite = new Composite(this,SWT.BORDER | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED);
81
this.composite.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE));
82
this.composite.addPaintListener(new PaintListener() {
83
public void paintControl(PaintEvent e) {
84
TGPainter painter = new TGPainter(e.gc);
88
this.composite.addMouseListener(new MouseAdapter() {
89
public void mouseUp(MouseEvent e) {
90
getComposite().setFocus();
91
getDialog().getEditor().setChord(getChord(e.x, e.y,true));
96
final Point origin = new Point(0, 0);
97
final ScrollBar vBar = this.composite.getVerticalBar();
98
vBar.setIncrement(SCROLL_INCREMENT);
99
vBar.addListener(SWT.Selection, new Listener() {
100
public void handleEvent(Event e) {
101
int vSelection = vBar.getSelection();
102
int destY = -vSelection - origin.y;
103
Rectangle rect = getComposite().getBounds();
104
getShell().scroll(0, destY, 0, 0, rect.width, rect.height, false);
105
origin.y = -vSelection;
110
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
111
data.minimumHeight = MIN_HEIGHT;
112
this.composite.setLayoutData(data);
113
this.addDisposeListener(new DisposeListener() {
114
public void widgetDisposed(DisposeEvent arg0) {
121
public void redraw(){
123
this.composite.redraw();
126
protected void paintChords(TGPainter painter) {
130
int vScroll = this.composite.getVerticalBar().getSelection();
131
Iterator it = this.graphicChords.iterator();
132
while (it.hasNext()) {
133
TGChordImpl chord = (TGChordImpl) it.next();
135
Color color = getChordColor(chord);
136
chord.setBackgroundColor(this.composite.getBackground());
137
chord.setColor(color);
138
chord.setNoteColor(color);
139
chord.setTonicColor(getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
140
chord.setFirstFretSpacing(CHORD_FIRST_FRET_SPACING);
141
chord.setStringSpacing(CHORD_STRING_SPACING);
142
chord.setFretSpacing(CHORD_FRET_SPACING);
143
chord.setNoteSize(CHORD_NOTE_SIZE);
144
chord.setFirstFretFont(getFont(painter.getGC()));
145
chord.setStyle(ViewLayout.DISPLAY_CHORD_DIAGRAM);
146
chord.update(painter, true);
147
if(fromX + chord.getWidth() >= ((getBounds().x + getBounds().width) - 20)){
149
fromY += chord.getHeight() + 10;
151
chord.setEditing(true);
152
chord.setPosX( fromX );
153
chord.setPosY( fromY - vScroll);
154
chord.paint(painter,(chord.getWidth() / 2),0);
156
fromX += chord.getWidth() + 10;
157
maxHeight = Math.max(maxHeight,chord.getHeight());
159
this.height = (fromY + maxHeight + 10);
163
private Color getChordColor(TGChordImpl chord){
164
if(this.selectedChord != null && this.selectedChord.equals(chord)){
165
return getDisplay().getSystemColor(SWT.COLOR_BLUE);
167
return getDisplay().getSystemColor(SWT.COLOR_BLACK);
170
public void updateScroll(){
171
Rectangle rect = this.composite.getBounds();
172
Rectangle client = this.composite.getClientArea();
173
ScrollBar vBar = this.composite.getVerticalBar();
174
vBar.setMaximum(this.height);
175
vBar.setThumb(Math.min(rect.height, client.height));
178
protected int getTrackString(int number){
179
TGString string = ChordList.this.beat.getMeasure().getTrack().getString(number);
180
return string.getValue();
183
protected Font getFont(GC painter){
184
if(this.font == null || this.font.isDisposed()){
185
Font available = painter.getFont();
186
if(available == null || available.isDisposed()){
187
available = getDisplay().getSystemFont();
189
FontData[] datas = available.getFontData();
190
if(datas.length > 0){
191
this.font = new Font(getDisplay(),datas[0].getName(),Math.min(7,datas[0].getHeight()),SWT.BOLD);
197
protected TGChordImpl getChord(int x, int y,boolean setAsSelected) {
198
Iterator it = this.graphicChords.iterator();
199
while (it.hasNext()) {
200
TGChordImpl chord = (TGChordImpl) it.next();
201
int x1 = chord.getPosX();
202
int x2 = x1 + chord.getWidth();
203
int y1 = chord.getPosY();
204
int y2 = y1 + chord.getHeight();
205
if (x > x1 && x < x2 && y > y1 && y < y2) {
207
if(this.selectedChord != null){
208
this.selectedChord.dispose();
210
this.selectedChord = chord;
219
public void setChords(List chords) {
220
this.disposeChords();
221
this.selectedChord = null;
223
Iterator it = chords.iterator();
224
while (it.hasNext()) {
225
TGChordImpl chord = (TGChordImpl) it.next();
226
chord.setTonic( ChordList.this.dialog.getSelector().getTonicList().getSelectionIndex() );
227
chord.setBeat(ChordList.this.beat);
228
this.graphicChords.add(chord);
233
public void disposeFont(){
234
if(this.font != null){
239
public void disposeChords(){
240
Iterator it = this.graphicChords.iterator();
241
while (it.hasNext()) {
242
((TGChordImpl) it.next()).dispose();
244
this.graphicChords.clear();
247
protected Composite getComposite(){
248
return this.composite;
251
protected ChordDialog getDialog(){
b'\\ No newline at end of file'