2
* Created on 17-dic-2005
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.actions.transport;
9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.events.TypedEvent;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Button;
20
import org.eclipse.swt.widgets.Combo;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Group;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Spinner;
27
import org.herac.tuxguitar.gui.TuxGuitar;
28
import org.herac.tuxguitar.gui.actions.Action;
29
import org.herac.tuxguitar.gui.util.DialogUtils;
30
import org.herac.tuxguitar.player.base.MidiPlayerMode;
35
* TODO To change the template for this generated type comment go to Window -
36
* Preferences - Java - Code Style - Code Templates
38
public class TransportModeAction extends Action {
39
public static final String NAME = "action.transport.mode";
41
protected static final int MIN_SELECTION = 1;
42
protected static final int MAX_SELECTION = 500;
43
protected static final int[] DEFAULT_PERCENTS = new int[]{25,50,75,100,125,150,175,200};
45
protected Button single;
46
protected Button singleLoop;
47
protected Combo singlePercent;
49
protected Button custom;
50
protected Spinner customFrom;
51
protected Spinner customTo;
52
protected Spinner customIncrement;
54
public TransportModeAction() {
55
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | KEY_BINDING_AVAILABLE);
58
protected int execute(TypedEvent e){
59
this.showDialog(e.widget.getDisplay().getActiveShell(), TuxGuitar.instance().getPlayer().getMode());
63
public void showDialog(final Shell parent,final MidiPlayerMode mode) {
64
final Shell dialog = DialogUtils.newDialog(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
65
dialog.setLayout(new GridLayout());
66
dialog.setText(TuxGuitar.getProperty("transport.mode"));
68
// ----------------------------------------------------------------------
70
Composite radios = new Composite(dialog, SWT.NONE);
71
radios.setLayout(new GridLayout());
72
radios.setLayoutData(getMainData());
75
this.single = new Button(radios, SWT.RADIO);
76
this.single.setText(TuxGuitar.getProperty("transport.mode.simple"));
77
this.single.setSelection(mode.getType() == MidiPlayerMode.TYPE_SINGLE);
78
RadioSelectionAdapter singleAdapter = new RadioSelectionAdapter(this.single);
80
Group singleGroup = new Group(radios, SWT.SHADOW_ETCHED_IN);
81
singleGroup.setLayout(new GridLayout(2,false));
82
singleGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
83
singleGroup.setText(TuxGuitar.getProperty("transport.mode.simple"));
84
singleAdapter.addControl(singleGroup);
86
singleAdapter.addControl(makeLabel(singleGroup, TuxGuitar.getProperty("transport.mode.simple.tempo-percent"),SWT.LEFT,1));
87
this.singlePercent = new Combo(singleGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
88
this.singlePercent.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
89
for(int i = 0; i < DEFAULT_PERCENTS.length; i ++){
90
this.singlePercent.add(Integer.toString(DEFAULT_PERCENTS[i]) + "%",i);
91
if(mode.getSinglePercent() == DEFAULT_PERCENTS[i]){
92
this.singlePercent.select(i);
95
singleAdapter.addControl(this.singlePercent);
97
this.singleLoop = new Button(singleGroup, SWT.CHECK);
98
this.singleLoop.setText(TuxGuitar.getProperty("transport.mode.simple.loop"));
99
this.singleLoop.setSelection(mode.isLoop());
100
singleAdapter.addControl(this.singleLoop);
102
GridData loopedData = new GridData(SWT.FILL,SWT.FILL,true,true);
103
loopedData.horizontalSpan = 2;
104
this.singleLoop.setLayoutData(loopedData);
107
this.custom = new Button(radios, SWT.RADIO);
108
this.custom.setText(TuxGuitar.getProperty("transport.mode.trainer"));
109
this.custom.setSelection(mode.getType() == MidiPlayerMode.TYPE_CUSTOM);
110
RadioSelectionAdapter customAdapter = new RadioSelectionAdapter(this.custom);
112
Group trainerGroup = new Group(radios, SWT.SHADOW_ETCHED_IN);
113
trainerGroup.setLayout(new GridLayout(6,false));
114
trainerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
115
trainerGroup.setText(TuxGuitar.getProperty("transport.mode.trainer"));
116
customAdapter.addControl(trainerGroup);
118
customAdapter.addControl(makeLabel(trainerGroup, TuxGuitar.getProperty("composition.tempo"),SWT.LEFT,1));
119
this.customFrom = new Spinner(trainerGroup,SWT.BORDER);
120
this.customFrom.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
121
this.customFrom.setMinimum(MIN_SELECTION);
122
this.customFrom.setMaximum(MAX_SELECTION);
123
this.customFrom.setSelection(mode.getCustomPercentFrom());
124
customAdapter.addControl(this.customFrom);
125
customAdapter.addControl(makeLabel(trainerGroup, "%",SWT.LEFT,1));
127
customAdapter.addControl(makeLabel(trainerGroup, TuxGuitar.getProperty("edit.to"),SWT.RIGHT,1));
128
this.customTo = new Spinner(trainerGroup,SWT.BORDER);
129
this.customTo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
130
this.customTo.setMinimum(MIN_SELECTION);
131
this.customTo.setMaximum(MAX_SELECTION);
132
this.customTo.setSelection(mode.getCustomPercentTo());
133
customAdapter.addControl(this.customTo);
134
customAdapter.addControl(makeLabel(trainerGroup, "%",SWT.LEFT,1));
136
customAdapter.addControl(makeLabel(trainerGroup, TuxGuitar.getProperty("transport.mode.trainer.increment-description"),SWT.LEFT,4));
137
this.customIncrement = new Spinner(trainerGroup,SWT.BORDER);
138
this.customIncrement.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
139
this.customIncrement.setMinimum(MIN_SELECTION);
140
this.customIncrement.setMaximum(MAX_SELECTION);
141
this.customIncrement.setSelection(mode.getCustomPercentIncrement());
142
customAdapter.addControl(this.customIncrement);
143
customAdapter.addControl(makeLabel(trainerGroup, "%",SWT.LEFT,1));
145
SpinnerSelectionAdapter spinnerAdapter = new SpinnerSelectionAdapter(this.customFrom,this.customTo,this.customIncrement);
146
this.customFrom.addSelectionListener(spinnerAdapter);
147
this.customTo.addSelectionListener(spinnerAdapter);
148
this.customIncrement.addSelectionListener(spinnerAdapter);
150
singleAdapter.update();
151
customAdapter.update();
152
// ------------------BUTTONS--------------------------
153
Composite buttons = new Composite(dialog, SWT.NONE);
154
buttons.setLayout(new GridLayout(2, false));
155
buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, true));
157
final Button buttonOK = new Button(buttons, SWT.PUSH);
158
buttonOK.setText(TuxGuitar.getProperty("ok"));
159
buttonOK.setLayoutData(getButtonData());
160
buttonOK.addSelectionListener(new SelectionAdapter() {
161
public void widgetSelected(SelectionEvent arg0) {
167
Button buttonCancel = new Button(buttons, SWT.PUSH);
168
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
169
buttonCancel.setLayoutData(getButtonData());
170
buttonCancel.addSelectionListener(new SelectionAdapter() {
171
public void widgetSelected(SelectionEvent arg0) {
176
dialog.setDefaultButton( buttonOK );
178
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
181
private GridData getMainData(){
182
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
183
data.minimumWidth = 350;
187
private GridData getButtonData(){
188
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
189
data.minimumWidth = 80;
190
data.minimumHeight = 25;
194
private Label makeLabel(Composite parent,String text,int aligment,int horizontalSpan){
195
Label label = new Label(parent,SWT.CENTER | aligment);
197
GridData data = new GridData(SWT.FILL,SWT.CENTER,true,true);
198
data.horizontalSpan = horizontalSpan;
199
label.setLayoutData(data);
203
protected void updateMode(MidiPlayerMode mode){
204
int type = (this.custom.getSelection())?MidiPlayerMode.TYPE_CUSTOM:MidiPlayerMode.TYPE_SINGLE;
206
mode.setLoop( (type == MidiPlayerMode.TYPE_CUSTOM || (type == MidiPlayerMode.TYPE_SINGLE && this.singleLoop.getSelection())));
207
mode.setSinglePercent( this.singlePercent.getSelectionIndex() >= 0?DEFAULT_PERCENTS[this.singlePercent.getSelectionIndex()]:MidiPlayerMode.DEFAULT_TEMPO_PERCENT);
208
mode.setCustomPercentFrom(this.customFrom.getSelection());
209
mode.setCustomPercentTo(this.customTo.getSelection());
210
mode.setCustomPercentIncrement(this.customIncrement.getSelection());
214
private class RadioSelectionAdapter extends SelectionAdapter{
215
private Button control;
216
private List controls;
218
public RadioSelectionAdapter(Button control) {
219
this.controls = new ArrayList();
220
this.control = control;
221
this.control.addSelectionListener(this);
224
public void addControl(Control control){
225
this.controls.add(control);
228
public void update(){
229
boolean enabled = this.control.getSelection();
230
Iterator it = this.controls.iterator();
232
Control control = (Control)it.next();
233
control.setEnabled(enabled);
237
public void widgetSelected(SelectionEvent e) {
243
private class SpinnerSelectionAdapter extends SelectionAdapter{
245
private Spinner from;
246
private Spinner increment;
248
public SpinnerSelectionAdapter(Spinner from,Spinner to, Spinner increment) {
251
this.increment = increment;
254
public void widgetSelected(SelectionEvent e) {
255
if(e.widget.equals(this.from)){
256
if(this.from.getSelection() < MIN_SELECTION){
257
this.from.setSelection(MIN_SELECTION);
258
}else if(this.from.getSelection() >= this.to.getSelection()){
259
this.from.setSelection(this.to.getSelection() - 1);
261
}else if(e.widget.equals(this.to)){
262
if(this.to.getSelection() <= this.from.getSelection()){
263
this.to.setSelection(this.from.getSelection() + 1);
264
}else if(this.to.getSelection() > MAX_SELECTION){
265
this.to.setSelection(MAX_SELECTION);
268
if(this.increment.getSelection() > (this.to.getSelection() - this.from.getSelection())){
269
this.increment.setSelection(this.to.getSelection() - this.from.getSelection());
b'\\ No newline at end of file'