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.Composite;
17
import org.eclipse.swt.widgets.Group;
18
import org.eclipse.swt.widgets.Shell;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.actions.Action;
21
import org.herac.tuxguitar.gui.editors.tab.Caret;
22
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
23
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTripletFeel;
24
import org.herac.tuxguitar.gui.util.DialogUtils;
25
import org.herac.tuxguitar.song.models.TGMeasureHeader;
30
* TODO To change the template for this generated type comment go to
31
* Window - Preferences - Java - Code Style - Code Templates
33
public class ChangeTripletFeelAction extends Action{
34
public static final String NAME = "action.composition.change-triplet-feel";
36
public ChangeTripletFeelAction() {
37
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
40
protected int execute(TypedEvent e){
41
showDialog(getEditor().getTablature().getShell());
45
public void showDialog(Shell shell) {
46
TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
47
if (measure != null) {
48
final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
50
dialog.setLayout(new GridLayout());
51
dialog.setText(TuxGuitar.getProperty("composition.tripletfeel"));
52
dialog.setMinimumSize(300,0);
54
//-------------TIME SIGNATURE-----------------------------------------------
55
Group tripletFeel = new Group(dialog,SWT.SHADOW_ETCHED_IN);
56
tripletFeel.setLayout(new GridLayout());
57
tripletFeel.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
58
tripletFeel.setText(TuxGuitar.getProperty("composition.tripletfeel"));
61
final Button tripletFeelNone = new Button(tripletFeel, SWT.RADIO);
62
tripletFeelNone.setText(TuxGuitar.getProperty("composition.tripletfeel.none"));
63
tripletFeelNone.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_NONE);
65
final Button tripletFeelEighth = new Button(tripletFeel, SWT.RADIO);
66
tripletFeelEighth.setText(TuxGuitar.getProperty("composition.tripletfeel.eighth"));
67
tripletFeelEighth.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_EIGHTH);
69
final Button tripletFeelSixteenth = new Button(tripletFeel, SWT.RADIO);
70
tripletFeelSixteenth.setText(TuxGuitar.getProperty("composition.tripletfeel.sixteenth"));
71
tripletFeelSixteenth.setSelection(measure.getTripletFeel() == TGMeasureHeader.TRIPLET_FEEL_SIXTEENTH);
73
//--------------------To End Checkbox-------------------------------
74
Group check = new Group(dialog,SWT.SHADOW_ETCHED_IN);
75
check.setLayout(new GridLayout());
76
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
77
check.setText(TuxGuitar.getProperty("options"));
79
final Button toEnd = new Button(check, SWT.CHECK);
80
toEnd.setText(TuxGuitar.getProperty("composition.tripletfeel.to-the-end"));
81
toEnd.setSelection(true);
82
//------------------BUTTONS--------------------------
83
Composite buttons = new Composite(dialog, SWT.NONE);
84
buttons.setLayout(new GridLayout(2,false));
85
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
87
final Button buttonOk = new Button(buttons, SWT.PUSH);
88
buttonOk.setText(TuxGuitar.getProperty("ok"));
89
buttonOk.setLayoutData(getButtonData());
90
buttonOk.addSelectionListener(new SelectionAdapter() {
91
public void widgetSelected(SelectionEvent arg0) {
92
boolean toEndValue = toEnd.getSelection();
93
int tripletFeel = TGMeasureHeader.TRIPLET_FEEL_NONE;
94
if(tripletFeelNone.getSelection()){
95
tripletFeel = TGMeasureHeader.TRIPLET_FEEL_NONE;
96
}else if(tripletFeelEighth.getSelection()){
97
tripletFeel = TGMeasureHeader.TRIPLET_FEEL_EIGHTH;
98
}else if(tripletFeelSixteenth.getSelection()){
99
tripletFeel = TGMeasureHeader.TRIPLET_FEEL_SIXTEENTH;
101
setTripletFeel(tripletFeel,toEndValue);
106
Button buttonCancel = new Button(buttons, SWT.PUSH);
107
buttonCancel.setLayoutData(getButtonData());
108
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
109
buttonCancel.addSelectionListener(new SelectionAdapter() {
110
public void widgetSelected(SelectionEvent arg0) {
115
dialog.setDefaultButton( buttonOk );
117
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
121
private GridData getButtonData(){
122
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
123
data.minimumWidth = 80;
124
data.minimumHeight = 25;
128
protected void setTripletFeel(int tripletFeel,boolean toEnd){
129
//comienza el undoable
130
UndoableChangeTripletFeel undoable = UndoableChangeTripletFeel.startUndo();
132
Caret caret = getEditor().getTablature().getCaret();
133
TGMeasureImpl measure = caret.getMeasure();
135
getSongManager().changeTripletFeel(measure.getStart(),tripletFeel,toEnd);
137
TuxGuitar.instance().getFileHistory().setUnsavedFile();
139
//actualizo la tablatura
143
addUndoableEdit(undoable.endUndo(tripletFeel,toEnd));