001: package abbot.editor.editors;
002:
003: import java.awt.*;
004: import java.awt.event.ActionEvent;
005: import java.util.*;
006:
007: import javax.swing.*;
008: import abbot.i18n.Strings;
009: import abbot.script.Appletviewer;
010: import abbot.editor.widgets.ArrayEditor;
011:
012: /** Provide convenient editing of an applet launch step. */
013: public class AppletviewerEditor extends StepEditor {
014:
015: public static final String HELP_DESC = Strings
016: .get("editor.applet.desc");
017:
018: private Appletviewer applet;
019:
020: private JTextField code;
021: private ArrayEditor params;
022: private JTextField codebase;
023: private JTextField archive;
024: private JTextField width;
025: private JTextField height;
026:
027: public AppletviewerEditor(Appletviewer applet) {
028: super (applet);
029: this .applet = applet;
030:
031: code = addTextField(Strings.get("editor.applet.code"), applet
032: .getCode());
033: width = addTextField(Strings.get("editor.applet.width"), applet
034: .getWidth());
035: height = addTextField(Strings.get("editor.applet.height"),
036: applet.getHeight());
037: // For some reason, if we *don't* futz with the layout of
038: // width/height, the pane never reconfigures properly for the array
039: // editor.
040: Component c;
041: ArrayList list = new ArrayList();
042: while ((c = getComponent(getComponentCount() - 1)) != code) {
043: remove(c);
044: list.add(c);
045: }
046: JPanel p = new JPanel();
047: //p.setBorder(new TitledBorder(Strings.get("editor.applet.size")));
048: p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
049: for (int i = list.size() - 1; i >= 0; i--) {
050: p.add((Component) list.get(i));
051: if (i != 0)
052: p.add(Box.createHorizontalStrut(MARGIN));
053: }
054: add(p);
055:
056: params = addArrayEditor(Strings.get("editor.applet.params"),
057: applet.getParamsAsArray());
058:
059: codebase = addTextField(Strings.get("editor.applet.codebase"),
060: applet.getCodebase());
061: archive = addTextField(Strings.get("editor.applet.archive"),
062: applet.getArchive());
063: }
064:
065: public void actionPerformed(ActionEvent ev) {
066: Object src = ev.getSource();
067: if (src == code) {
068: applet.setCode(code.getText());
069: fireStepChanged();
070: } else if (src == params) {
071: Object[] values = params.getValues();
072: Map map = new HashMap();
073: for (int i = 0; i < values.length; i++) {
074: String v = (String) values[i];
075: int eq = v.indexOf("=");
076: if (eq != -1) {
077: String key = v.substring(0, eq);
078: String value = v.substring(eq + 1);
079: map.put(key, value);
080: }
081: }
082: applet.setParams(map);
083: fireStepChanged();
084: } else if (src == codebase) {
085: String value = codebase.getText();
086: if ("".equals(value))
087: value = null;
088: applet.setCodebase(value);
089: fireStepChanged();
090: } else if (src == archive) {
091: String value = archive.getText();
092: if ("".equals(value))
093: value = null;
094: applet.setArchive(value);
095: fireStepChanged();
096: } else if (src == width) {
097: String value = width.getText();
098: if ("".equals(value))
099: value = null;
100: try {
101: Integer.parseInt(value);
102: applet.setWidth(value);
103: width.setForeground(DEFAULT_FOREGROUND);
104: fireStepChanged();
105: } catch (NumberFormatException e) {
106: width.setForeground(ERROR_FOREGROUND);
107: }
108: } else if (src == height) {
109: String value = height.getText();
110: if ("".equals(value))
111: value = null;
112: try {
113: Integer.parseInt(value);
114: applet.setHeight(value);
115: width.setForeground(DEFAULT_FOREGROUND);
116: fireStepChanged();
117: } catch (NumberFormatException e) {
118: width.setForeground(ERROR_FOREGROUND);
119: }
120: } else {
121: super .actionPerformed(ev);
122: }
123:
124: // Remove the default placeholder description
125: if (HELP_DESC.equals(applet.getDescription())) {
126: applet.setDescription(null);
127: fireStepChanged();
128: }
129: }
130: }
|