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.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.clipboard.MeasureTransferable;
23
import org.herac.tuxguitar.gui.editors.TablatureEditor;
24
import org.herac.tuxguitar.gui.editors.tab.Caret;
25
import org.herac.tuxguitar.gui.editors.tab.MeasureCoords;
26
import org.herac.tuxguitar.gui.editors.tab.SongTrackCoords;
27
import org.herac.tuxguitar.song.models.Measure;
32
* TODO To change the template for this generated type comment go to
33
* Window - Preferences - Java - Code Style - Code Templates
35
public class CopyMeasureAction extends Action{
36
public static final String NAME = "action.measure.copy";
38
private boolean copyAllTracks;
40
public CopyMeasureAction(TablatureEditor tablatureEditor) {
41
super(NAME,true,tablatureEditor);
44
public boolean doAction(TypedEvent e) {
45
showDialog(getEditor().getTablature().getShell());
50
public void showDialog(Shell shell) {
51
SongTrackCoords track = getEditor().getTablature().getCaret().getSongTrackCoords();
52
MeasureCoords measure = getEditor().getTablature().getCaret().getMeasureCoords();
53
if (measure != null) {
54
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
55
dialog.setLayout(new GridLayout());
56
dialog.setText(TuxGuitar.getProperty("edit.copy"));
58
//----------------------------------------------------------------------
59
Composite range = new Composite(dialog,SWT.NONE);
60
range.setLayout(new GridLayout(4,false));
61
range.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
63
int measureCount = getSongManager().countMeasures();
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(new GridData(26,SWT.DEFAULT));
69
fromSpinner.setMinimum(1);
70
fromSpinner.setMaximum(measureCount);
71
fromSpinner.setSelection(measure.getMeasure().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(new GridData(26,SWT.DEFAULT));
77
toSpinner.setMinimum(1);
78
toSpinner.setMaximum(measureCount);
79
toSpinner.setSelection(measure.getMeasure().getNumber());
81
final int minSelection = 1;
82
final int maxSelection = track.getMeasuresCoords().size();
85
fromSpinner.addSelectionListener(new SelectionAdapter() {
86
public void widgetSelected(SelectionEvent e) {
87
int fromSelection = fromSpinner.getSelection();
88
int toSelection = toSpinner.getSelection();
90
if(fromSelection < minSelection){
91
fromSpinner.setSelection(minSelection);
92
}else if(fromSelection > toSelection){
93
fromSpinner.setSelection(toSelection);
97
toSpinner.addSelectionListener(new SelectionAdapter() {
98
public void widgetSelected(SelectionEvent e) {
99
int toSelection = toSpinner.getSelection();
100
int fromSelection = fromSpinner.getSelection();
101
if(toSelection < fromSelection){
102
toSpinner.setSelection(fromSelection);
103
}else if(toSelection > maxSelection){
104
toSpinner.setSelection(maxSelection);
108
//----------------------------------------------------------------------
109
copyAllTracks = true;
110
if(getEditor().getSongManager().countTracks() > 1){
111
Composite checkComposites = new Composite(dialog,SWT.NONE);
112
checkComposites.setLayout(new GridLayout());
113
checkComposites.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
115
final Button allTracks = new Button(checkComposites,SWT.CHECK);
116
allTracks.setText(TuxGuitar.getProperty("edit.all-tracks"));
117
allTracks.setSelection(copyAllTracks);
118
allTracks.addSelectionListener(new SelectionAdapter() {
119
public void widgetSelected(SelectionEvent e) {
120
copyAllTracks = allTracks.getSelection();
124
//------------------BUTTONS--------------------------
125
Composite buttons = new Composite(dialog, SWT.NONE);
126
buttons.setLayout(new GridLayout(2,false));
127
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
129
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
130
data.minimumWidth = 80;
131
data.minimumHeight = 25;
133
final Button buttonOK = new Button(buttons, SWT.PUSH);
134
buttonOK.setText(TuxGuitar.getProperty("ok"));
135
buttonOK.setLayoutData(data);
136
buttonOK.addSelectionListener(new SelectionAdapter() {
137
public void widgetSelected(SelectionEvent arg0) {
138
copyMeasures(fromSpinner.getSelection(),toSpinner.getSelection(),copyAllTracks);
143
Button buttonCancel = new Button(buttons, SWT.PUSH);
144
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
145
buttonCancel.setLayoutData(data);
146
buttonCancel.addSelectionListener(new SelectionAdapter() {
147
public void widgetSelected(SelectionEvent arg0) {
155
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
156
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
157
dialog.setLocation(x, y);
159
while (!dialog.isDisposed()) {
160
if (!dialog.getDisplay().readAndDispatch()) {
161
dialog.getDisplay().sleep();
169
private void copyMeasures(int m1,int m2,boolean allTracks){
170
if(m1 > 0 && m1 <= m2){
171
Caret caret = getEditor().getTablature().getCaret();
172
Measure measure1 = getSongManager().getTrackManager().getMeasure(caret.getSongTrackCoords().getTrack(),m1);
173
Measure measure2 = getSongManager().getTrackManager().getMeasure(caret.getSongTrackCoords().getTrack(),m2);
174
if(measure1 != null && measure2 != null){
175
long p1 = measure1.getStart();
176
long p2 = measure2.getStart();
177
MeasureTransferable transferable = new MeasureTransferable(getEditor(),p1,p2,allTracks);
178
getEditor().getClipBoard().addTransferable(transferable);