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.Group;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Shell;
21
import org.herac.tuxguitar.gui.TuxGuitar;
22
import org.herac.tuxguitar.gui.actions.Action;
23
import org.herac.tuxguitar.gui.editors.tab.Caret;
24
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
25
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTimeSignature;
26
import org.herac.tuxguitar.gui.util.DialogUtils;
27
import org.herac.tuxguitar.song.managers.TGSongManager;
28
import org.herac.tuxguitar.song.models.TGTimeSignature;
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() {
40
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
43
protected int execute(TypedEvent e){
44
showDialog(getEditor().getTablature().getShell());
48
public void showDialog(Shell shell) {
49
TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
50
if (measure != null) {
51
final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
53
dialog.setLayout(new GridLayout());
54
dialog.setText(TuxGuitar.getProperty("composition.timesignature"));
56
//-------------TIME SIGNATURE-----------------------------------------------
57
Group timeSignature = new Group(dialog,SWT.SHADOW_ETCHED_IN);
58
timeSignature.setLayout(new GridLayout(2,false));
59
timeSignature.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
60
timeSignature.setText(TuxGuitar.getProperty("composition.timesignature"));
62
TGTimeSignature currentTimeSignature = measure.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());
82
//--------------------To End Checkbox-------------------------------
83
Group check = new Group(dialog,SWT.SHADOW_ETCHED_IN);
84
check.setLayout(new GridLayout());
85
check.setText(TuxGuitar.getProperty("options"));
86
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
88
final Button toEnd = new Button(check, SWT.CHECK);
89
toEnd.setText(TuxGuitar.getProperty("composition.timesignature.to-the-end"));
90
toEnd.setSelection(true);
91
//------------------BUTTONS--------------------------
92
Composite buttons = new Composite(dialog, SWT.NONE);
93
buttons.setLayout(new GridLayout(2,false));
94
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
96
final Button buttonOk = new Button(buttons, SWT.PUSH);
97
buttonOk.setText(TuxGuitar.getProperty("ok"));
98
buttonOk.setLayoutData(getButtonData());
99
buttonOk.addSelectionListener(new SelectionAdapter() {
100
public void widgetSelected(SelectionEvent arg0) {
101
boolean toEndValue = toEnd.getSelection();
102
int numeratorValue = Integer.parseInt(numerator.getText());
103
int denominatorValue = Integer.parseInt(denominator.getText());
105
TGTimeSignature timeSignature = getSongManager().getFactory().newTimeSignature();
106
timeSignature.setNumerator(numeratorValue);
107
timeSignature.getDenominator().setValue(denominatorValue);
109
setTimeSignature(timeSignature,toEndValue);
115
Button buttonCancel = new Button(buttons, SWT.PUSH);
116
buttonCancel.setLayoutData(getButtonData());
117
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
118
buttonCancel.addSelectionListener(new SelectionAdapter() {
119
public void widgetSelected(SelectionEvent arg0) {
124
dialog.setDefaultButton( buttonOk );
126
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
130
private GridData getButtonData(){
131
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
132
data.minimumWidth = 80;
133
data.minimumHeight = 25;
137
private GridData getComboData(){
138
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
139
data.minimumWidth = 150;
143
protected void setTimeSignature(TGTimeSignature timeSignature,boolean toEnd){
144
//comienza el undoable
145
UndoableChangeTimeSignature undoable = UndoableChangeTimeSignature.startUndo();
147
Caret caret = getEditor().getTablature().getCaret();
148
TGMeasureImpl measure = caret.getMeasure();
150
getSongManager().changeTimeSignature(measure.getStart(),timeSignature,toEnd);
152
TuxGuitar.instance().getFileHistory().setUnsavedFile();
154
//actualizo la tablatura
158
addUndoableEdit(undoable.endUndo(timeSignature,toEnd));
161
public TGSongManager getSongManager(){
162
return super.getSongManager();