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.Shell;
18
import org.herac.tuxguitar.gui.TuxGuitar;
19
import org.herac.tuxguitar.gui.actions.Action;
20
import org.herac.tuxguitar.gui.clipboard.CannotInsertTransferException;
21
import org.herac.tuxguitar.gui.clipboard.MeasureTransferable;
22
import org.herac.tuxguitar.gui.clipboard.Transferable;
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;
31
* TODO To change the template for this generated type comment go to
32
* Window - Preferences - Java - Code Style - Code Templates
34
public class PasteMeasureAction extends Action{
35
public static final String NAME = "action.measure.paste";
36
private int pasteMode;
38
public PasteMeasureAction(TablatureEditor tablatureEditor) {
39
super(NAME,true,tablatureEditor);
42
public boolean doAction(TypedEvent e) {
43
pasteMode = MeasureTransferable.TRANSFER_TYPE_REPLACE;
44
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.paste"));
59
//----------------------------------------------------------------------
60
Composite radios = new Composite(dialog,SWT.NONE);
61
radios.setLayout(new GridLayout());
62
radios.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
64
final Button replace = new Button(radios,SWT.RADIO);
65
replace.setText(TuxGuitar.getProperty("edit.paste.replace-mode"));
67
final Button insert = new Button(radios,SWT.RADIO);
68
insert.setText(TuxGuitar.getProperty("edit.paste.insert-mode"));
70
replace.addSelectionListener(new SelectionAdapter() {
71
public void widgetSelected(SelectionEvent arg0) {
72
if(replace.getSelection()){
73
pasteMode = MeasureTransferable.TRANSFER_TYPE_REPLACE;
77
insert.addSelectionListener(new SelectionAdapter() {
78
public void widgetSelected(SelectionEvent arg0) {
79
if(insert.getSelection()){
80
pasteMode = MeasureTransferable.TRANSFER_TYPE_INSERT;
84
replace.setSelection(true);
85
//------------------BUTTONS--------------------------
86
Composite buttons = new Composite(dialog, SWT.NONE);
87
buttons.setLayout(new GridLayout(2,false));
88
buttons.setLayoutData(new GridData(SWT.END,SWT.FILL,true,true));
90
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
91
data.minimumWidth = 80;
92
data.minimumHeight = 25;
94
final Button buttonOK = new Button(buttons, SWT.PUSH);
95
buttonOK.setText(TuxGuitar.getProperty("ok"));
96
buttonOK.setLayoutData(data);
97
buttonOK.addSelectionListener(new SelectionAdapter() {
98
public void widgetSelected(SelectionEvent arg0) {
104
Button buttonCancel = new Button(buttons, SWT.PUSH);
105
buttonCancel.setText(TuxGuitar.getProperty("cancel"));
106
buttonCancel.setLayoutData(data);
107
buttonCancel.addSelectionListener(new SelectionAdapter() {
108
public void widgetSelected(SelectionEvent arg0) {
116
int x = shell.getBounds().x + (shell.getBounds().width - dialog.getSize().x) / 2;
117
int y = shell.getBounds().y + (shell.getBounds().height - dialog.getSize().y) / 2;
118
dialog.setLocation(x, y);
120
while (!dialog.isDisposed()) {
121
if (!dialog.getDisplay().readAndDispatch()) {
122
dialog.getDisplay().sleep();
130
private void pasteMeasures(){
132
Transferable transferable = getEditor().getClipBoard().getTransferable();
133
if(transferable instanceof MeasureTransferable){
134
Caret caret = getEditor().getTablature().getCaret();
136
((MeasureTransferable)transferable).setTransferType(this.pasteMode);
137
transferable.insertTransfer();
142
} catch (CannotInsertTransferException ex) {
143
ex.printStackTrace();