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.TGMeasureImpl;
24
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeClef;
25
import org.herac.tuxguitar.gui.util.DialogUtils;
26
import org.herac.tuxguitar.song.models.TGMeasure;
27
import org.herac.tuxguitar.song.models.TGTrack;
32
* TODO To change the template for this generated type comment go to
33
* Window - Preferences - Java - Code Style - Code Templates
35
public class ChangeClefAction extends Action{
36
public static final String NAME = "action.composition.change-clef";
38
public ChangeClefAction() {
39
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
42
protected int execute(TypedEvent e){
43
showDialog(getEditor().getTablature().getShell());
47
public void showDialog(Shell shell) {
48
TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
49
if (measure != null) {
50
final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
52
dialog.setLayout(new GridLayout());
53
dialog.setText(TuxGuitar.getProperty("composition.clef"));
55
//-------clef-------------------------------------
56
Group clef = new Group(dialog,SWT.SHADOW_ETCHED_IN);
57
clef.setLayout(new GridLayout(2,false));
58
clef.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
59
clef.setText(TuxGuitar.getProperty("composition.clef"));
61
Label numeratorLabel = new Label(clef, SWT.NULL);
62
numeratorLabel.setText(TuxGuitar.getProperty("composition.clef") + ":");
64
final Combo clefs = new Combo(clef, SWT.DROP_DOWN | SWT.READ_ONLY);
66
clefs.add(TuxGuitar.getProperty("composition.clef.treble"));
67
clefs.add(TuxGuitar.getProperty("composition.clef.bass"));
68
clefs.add(TuxGuitar.getProperty("composition.clef.tenor"));
69
clefs.add(TuxGuitar.getProperty("composition.clef.alto"));
70
clefs.select(measure.getClef() - 1);
71
clefs.setLayoutData(getComboData());
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.clef.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.RIGHT,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
setClef((clefs.getSelectionIndex() + 1),toEndValue);
99
Button buttonCancel = new Button(buttons, SWT.PUSH);
100
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
101
buttonCancel.setLayoutData(getButtonData());
102
buttonCancel.addSelectionListener(new SelectionAdapter() {
103
public void widgetSelected(SelectionEvent arg0) {
108
dialog.setDefaultButton( buttonOK );
110
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
114
private GridData getComboData(){
115
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
116
data.minimumWidth = 150;
120
protected GridData getButtonData(){
121
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
122
data.minimumWidth = 80;
123
data.minimumHeight = 25;
127
protected void setClef(int clef,boolean toEnd){
128
//comienza el undoable
129
UndoableChangeClef undoable = UndoableChangeClef.startUndo();
131
TGMeasure measure = getEditor().getTablature().getCaret().getMeasure();
132
TGTrack track = getEditor().getTablature().getCaret().getTrack();
133
getSongManager().getTrackManager().changeClef(track,measure.getStart(),clef,toEnd);
135
TuxGuitar.instance().getFileHistory().setUnsavedFile();
137
//actualizo la tablatura
141
addUndoableEdit(undoable.endUndo(clef,toEnd));