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.measure;
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.Group;
18
import org.eclipse.swt.widgets.Label;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Spinner;
21
import org.herac.tuxguitar.gui.TuxGuitar;
22
import org.herac.tuxguitar.gui.actions.Action;
23
import org.herac.tuxguitar.gui.editors.tab.Caret;
24
import org.herac.tuxguitar.gui.editors.tab.TGMeasureImpl;
25
import org.herac.tuxguitar.gui.editors.tab.TGTrackImpl;
26
import org.herac.tuxguitar.gui.undo.undoables.measure.UndoableRemoveMeasure;
27
import org.herac.tuxguitar.gui.util.DialogUtils;
28
import org.herac.tuxguitar.song.models.TGMeasure;
29
import org.herac.tuxguitar.song.models.TGTrack;
34
* TODO To change the template for this generated type comment go to
35
* Window - Preferences - Java - Code Style - Code Templates
37
public class RemoveMeasureAction extends Action{
38
public static final String NAME = "action.measure.remove";
40
public RemoveMeasureAction() {
41
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
44
protected int execute(TypedEvent e){
45
showDialog(getEditor().getTablature().getShell()/*,e*/);
49
public void showDialog(Shell shell/*,final TypedEvent event*/) {
50
TGTrackImpl track = getEditor().getTablature().getCaret().getTrack();
51
TGMeasureImpl measure = getEditor().getTablature().getCaret().getMeasure();
52
if (measure != null) {
53
final Shell dialog = DialogUtils.newDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
54
dialog.setLayout(new GridLayout());
55
dialog.setText(TuxGuitar.getProperty("edit.delete"));
57
//----------------------------------------------------------------------
58
Group range = new Group(dialog,SWT.SHADOW_ETCHED_IN);
59
range.setLayout(new GridLayout(2,false));
60
range.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
61
range.setText(TuxGuitar.getProperty("edit.delete"));
63
int measureCount = getSongManager().getSong().countMeasureHeaders();
65
Label fromLabel = new Label(range, SWT.NULL);
66
fromLabel.setText(TuxGuitar.getProperty("edit.from"));
67
final Spinner fromSpinner = new Spinner(range, SWT.BORDER);
68
fromSpinner.setLayoutData(getSpinnerData());
69
fromSpinner.setMinimum(1);
70
fromSpinner.setMaximum(measureCount);
71
fromSpinner.setSelection(measure.getNumber());
73
Label toLabel = new Label(range, SWT.NULL);
74
toLabel.setText(TuxGuitar.getProperty("edit.to"));
75
final Spinner toSpinner = new Spinner(range, SWT.BORDER);
76
toSpinner.setLayoutData(getSpinnerData());
77
toSpinner.setMinimum(1);
78
toSpinner.setMaximum(measureCount);
79
toSpinner.setSelection(measure.getNumber());
81
final int minSelection = 1;
82
final int maxSelection = track.countMeasures();
84
fromSpinner.addSelectionListener(new SelectionAdapter() {
85
public void widgetSelected(SelectionEvent e) {
86
int fromSelection = fromSpinner.getSelection();
87
int toSelection = toSpinner.getSelection();
89
if(fromSelection < minSelection){
90
fromSpinner.setSelection(minSelection);
91
}else if(fromSelection > toSelection){
92
fromSpinner.setSelection(toSelection);
96
toSpinner.addSelectionListener(new SelectionAdapter() {
97
public void widgetSelected(SelectionEvent e) {
98
int toSelection = toSpinner.getSelection();
99
int fromSelection = fromSpinner.getSelection();
100
if(toSelection < fromSelection){
101
toSpinner.setSelection(fromSelection);
102
}else if(toSelection > maxSelection){
103
toSpinner.setSelection(maxSelection);
107
//------------------BUTTONS--------------------------
108
Composite buttons = new Composite(dialog, SWT.NONE);
109
buttons.setLayout(new GridLayout(2,false));
110
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
112
final Button buttonOK = new Button(buttons, SWT.PUSH);
113
buttonOK.setText(TuxGuitar.getProperty("ok"));
114
buttonOK.setLayoutData(getButtonData());
115
buttonOK.addSelectionListener(new SelectionAdapter() {
116
public void widgetSelected(SelectionEvent arg0) {
117
removeMeasures(fromSpinner.getSelection(),toSpinner.getSelection()/*,event*/);
122
Button buttonCancel = new Button(buttons, SWT.PUSH);
123
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
124
buttonCancel.setLayoutData(getButtonData());
125
buttonCancel.addSelectionListener(new SelectionAdapter() {
126
public void widgetSelected(SelectionEvent arg0) {
131
dialog.setDefaultButton( buttonOK );
133
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
137
private GridData getButtonData(){
138
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
139
data.minimumWidth = 80;
140
data.minimumHeight = 25;
144
protected GridData getSpinnerData(){
145
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
146
data.minimumWidth = 180;
150
protected void removeMeasures(int m1,int m2/*,TypedEvent event*/){
151
if(m1 > 0 && m1 <= m2 && m2 <= getSongManager().getSong().countMeasureHeaders()){
152
Caret caret = getEditor().getTablature().getCaret();
154
if(m1 == 1 && m2 == getSongManager().getSong().countMeasureHeaders()){
155
//TuxGuitar.instance().getAction(NewFileAction.NAME).process(event);
156
TuxGuitar.instance().newSong();
159
//comienza el undoable
160
UndoableRemoveMeasure undoable = new UndoableRemoveMeasure(m1,m2);
161
TuxGuitar.instance().getFileHistory().setUnsavedFile();
164
getSongManager().removeMeasureHeaders(m1,m2);
168
int measureCount = getSongManager().getSong().countMeasureHeaders();
169
if(caret.getMeasure().getNumber() > measureCount){
170
TGTrack track = getSongManager().getTrack(caret.getTrack().getNumber());
171
TGMeasure measure = getSongManager().getTrackManager().getMeasure(track,measureCount);
172
caret.update(track.getNumber(),measure.getStart(),1);
176
addUndoableEdit(undoable.endUndo());