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.MeasureCoords;
24
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeClef;
25
import org.herac.tuxguitar.song.models.Measure;
26
import org.herac.tuxguitar.song.models.SongTrack;
31
* TODO To change the template for this generated type comment go to
32
* Window - Preferences - Java - Code Style - Code Templates
34
public class ChangeClefAction extends Action{
35
public static final String NAME = "action.composition.change-clef";
37
public ChangeClefAction(TablatureEditor tablatureEditor) {
38
super(NAME,true,tablatureEditor);
41
public boolean doAction(TypedEvent e) {
42
showDialog(getEditor().getTablature().getShell());
47
public void showDialog(Shell shell) {
48
MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
49
if (measure != null) {
50
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
52
dialog.setLayout(new GridLayout());
53
dialog.setText(TuxGuitar.getProperty("composition.clef"));
55
//-------clef-------------------------------------
56
Composite clef = new Composite(dialog, SWT.NONE);
57
clef.setLayout(new GridLayout(2,false));
58
clef.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
60
Label numeratorLabel = new Label(clef, SWT.NULL);
61
numeratorLabel.setText(TuxGuitar.getProperty("composition.clef") + ":");
63
final Combo clefs = new Combo(clef, SWT.DROP_DOWN | SWT.READ_ONLY);
65
clefs.add(TuxGuitar.getProperty("composition.clef.treble"));
66
clefs.add(TuxGuitar.getProperty("composition.clef.bass"));
67
clefs.add(TuxGuitar.getProperty("composition.clef.tenor"));
68
clefs.add(TuxGuitar.getProperty("composition.clef.alto"));
69
clefs.select(measure.getMeasure().getClef() - 1);
70
clefs.setLayoutData(getComboData());
72
//--------------------To End Checkbox-------------------------------
73
Composite check = new Composite(dialog, SWT.NONE);
74
check.setLayout(new GridLayout());
75
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
77
final Button toEnd = new Button(check, SWT.CHECK);
78
toEnd.setText(TuxGuitar.getProperty("composition.clef.to-the-end"));
79
toEnd.setSelection(true);
80
//------------------BUTTONS--------------------------
81
Composite buttons = new Composite(dialog, SWT.NONE);
82
buttons.setLayout(new GridLayout(2,false));
83
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
85
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
86
data.minimumWidth = 80;
87
data.minimumHeight = 25;
89
final Button buttonOK = new Button(buttons, SWT.PUSH);
90
buttonOK.setText(TuxGuitar.getProperty("ok"));
91
buttonOK.setLayoutData(data);
92
buttonOK.addSelectionListener(new SelectionAdapter() {
93
public void widgetSelected(SelectionEvent arg0) {
94
boolean toEndValue = toEnd.getSelection();
95
setClef((clefs.getSelectionIndex() + 1),toEndValue);
101
Button buttonCancel = new Button(buttons, SWT.PUSH);
102
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
103
buttonCancel.setLayoutData(data);
104
buttonCancel.addSelectionListener(new SelectionAdapter() {
105
public void widgetSelected(SelectionEvent arg0) {
113
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
114
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
115
dialog.setLocation(x, y);
117
while (!dialog.isDisposed()) {
118
if (!dialog.getDisplay().readAndDispatch()) {
119
dialog.getDisplay().sleep();
126
private GridData getComboData(){
127
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
128
data.minimumWidth = 150;
132
private void setClef(int clef,boolean toEnd){
133
//comienza el undoable
134
UndoableChangeClef undoable = UndoableChangeClef.startUndo();
136
Measure measure = getEditor().getTablature().getCaret().getMeasureCoords().getMeasure();
137
SongTrack track = getEditor().getTablature().getCaret().getSongTrackCoords().getTrack();
138
getSongManager().getTrackManager().changeClef(track,measure.getStart(),clef,toEnd);
140
//actualizo la tablatura
145
getEditor().getUndoManager().addEdit(undoable.endUndo(clef,toEnd));