01: package abbot.editor.editors;
02:
03: import java.awt.event.ActionEvent;
04: import java.io.File;
05: import javax.swing.*;
06: import abbot.Log;
07: import abbot.i18n.Strings;
08: import abbot.script.*;
09: import abbot.script.Script;
10: import abbot.editor.EditorConstants;
11: import abbot.editor.widgets.Mnemonic;
12:
13: /** Provide convenient editing of a Script step. */
14: public class ScriptEditor extends SequenceEditor {
15:
16: private Script script;
17:
18: private JTextField path;
19: private JCheckBox fork;
20: private JTextField vmargs;
21:
22: public ScriptEditor(Script script) {
23: super (script);
24: this .script = script;
25:
26: path = addTextField(Strings.get("FilePath"), script
27: .getFilename());
28:
29: if (!(script instanceof Fixture)) {
30: fork = addCheckBox("", script.isForked());
31: String key = EditorConstants.ACTION_PREFIX
32: + EditorConstants.ACTION_TOGGLE_FORKED;
33: Mnemonic mnemonic = Mnemonic.getMnemonic(Strings.get(key));
34: mnemonic.setMnemonic(fork);
35: addVMArgs();
36: }
37: }
38:
39: private void addVMArgs() {
40: if (script.isForked()) {
41: vmargs = addTextField(Strings.get("VMArgs"), script
42: .getVMArgs());
43: } else if (vmargs != null) {
44: while (getComponent(getComponentCount() - 1) != fork) {
45: remove(getComponentCount() - 1);
46: }
47: vmargs = null;
48: }
49: revalidate();
50: repaint();
51: }
52:
53: public void actionPerformed(ActionEvent ev) {
54: Object src = ev.getSource();
55: if (src == path) {
56: String filename = path.getText().trim();
57: File file = new File(script.getRelativeTo(), filename);
58: script.setFile(file);
59: try {
60: script.load();
61: } catch (Exception exc) {
62: Log.warn(exc);
63: }
64: fireStepChanged();
65: } else if (src == fork) {
66: script.setForked(!script.isForked());
67: addVMArgs();
68: fireStepChanged();
69: } else if (src == vmargs) {
70: String text = vmargs.getText();
71: if ("".equals(text))
72: text = null;
73: script.setVMArgs(text);
74: fireStepChanged();
75: } else {
76: super.actionPerformed(ev);
77: }
78: }
79: }
|