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.composition;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.SelectionAdapter;
11
import org.eclipse.swt.events.SelectionEvent;
12
import org.eclipse.swt.events.TypedEvent;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Combo;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Label;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Spinner;
21
import org.herac.tuxguitar.gui.TuxGuitar;
22
import org.herac.tuxguitar.gui.actions.Action;
23
import org.herac.tuxguitar.gui.editors.TablatureEditor;
24
import org.herac.tuxguitar.gui.editors.tab.Caret;
25
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
26
import org.herac.tuxguitar.gui.editors.tab.SongCoords;
27
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTempo;
28
import org.herac.tuxguitar.gui.util.MessageDialog;
29
import org.herac.tuxguitar.song.models.Tempo;
34
* TODO To change the template for this generated type comment go to
35
* Window - Preferences - Java - Code Style - Code Templates
37
public class ChangeTempoAction extends Action{
38
public static final String NAME = "action.composition.change-tempo";
39
private static final int MIN_TEMPO = 30;
40
private static final int MAX_TEMPO = 320;
42
private static final int[] DEFAULT_PERCENTS = new int[]{25,50,75,100,125,150,175,200};
44
public ChangeTempoAction(TablatureEditor tablatureEditor) {
45
super(NAME,true,tablatureEditor);
48
public boolean doAction(TypedEvent e) {
49
showDialog(getEditor().getTablature().getShell());
54
public void showDialog(Shell shell) {
55
MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
56
if (measure != null) {
57
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
59
dialog.setLayout(new GridLayout());
60
dialog.setText(TuxGuitar.getProperty("composition.tempo"));
62
//-----------------TEMPO------------------------
63
Composite composite = new Composite(dialog, SWT.NONE);
64
composite.setLayout(new GridLayout(2,false));
65
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
67
Tempo currentTempo = measure.getMeasure().getTempo();
68
Label tempoLabel = new Label(composite, SWT.NULL);
69
tempoLabel.setText(TuxGuitar.getProperty("composition.tempo"));
71
final Spinner tempo = new Spinner(composite, SWT.BORDER);
72
tempo.setLayoutData(getSpinnerData());
73
tempo.setMinimum(MIN_TEMPO);
74
tempo.setMaximum(MAX_TEMPO);
75
tempo.setSelection(currentTempo.getValue());
77
Label percentLabel = new Label(composite, SWT.NULL);
78
percentLabel.setText(TuxGuitar.getProperty("composition.tempo-percent"));
80
final Combo percent = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
81
percent.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
82
for(int i = 0; i < DEFAULT_PERCENTS.length; i ++){
83
percent.add(Integer.toString(DEFAULT_PERCENTS[i]) + "%",i);
84
if(currentTempo.getPercent() == DEFAULT_PERCENTS[i]){
88
//------------------BUTTONS--------------------------
89
Composite buttons = new Composite(dialog, SWT.NONE);
90
buttons.setLayout(new GridLayout(2,false));
91
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
93
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
94
data.minimumWidth = 80;
95
data.minimumHeight = 25;
97
final Button buttonOK = new Button(buttons, SWT.PUSH);
98
buttonOK.setText(TuxGuitar.getProperty("ok"));
99
buttonOK.setLayoutData(data);
100
buttonOK.addSelectionListener(new SelectionAdapter() {
101
public void widgetSelected(SelectionEvent arg0) {
102
boolean valid = false;
104
int tempoValue = tempo.getSelection();
106
if(tempoValue >= MIN_TEMPO && MAX_TEMPO <= 320){
107
Tempo tempo = new Tempo(tempoValue,DEFAULT_PERCENTS[ (percent.getSelectionIndex() >= 0)?percent.getSelectionIndex():3 ]);
113
showErrorMessage(TuxGuitar.getProperty("composition.tempo.invalid"));
120
Button buttonCancel = new Button(buttons, SWT.PUSH);
121
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
122
buttonCancel.setLayoutData(data);
123
buttonCancel.addSelectionListener(new SelectionAdapter() {
124
public void widgetSelected(SelectionEvent arg0) {
132
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
133
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
134
dialog.setLocation(x, y);
136
while (!dialog.isDisposed()) {
137
if (!dialog.getDisplay().readAndDispatch()) {
138
dialog.getDisplay().sleep();
144
private GridData getSpinnerData(){
145
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
146
data.minimumWidth = 150;
150
private void setTempo(Tempo tempo){
151
//comienza el undoable
152
UndoableChangeTempo undoable = UndoableChangeTempo.startUndo();
154
Caret caret = getEditor().getTablature().getCaret();
155
SongCoords songCoords = caret.getSongCoords();
156
MeasureCoords measure = caret.getMeasureCoords();
158
getSongManager().changeTempo(measure.getMeasure().getStart(),tempo,true);
160
//actualizo la tablatura
165
getEditor().getUndoManager().addEdit(undoable.endUndo(tempo));
169
private void showErrorMessage(String message){
170
String name = "Error Message";
171
new MessageDialog(name,message,SWT.ICON_ERROR | SWT.OK).show(getEditor().getTablature().getShell());