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.Shell;
18
import org.herac.tuxguitar.gui.TuxGuitar;
19
import org.herac.tuxguitar.gui.actions.Action;
20
import org.herac.tuxguitar.gui.editors.TablatureEditor;
21
import org.herac.tuxguitar.gui.editors.tab.Caret;
22
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
23
import org.herac.tuxguitar.gui.editors.tab.SongCoords;
24
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeTripletFeel;
25
import org.herac.tuxguitar.song.models.MeasureHeader;
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(TablatureEditor tablatureEditor) {
37
super(NAME,tablatureEditor);
40
public boolean doAction(TypedEvent e) {
41
showDialog(getEditor().getTablature().getShell());
46
public void showDialog(Shell shell) {
47
MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
48
if (measure != null) {
49
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
51
dialog.setLayout(new GridLayout());
52
dialog.setText(TuxGuitar.getProperty("composition.tripletfeel"));
54
//-------------TIME SIGNATURE-----------------------------------------------
55
Composite tripletFeel = new Composite(dialog, SWT.NONE);
56
tripletFeel.setLayout(new GridLayout());
57
tripletFeel.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
61
final Button tripletFeelNone = new Button(tripletFeel, SWT.RADIO);
62
tripletFeelNone.setText(TuxGuitar.getProperty("composition.tripletfeel.none"));
63
tripletFeelNone.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_NONE);
65
final Button tripletFeelEighth = new Button(tripletFeel, SWT.RADIO);
66
tripletFeelEighth.setText(TuxGuitar.getProperty("composition.tripletfeel.eighth"));
67
tripletFeelEighth.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_EIGHTH);
69
final Button tripletFeelSixteenth = new Button(tripletFeel, SWT.RADIO);
70
tripletFeelSixteenth.setText(TuxGuitar.getProperty("composition.tripletfeel.sixteenth"));
71
tripletFeelSixteenth.setSelection(measure.getMeasure().getTripletFeel() == MeasureHeader.TRIPLET_FEEL_SIXTEENTH);
73
//--------------------To End Checkbox-------------------------------
74
Composite check = new Composite(dialog, SWT.NONE);
75
check.setLayout(new GridLayout());
76
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
78
final Button toEnd = new Button(check, SWT.CHECK);
79
toEnd.setText(TuxGuitar.getProperty("composition.tripletfeel.to-the-end"));
80
toEnd.setSelection(true);
81
//------------------BUTTONS--------------------------
82
Composite buttons = new Composite(dialog, SWT.NONE);
83
buttons.setLayout(new GridLayout(2,false));
84
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
86
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
87
data.minimumWidth = 80;
88
data.minimumHeight = 25;
91
final Button buttonOk = new Button(buttons, SWT.PUSH);
92
buttonOk.setText(TuxGuitar.getProperty("ok"));
93
buttonOk.setLayoutData(data);
94
buttonOk.addSelectionListener(new SelectionAdapter() {
95
public void widgetSelected(SelectionEvent arg0) {
96
boolean toEndValue = toEnd.getSelection();
97
int tripletFeel = MeasureHeader.TRIPLET_FEEL_NONE;
98
if(tripletFeelNone.getSelection()){
99
tripletFeel = MeasureHeader.TRIPLET_FEEL_NONE;
100
}else if(tripletFeelEighth.getSelection()){
101
tripletFeel = MeasureHeader.TRIPLET_FEEL_EIGHTH;
102
}else if(tripletFeelSixteenth.getSelection()){
103
tripletFeel = MeasureHeader.TRIPLET_FEEL_SIXTEENTH;
105
setTripletFeel(tripletFeel,toEndValue);
110
Button buttonCancel = new Button(buttons, SWT.PUSH);
111
buttonCancel.setLayoutData(data);
112
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
113
buttonCancel.addSelectionListener(new SelectionAdapter() {
114
public void widgetSelected(SelectionEvent arg0) {
119
dialog.setMinimumSize(300,0);
123
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
124
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
125
dialog.setLocation(x, y);
127
while (!dialog.isDisposed()) {
128
if (!dialog.getDisplay().readAndDispatch()) {
129
dialog.getDisplay().sleep();
136
private void setTripletFeel(int tripletFeel,boolean toEnd){
137
//comienza el undoable
138
UndoableChangeTripletFeel undoable = UndoableChangeTripletFeel.startUndo();
140
Caret caret = getEditor().getTablature().getCaret();
141
SongCoords songCoords = caret.getSongCoords();
142
MeasureCoords measure = caret.getMeasureCoords();
144
getSongManager().changeTripletFeel(measure.getMeasure().getStart(),tripletFeel,toEnd);
146
//actualizo la tablatura
151
getEditor().getUndoManager().addEdit(undoable.endUndo(tripletFeel,toEnd));