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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/actions/insert/InsertTextAction.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.insert;
 
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.Group;
 
18
import org.eclipse.swt.widgets.Label;
 
19
import org.eclipse.swt.widgets.Shell;
 
20
import org.eclipse.swt.widgets.Text;
 
21
import org.herac.tuxguitar.gui.TuxGuitar;
 
22
import org.herac.tuxguitar.gui.actions.Action;
 
23
import org.herac.tuxguitar.gui.undo.undoables.measure.UndoableMeasureGeneric;
 
24
import org.herac.tuxguitar.gui.util.DialogUtils;
 
25
import org.herac.tuxguitar.song.models.TGBeat;
 
26
import org.herac.tuxguitar.song.models.TGText;
 
27
 
 
28
/**
 
29
 * @author julian
 
30
 * 
 
31
 * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
 
32
 */
 
33
public class InsertTextAction extends Action {
 
34
        public static final String NAME = "action.insert.text";
 
35
        
 
36
        public InsertTextAction() {
 
37
                super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
 
38
        }
 
39
        
 
40
        protected int execute(TypedEvent e){
 
41
                final TGBeat beat = getEditor().getTablature().getCaret().getSelectedBeat();
 
42
                
 
43
                showInsertDialog(beat,(beat.getText() == null?new String():beat.getText().getValue()));
 
44
                
 
45
                return 0;
 
46
        }
 
47
        
 
48
        public void updateTablature() {
 
49
                fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());
 
50
        }
 
51
        
 
52
        public void showInsertDialog(final TGBeat beat,String value) {
 
53
                final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
 
54
                
 
55
                
 
56
                dialog.setLayout(new GridLayout());
 
57
                dialog.setText(TuxGuitar.getProperty("text.editor"));
 
58
                
 
59
                Group group = new Group(dialog,SWT.SHADOW_ETCHED_IN);
 
60
                group.setLayout(new GridLayout());
 
61
                group.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
62
                group.setText(TuxGuitar.getProperty("text.insert"));
 
63
                
 
64
                Composite composite = new Composite(group, SWT.NONE);
 
65
                composite.setLayout(new GridLayout(2,false));
 
66
                composite.setLayoutData(getMainData());  
 
67
                
 
68
                final Label label = new Label(composite,SWT.LEFT);
 
69
                label.setText(TuxGuitar.getProperty("text.text") + ":");
 
70
                label.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,false,true));
 
71
                
 
72
                final Text text = new Text(composite,SWT.BORDER | SWT.SINGLE);
 
73
                text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
 
74
                text.setText(value);
 
75
                
 
76
                //------------------BUTTONS--------------------------
 
77
                Composite buttons = new Composite(dialog, SWT.NONE);
 
78
                buttons.setLayout(new GridLayout(3,false));
 
79
                buttons.setLayoutData(new GridData(SWT.RIGHT,SWT.FILL,true,true));
 
80
                
 
81
                final Button buttonOK = new Button(buttons, SWT.PUSH);
 
82
                buttonOK.setText(TuxGuitar.getProperty("ok"));
 
83
                buttonOK.setLayoutData(getButtonData());
 
84
                buttonOK.addSelectionListener(new SelectionAdapter() {
 
85
                        public void widgetSelected(SelectionEvent arg0) {
 
86
                                insertText(beat,text.getText());
 
87
                                dialog.dispose();
 
88
                        }
 
89
                });
 
90
                
 
91
                final Button buttonClean = new Button(buttons, SWT.PUSH);
 
92
                buttonClean.setText(TuxGuitar.getProperty("clean"));
 
93
                buttonClean.setLayoutData(getButtonData());
 
94
                buttonClean.addSelectionListener(new SelectionAdapter() {
 
95
                        public void widgetSelected(SelectionEvent arg0) {
 
96
                                removeText(beat);
 
97
                                dialog.dispose();
 
98
                        }
 
99
                });
 
100
                
 
101
                Button buttonCancel = new Button(buttons, SWT.PUSH);
 
102
                buttonCancel.setText(TuxGuitar.getProperty("cancel"));
 
103
                buttonCancel.setLayoutData(getButtonData());
 
104
                buttonCancel.addSelectionListener(new SelectionAdapter() {
 
105
                        public void widgetSelected(SelectionEvent arg0) {
 
106
                                dialog.dispose();
 
107
                        }
 
108
                });
 
109
                
 
110
                dialog.setDefaultButton( buttonOK );
 
111
                
 
112
                DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
 
113
        }
 
114
        
 
115
        private GridData getMainData(){
 
116
                GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
 
117
                data.minimumWidth = 300;
 
118
                return data;
 
119
        }
 
120
        
 
121
        private GridData getButtonData(){
 
122
                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
 
123
                data.minimumWidth = 80;
 
124
                data.minimumHeight = 25;
 
125
                return data;
 
126
        }
 
127
        
 
128
        protected void insertText(TGBeat beat,String value) {
 
129
                //comienza el undoable
 
130
                UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
 
131
                
 
132
                TGText text = getSongManager().getFactory().newText();
 
133
                text.setValue(value);
 
134
                getSongManager().getMeasureManager().addText(beat, text);
 
135
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
136
                updateTablature();
 
137
                
 
138
                //termia el undoable
 
139
                addUndoableEdit(undoable.endUndo());
 
140
        }
 
141
        
 
142
        protected void removeText(TGBeat beat) {
 
143
                //comienza el undoable
 
144
                UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
 
145
                
 
146
                getSongManager().getMeasureManager().removeText(beat);
 
147
                TuxGuitar.instance().getFileHistory().setUnsavedFile();
 
148
                updateTablature();
 
149
                
 
150
                //termia el undoable
 
151
                addUndoableEdit(undoable.endUndo());
 
152
        }
 
153
}
 
 
b'\\ No newline at end of file'