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.insert;
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.Label;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.swt.widgets.Spinner;
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.editors.tab.SongCoords;
25
import org.herac.tuxguitar.gui.undo.undoables.custom.UndoableChangeCloseRepeat;
30
* TODO To change the template for this generated type comment go to
31
* Window - Preferences - Java - Code Style - Code Templates
33
public class CloseRepeatAction extends Action{
34
public static final String NAME = "action.insert.close-repeat";
36
public CloseRepeatAction(TablatureEditor tablatureEditor) {
37
super(NAME,true,tablatureEditor);
40
public boolean doAction(TypedEvent e) {
41
MeasureCoords measureCoords = getEditor().getTablature().getCaret().getMeasureCoords();
42
SongCoords songCoords = getEditor().getTablature().getCaret().getSongCoords();
43
showCloseRepeatDialog(getEditor().getTablature().getShell(), measureCoords, songCoords);
47
protected void updateTablature() {
48
fireUpdate(getEditor().getTablature().getCaret().getMeasureCoords().getMeasure().getNumber());
52
public void showCloseRepeatDialog(Shell shell, final MeasureCoords measureCoords, final SongCoords songCoords) {
53
if (measureCoords != null) {
54
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
56
dialog.setLayout(new GridLayout());
57
dialog.setText(TuxGuitar.getProperty("repetitions"));
60
int currentNumberOfRepetitions = measureCoords.getMeasure().getNumberOfRepetitions();
61
if (currentNumberOfRepetitions < 1) {
62
currentNumberOfRepetitions = 1;
65
Composite composite = new Composite(dialog,SWT.NONE);
66
composite.setLayout(new GridLayout(2,false));
67
composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
69
Label numberOfRepetitionsLabel = new Label(composite, SWT.NULL);
70
numberOfRepetitionsLabel.setText(TuxGuitar.getProperty("repeat.number-of-repetitions"));
72
final Spinner numberOfRepetitions = new Spinner(composite, SWT.BORDER);
73
numberOfRepetitions.setLayoutData(new GridData(50,13));
74
numberOfRepetitions.setMinimum(0);
75
numberOfRepetitions.setMaximum(100);
76
numberOfRepetitions.setSelection(currentNumberOfRepetitions);
77
numberOfRepetitions.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
79
//----------------------BUTTONS--------------------------------
80
Composite buttons = new Composite(dialog, SWT.NONE);
81
buttons.setLayout(new GridLayout(2,false));
82
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
84
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
85
data.minimumWidth = 80;
86
data.minimumHeight = 25;
88
final Button buttonOK = new Button(buttons, SWT.PUSH);
89
buttonOK.setText(TuxGuitar.getProperty("ok"));
90
buttonOK.setLayoutData(data);
91
buttonOK.addSelectionListener(new SelectionAdapter() {
92
public void widgetSelected(SelectionEvent arg0) {
93
closeRepeat(measureCoords, songCoords, numberOfRepetitions.getSelection());
97
Button buttonCancel = new Button(buttons, SWT.PUSH);
98
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
99
buttonCancel.setLayoutData(data);
100
buttonCancel.addSelectionListener(new SelectionAdapter() {
101
public void widgetSelected(SelectionEvent arg0) {
109
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
110
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
111
dialog.setLocation(x, y);
113
while (!dialog.isDisposed()) {
114
if (!dialog.getDisplay().readAndDispatch()) {
115
dialog.getDisplay().sleep();
122
private void closeRepeat(MeasureCoords measureCoords, SongCoords songCoords, int numberOfRepetitions) {
123
//comienza el undoable
124
UndoableChangeCloseRepeat undoable = UndoableChangeCloseRepeat.startUndo();
126
numberOfRepetitions = Math.abs(numberOfRepetitions);
127
getSongManager().changeCloseRepeat(measureCoords.getMeasure().getStart(), numberOfRepetitions);
131
getEditor().getUndoManager().addEdit(undoable.endUndo(numberOfRepetitions));