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.UndoableChangeKeySignature;
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 ChangeKeySignatureAction extends Action{
35
public static final String NAME = "action.composition.change-key-signature";
37
public ChangeKeySignatureAction(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.keysignature"));
55
//-------key Signature-------------------------------------
56
Composite keySignature = new Composite(dialog, SWT.NONE);
57
keySignature.setLayout(new GridLayout(2,false));
58
keySignature.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
60
Label numeratorLabel = new Label(keySignature, SWT.NULL);
61
numeratorLabel.setText(TuxGuitar.getProperty("composition.keysignature") + ":");
63
final Combo keySignatures = new Combo(keySignature, SWT.DROP_DOWN | SWT.READ_ONLY);
65
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.natural"));
66
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-1"));
67
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-2"));
68
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-3"));
69
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-4"));
70
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-5"));
71
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-6"));
72
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.sharp-7"));
73
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-1"));
74
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-2"));
75
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-3"));
76
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-4"));
77
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-5"));
78
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-6"));
79
keySignatures.add(TuxGuitar.getProperty("composition.keysignature.flat-7"));
80
keySignatures.select(measure.getMeasure().getKeySignature());
81
keySignatures.setLayoutData(getComboData());
82
//--------------------To End Checkbox-------------------------------
83
Composite check = new Composite(dialog, SWT.NONE);
84
check.setLayout(new GridLayout());
85
check.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
87
final Button toEnd = new Button(check, SWT.CHECK);
88
toEnd.setText(TuxGuitar.getProperty("composition.keysignature.to-the-end"));
89
toEnd.setSelection(true);
90
//------------------BUTTONS--------------------------
91
Composite buttons = new Composite(dialog, SWT.NONE);
92
buttons.setLayout(new GridLayout(2,false));
93
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
95
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
96
data.minimumWidth = 80;
97
data.minimumHeight = 25;
99
final Button buttonOK = new Button(buttons, SWT.PUSH);
100
buttonOK.setText(TuxGuitar.getProperty("ok"));
101
buttonOK.setLayoutData(data);
102
buttonOK.addSelectionListener(new SelectionAdapter() {
103
public void widgetSelected(SelectionEvent arg0) {
104
boolean toEndValue = toEnd.getSelection();
105
setKeySignature(keySignatures.getSelectionIndex(),toEndValue);
111
Button buttonCancel = new Button(buttons, SWT.PUSH);
112
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
113
buttonCancel.setLayoutData(data);
114
buttonCancel.addSelectionListener(new SelectionAdapter() {
115
public void widgetSelected(SelectionEvent arg0) {
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();
135
private GridData getComboData(){
136
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
137
data.minimumWidth = 150;
141
private void setKeySignature(int keySignature,boolean toEnd){
142
//comienza el undoable
143
UndoableChangeKeySignature undoable = UndoableChangeKeySignature.startUndo();
145
Measure measure = getEditor().getTablature().getCaret().getMeasureCoords().getMeasure();
146
SongTrack track = getEditor().getTablature().getCaret().getSongTrackCoords().getTrack();
147
getSongManager().getTrackManager().changeKeySignature(track,measure.getStart(),keySignature,toEnd);
149
//actualizo la tablatura
154
getEditor().getUndoManager().addEdit(undoable.endUndo(keySignature,toEnd));