~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/actions/measure/PasteMeasureAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 17-dic-2005
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.actions.measure;
8
 
 
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;
27
 
 
28
 
/**
29
 
 * @author julian
30
 
 *
31
 
 * TODO To change the template for this generated type comment go to
32
 
 * Window - Preferences - Java - Code Style - Code Templates
33
 
 */
34
 
public class PasteMeasureAction extends Action{
35
 
    public static final String NAME = "action.measure.paste";
36
 
    private int pasteMode;
37
 
    
38
 
    public PasteMeasureAction(TablatureEditor tablatureEditor) {
39
 
        super(NAME,true,tablatureEditor);       
40
 
    }
41
 
 
42
 
    public boolean doAction(TypedEvent e) {
43
 
        pasteMode = MeasureTransferable.TRANSFER_TYPE_REPLACE;          
44
 
            showDialog(getEditor().getTablature().getShell());      
45
 
        return true;
46
 
    }
47
 
 
48
 
    
49
 
 
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"));
57
 
            
58
 
 
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));
63
 
            
64
 
            final Button replace = new Button(radios,SWT.RADIO);
65
 
            replace.setText(TuxGuitar.getProperty("edit.paste.replace-mode"));
66
 
            
67
 
            final Button insert = new Button(radios,SWT.RADIO);
68
 
            insert.setText(TuxGuitar.getProperty("edit.paste.insert-mode"));
69
 
            
70
 
            replace.addSelectionListener(new SelectionAdapter() {
71
 
                public void widgetSelected(SelectionEvent arg0) {
72
 
                        if(replace.getSelection()){
73
 
                                pasteMode = MeasureTransferable.TRANSFER_TYPE_REPLACE;
74
 
                        }
75
 
                }
76
 
            });
77
 
            insert.addSelectionListener(new SelectionAdapter() {
78
 
                public void widgetSelected(SelectionEvent arg0) {
79
 
                        if(insert.getSelection()){
80
 
                                pasteMode = MeasureTransferable.TRANSFER_TYPE_INSERT;
81
 
                        }
82
 
                }
83
 
            });                                    
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));            
89
 
            
90
 
            GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);    
91
 
            data.minimumWidth = 80;
92
 
            data.minimumHeight = 25;     
93
 
            
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) {   
99
 
                        pasteMeasures();
100
 
                    dialog.dispose();
101
 
                }
102
 
            });
103
 
 
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) {
109
 
                    dialog.dispose();
110
 
                }
111
 
            });
112
 
 
113
 
            dialog.pack();
114
 
            dialog.open();
115
 
 
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);
119
 
            
120
 
                while (!dialog.isDisposed()) {
121
 
                if (!dialog.getDisplay().readAndDispatch()) {
122
 
                        dialog.getDisplay().sleep();
123
 
                }
124
 
 
125
 
            }   
126
 
        }
127
 
    }
128
 
 
129
 
    
130
 
    private void pasteMeasures(){
131
 
            try {                               
132
 
                Transferable transferable = getEditor().getClipBoard().getTransferable();
133
 
                if(transferable instanceof MeasureTransferable){                
134
 
                        Caret caret = getEditor().getTablature().getCaret();  
135
 
                        
136
 
                        ((MeasureTransferable)transferable).setTransferType(this.pasteMode);
137
 
                        transferable.insertTransfer();                           
138
 
            
139
 
                        updateTablature();              
140
 
                        redraw();
141
 
                }
142
 
        } catch (CannotInsertTransferException ex) {                    
143
 
            ex.printStackTrace();
144
 
        }       
145
 
    }
146
 
}