~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/lyric/LyricEditor.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.herac.tuxguitar.gui.editors.lyric;
2
 
 
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;
19
 
 
20
 
public class LyricEditor {
21
 
        private static int EDITOR_WIDTH = 400;
22
 
        private static int EDITOR_HEIGHT = 200;
23
 
        
24
 
        private SongTrack track;
25
 
        private Shell dialog;
26
 
        private LyricModifyListener listener;
27
 
        private Label label;
28
 
        private Spinner from;
29
 
        private Text text;
30
 
        
31
 
        
32
 
        public LyricEditor(){           
33
 
                this.listener = new LyricModifyListener(this);
34
 
        }
35
 
        
36
 
        public void show() {            
37
 
                Shell shell = TuxGuitar.instance().getShell();
38
 
                Rectangle sBounds = shell.getBounds();
39
 
                Rectangle dBounds = shell.getDisplay().getBounds();
40
 
 
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"));
44
 
                
45
 
                this.updateSongTrack();
46
 
                this.loadComposites();
47
 
                
48
 
                
49
 
 
50
 
        int x = shell.getBounds().x + (shell.getBounds().width - EDITOR_WIDTH) / 2;
51
 
        int y = shell.getBounds().y + (shell.getBounds().height - EDITOR_HEIGHT) / 2;
52
 
        
53
 
        this.dialog.setSize(EDITOR_WIDTH,EDITOR_HEIGHT);
54
 
        this.dialog.setLocation(x, y);
55
 
                this.dialog.open();             
56
 
                
57
 
                while (!dialog.isDisposed()) {
58
 
                        if (!dialog.getDisplay().readAndDispatch()) {
59
 
                                dialog.getDisplay().sleep();
60
 
                        }
61
 
                }       
62
 
                                
63
 
                this.track = null;
64
 
                this.label = null;
65
 
                this.text = null;               
66
 
                this.dialog = null;                             
67
 
        }
68
 
 
69
 
        private void loadComposites(){
70
 
                
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));
74
 
                
75
 
                loadToolBar(composite);
76
 
                loadLyricText(composite);
77
 
        }
78
 
 
79
 
 
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));
84
 
                
85
 
                Button previous = new Button(composite, SWT.ARROW | SWT.LEFT);
86
 
                Button next = new Button(composite, SWT.ARROW | SWT.RIGHT);
87
 
                
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));
91
 
                
92
 
                
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));
96
 
 
97
 
                
98
 
                //GridData fromData = new GridData(SWT.END,SWT.CENTER,false,true);
99
 
                //fromData.widthHint = 24;
100
 
                
101
 
                this.from = new Spinner(composite,SWT.BORDER);
102
 
                this.from.setLayoutData(getSpinnerData());
103
 
                
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);
109
 
                
110
 
                
111
 
                previous.addSelectionListener(new SelectionAdapter() {
112
 
                        public void widgetSelected(SelectionEvent e) {
113
 
                                TuxGuitar.instance().getAction(GoPreviousTrackAction.NAME).process(e);
114
 
                                composite.layout();
115
 
                        }               
116
 
                });             
117
 
                next.addSelectionListener(new SelectionAdapter() {
118
 
                        public void widgetSelected(SelectionEvent e) {
119
 
                                TuxGuitar.instance().getAction(GoNextTrackAction.NAME).process(e);
120
 
                        }               
121
 
                });             
122
 
                
123
 
        }
124
 
 
125
 
    private GridData getSpinnerData(){
126
 
        GridData data = new GridData();
127
 
        //data.horizontalAlignment = SWT.RIGHT;
128
 
        //data.grabExcessHorizontalSpace = false;
129
 
        
130
 
        //GridData data = new GridData(SWT.RIGHT,SWT.DEFAULT,false,true);
131
 
        //data.minimumWidth = 40;
132
 
        return data;
133
 
    }
134
 
 
135
 
        private void loadLyricText(Composite parent){
136
 
                
137
 
                Composite composite = new Composite(parent,SWT.NONE);
138
 
                composite.setLayout(new GridLayout());
139
 
                composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
140
 
                
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);
146
 
        }
147
 
        
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());
153
 
                        }
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);
158
 
                        }                       
159
 
                        if(this.text != null && !this.text.isDisposed()){
160
 
                                this.text.setText(this.track.getLyrics().getLyrics());
161
 
                        }
162
 
                }
163
 
        }       
164
 
        
165
 
        public SongTrack getTrack(){
166
 
                return this.track;
167
 
        }
168
 
        
169
 
}