1
package org.herac.tuxguitar.gui.editors.lyric;
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.graphics.Rectangle;
7
import org.eclipse.swt.layout.GridData;
8
import org.eclipse.swt.layout.GridLayout;
9
import org.eclipse.swt.widgets.Button;
10
import org.eclipse.swt.widgets.Composite;
11
import org.eclipse.swt.widgets.Label;
12
import org.eclipse.swt.widgets.Shell;
13
import org.eclipse.swt.widgets.Spinner;
14
import org.eclipse.swt.widgets.Text;
15
import org.herac.tuxguitar.gui.TuxGuitar;
16
import org.herac.tuxguitar.gui.actions.track.GoNextTrackAction;
17
import org.herac.tuxguitar.gui.actions.track.GoPreviousTrackAction;
18
import org.herac.tuxguitar.song.models.SongTrack;
20
public class LyricEditor {
21
private static int EDITOR_WIDTH = 400;
22
private static int EDITOR_HEIGHT = 200;
24
private SongTrack track;
26
private LyricModifyListener listener;
33
this.listener = new LyricModifyListener(this);
37
Shell shell = TuxGuitar.instance().getShell();
38
Rectangle sBounds = shell.getBounds();
39
Rectangle dBounds = shell.getDisplay().getBounds();
41
this.dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE);
42
this.dialog.setLayout(new GridLayout());
43
this.dialog.setText(TuxGuitar.getProperty("lyric.editor"));
45
this.updateSongTrack();
46
this.loadComposites();
50
int x = shell.getBounds().x + (shell.getBounds().width - EDITOR_WIDTH) / 2;
51
int y = shell.getBounds().y + (shell.getBounds().height - EDITOR_HEIGHT) / 2;
53
this.dialog.setSize(EDITOR_WIDTH,EDITOR_HEIGHT);
54
this.dialog.setLocation(x, y);
57
while (!dialog.isDisposed()) {
58
if (!dialog.getDisplay().readAndDispatch()) {
59
dialog.getDisplay().sleep();
69
private void loadComposites(){
71
Composite composite = new Composite(this.dialog,SWT.NONE);
72
composite.setLayout(new GridLayout());
73
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
75
loadToolBar(composite);
76
loadLyricText(composite);
80
private void loadToolBar(Composite parent){
81
final Composite composite = new Composite(parent,SWT.NONE);
82
composite.setLayout(new GridLayout(5,false));
83
composite.setLayoutData(new GridData(SWT.FILL,SWT.NONE,true,false));
85
Button previous = new Button(composite, SWT.ARROW | SWT.LEFT);
86
Button next = new Button(composite, SWT.ARROW | SWT.RIGHT);
88
this.label = new Label(composite,SWT.NONE);
89
this.label.setText(this.track.getName());
90
this.label.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
93
Label fromLabel = new Label(composite,SWT.NONE);
94
fromLabel.setText(TuxGuitar.getProperty("edit.from"));
95
fromLabel.setLayoutData(new GridData(SWT.RIGHT,SWT.CENTER,false,true));
98
//GridData fromData = new GridData(SWT.END,SWT.CENTER,false,true);
99
//fromData.widthHint = 24;
101
this.from = new Spinner(composite,SWT.BORDER);
102
this.from.setLayoutData(getSpinnerData());
104
this.from.setMinimum(1);
105
this.from.setMaximum(this.track.getMeasures().size());
106
this.from.setSelection(this.track.getLyrics().getFrom());
107
this.from.setEnabled(this.track.getMeasures().size() > 1);
108
this.from.addModifyListener(this.listener);
111
previous.addSelectionListener(new SelectionAdapter() {
112
public void widgetSelected(SelectionEvent e) {
113
TuxGuitar.instance().getAction(GoPreviousTrackAction.NAME).process(e);
117
next.addSelectionListener(new SelectionAdapter() {
118
public void widgetSelected(SelectionEvent e) {
119
TuxGuitar.instance().getAction(GoNextTrackAction.NAME).process(e);
125
private GridData getSpinnerData(){
126
GridData data = new GridData();
127
//data.horizontalAlignment = SWT.RIGHT;
128
//data.grabExcessHorizontalSpace = false;
130
//GridData data = new GridData(SWT.RIGHT,SWT.DEFAULT,false,true);
131
//data.minimumWidth = 40;
135
private void loadLyricText(Composite parent){
137
Composite composite = new Composite(parent,SWT.NONE);
138
composite.setLayout(new GridLayout());
139
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
141
this.text = new Text(composite,SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
142
this.text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
143
this.text.setFocus();
144
this.text.setText(this.track.getLyrics().getLyrics());
145
this.text.addModifyListener(this.listener);
148
public void updateSongTrack(){
149
if(this.dialog != null && !this.dialog.isDisposed()){
150
this.track = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret().getSongTrackCoords().getTrack();
151
if(this.label != null && !this.label.isDisposed()){
152
this.label.setText(this.track.getName());
154
if(this.from != null && !this.from.isDisposed()){
155
this.from.setMaximum(this.track.getMeasures().size());
156
this.from.setSelection(this.track.getLyrics().getFrom());
157
this.from.setEnabled(this.track.getMeasures().size() > 1);
159
if(this.text != null && !this.text.isDisposed()){
160
this.text.setText(this.track.getLyrics().getLyrics());
165
public SongTrack getTrack(){