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.herac.tuxguitar.gui.TuxGuitar;
21
import org.herac.tuxguitar.gui.actions.Action;
22
import org.herac.tuxguitar.gui.editors.TablatureEditor;
23
import org.herac.tuxguitar.gui.editors.tab.Caret;
24
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
25
import org.herac.tuxguitar.gui.editors.tab.SongCoords;
26
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTimeSignature;
27
import org.herac.tuxguitar.song.models.Duration;
28
import org.herac.tuxguitar.song.models.TimeSignature;
33
* TODO To change the template for this generated type comment go to
34
* Window - Preferences - Java - Code Style - Code Templates
36
public class ChangeTimeSignatureAction extends Action{
37
public static final String NAME = "action.composition.change-time-signature";
39
public ChangeTimeSignatureAction(TablatureEditor tablatureEditor) {
40
super(NAME,true,tablatureEditor);
43
public boolean doAction(TypedEvent e) {
44
showDialog(getEditor().getTablature().getShell());
49
public void showDialog(Shell shell) {
50
MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
51
if (measure != null) {
52
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
54
dialog.setLayout(new GridLayout());
55
dialog.setText(TuxGuitar.getProperty("composition.timesignature"));
57
//-------------TIME SIGNATURE-----------------------------------------------
58
Composite timeSignature = new Composite(dialog, SWT.NONE);
59
timeSignature.setLayout(new GridLayout(2,false));
60
timeSignature.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
62
TimeSignature currentTimeSignature = measure.getMeasure().getTimeSignature();
64
Label numeratorLabel = new Label(timeSignature, SWT.NULL);
65
numeratorLabel.setText(TuxGuitar.getProperty("composition.timesignature.Numerator"));
66
final Combo numerator = new Combo(timeSignature, SWT.DROP_DOWN | SWT.READ_ONLY);
67
for (int i = 1; i <= 32; i++) {
68
numerator.add(Integer.toString(i));
70
numerator.setText(Integer.toString(currentTimeSignature.getNumerator()));
71
numerator.setLayoutData(getComboData());
73
Label denominatorLabel = new Label(timeSignature, SWT.NULL);
74
denominatorLabel.setText(TuxGuitar.getProperty("composition.timesignature.denominator"));
75
final Combo denominator = new Combo(timeSignature, SWT.DROP_DOWN | SWT.READ_ONLY);
76
for (int i = 1; i <= 32; i = i * 2) {
77
denominator.add(Integer.toString(i));
79
denominator.setText(Integer.toString(currentTimeSignature.getDenominator().getValue()));
80
denominator.setLayoutData(getComboData());
81
//--------------------To End Checkbox-------------------------------
82
Composite check = new Composite(dialog, SWT.NONE);
83
check.setLayout(new GridLayout());
84
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
86
final Button toEnd = new Button(check, SWT.CHECK);
87
toEnd.setText(TuxGuitar.getProperty("composition.timesignature.to-the-end"));
88
toEnd.setSelection(true);
89
//------------------BUTTONS--------------------------
90
Composite buttons = new Composite(dialog, SWT.NONE);
91
buttons.setLayout(new GridLayout(2,false));
92
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
94
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
95
data.minimumWidth = 80;
96
data.minimumHeight = 25;
99
final Button buttonOk = new Button(buttons, SWT.PUSH);
100
buttonOk.setText(TuxGuitar.getProperty("ok"));
101
buttonOk.setLayoutData(data);
102
buttonOk.addSelectionListener(new SelectionAdapter() {
103
public void widgetSelected(SelectionEvent arg0) {
104
boolean toEndValue = toEnd.getSelection();
105
int numeratorValue = Integer.parseInt(numerator.getText());
106
int denominatorValue = Integer.parseInt(denominator.getText());
107
TimeSignature timeSignature = new TimeSignature(numeratorValue,new Duration(denominatorValue));
108
setTimeSignature(timeSignature,toEndValue);
114
Button buttonCancel = new Button(buttons, SWT.PUSH);
115
buttonCancel.setLayoutData(data);
116
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
117
buttonCancel.addSelectionListener(new SelectionAdapter() {
118
public void widgetSelected(SelectionEvent arg0) {
126
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
127
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
128
dialog.setLocation(x, y);
130
while (!dialog.isDisposed()) {
131
if (!dialog.getDisplay().readAndDispatch()) {
132
dialog.getDisplay().sleep();
138
private GridData getComboData(){
139
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
140
data.minimumWidth = 150;
144
private void setTimeSignature(TimeSignature timeSignature,boolean toEnd){
145
//comienza el undoable
146
UndoableChangeTimeSignature undoable = UndoableChangeTimeSignature.startUndo();
148
Caret caret = getEditor().getTablature().getCaret();
149
SongCoords songCoords = caret.getSongCoords();
150
MeasureCoords measure = caret.getMeasureCoords();
152
getSongManager().changeTimeSignature(measure.getMeasure().getStart(),timeSignature,toEnd);
154
//actualizo la tablatura
159
getEditor().getUndoManager().addEdit(undoable.endUndo(timeSignature,toEnd));