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.insert;
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;
31
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
33
public class InsertTextAction extends Action {
34
public static final String NAME = "action.insert.text";
36
public InsertTextAction() {
37
super(NAME, AUTO_LOCK | AUTO_UNLOCK | AUTO_UPDATE | DISABLE_ON_PLAYING | KEY_BINDING_AVAILABLE);
40
protected int execute(TypedEvent e){
41
final TGBeat beat = getEditor().getTablature().getCaret().getSelectedBeat();
43
showInsertDialog(beat,(beat.getText() == null?new String():beat.getText().getValue()));
48
public void updateTablature() {
49
fireUpdate(getEditor().getTablature().getCaret().getMeasure().getNumber());
52
public void showInsertDialog(final TGBeat beat,String value) {
53
final Shell dialog = DialogUtils.newDialog(TuxGuitar.instance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
56
dialog.setLayout(new GridLayout());
57
dialog.setText(TuxGuitar.getProperty("text.editor"));
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"));
64
Composite composite = new Composite(group, SWT.NONE);
65
composite.setLayout(new GridLayout(2,false));
66
composite.setLayoutData(getMainData());
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));
72
final Text text = new Text(composite,SWT.BORDER | SWT.SINGLE);
73
text.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
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));
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());
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) {
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) {
110
dialog.setDefaultButton( buttonOK );
112
DialogUtils.openDialog(dialog,DialogUtils.OPEN_STYLE_CENTER | DialogUtils.OPEN_STYLE_PACK | DialogUtils.OPEN_STYLE_WAIT);
115
private GridData getMainData(){
116
GridData data = new GridData(SWT.FILL,SWT.FILL,true,true);
117
data.minimumWidth = 300;
121
private GridData getButtonData(){
122
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
123
data.minimumWidth = 80;
124
data.minimumHeight = 25;
128
protected void insertText(TGBeat beat,String value) {
129
//comienza el undoable
130
UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
132
TGText text = getSongManager().getFactory().newText();
133
text.setValue(value);
134
getSongManager().getMeasureManager().addText(beat, text);
135
TuxGuitar.instance().getFileHistory().setUnsavedFile();
139
addUndoableEdit(undoable.endUndo());
142
protected void removeText(TGBeat beat) {
143
//comienza el undoable
144
UndoableMeasureGeneric undoable = UndoableMeasureGeneric.startUndo();
146
getSongManager().getMeasureManager().removeText(beat);
147
TuxGuitar.instance().getFileHistory().setUnsavedFile();
151
addUndoableEdit(undoable.endUndo());
b'\\ No newline at end of file'