001: package abbot.editor.editors;
002:
003: import javax.swing.*;
004: import abbot.Log;
005: import abbot.script.*;
006:
007: /** Edit a raw AWTEvent. */
008:
009: public class EventEditor extends StepEditor {
010:
011: private Event event;
012: JComboBox type;
013: JComboBox kind;
014: JComboBox cref;
015: private boolean ignoreCombo = false;
016:
017: JTextField xValue;
018: JTextField yValue;
019:
020: JTextField keyCode;
021:
022: public EventEditor(Event event) {
023: super (event);
024: this .event = event;
025: String idtype = event.getType();
026: String idkind = event.getKind();
027: String[] typeValues = { "Mouse Event", "Key Event" };
028: ignoreCombo = true;
029: type = addComboBox("Type", typeValues[0], typeValues);
030: type.setEnabled(false);
031: type.setEditable(false);
032: Resolver resolver = event.getResolver();
033: String refid = event.getComponentID();
034: if ("MouseEvent".equals(idtype)) {
035: String[] kindValues = { "MOUSE_PRESSED", "MOUSE_RELEASED",
036: "MOUSE_MOVED", "MOUSE_DRAGGED" };
037: kind = addComboBox("Kind", idkind, kindValues);
038: kind.setEditable(false);
039: kind.setEnabled(false);
040: cref = addComponentSelector("On Component", refid,
041: resolver, false);
042: xValue = addTextField("X", event
043: .getAttribute(XMLConstants.TAG_X));
044: yValue = addTextField("Y", event
045: .getAttribute(XMLConstants.TAG_Y));
046: } else if ("KeyEvent".equals(idtype)) {
047: type.setSelectedItem(typeValues[1]);
048: String[] kindValues = { "KEY_PRESSED", "KEY_RELEASED" };
049: kind = addComboBox("Kind", idkind, kindValues);
050: kind.setEditable(false);
051: cref = addComponentSelector("On Component", refid,
052: resolver, false);
053: // FIXME make a popup w/all keycodes
054: keyCode = addTextField("Key Code", event
055: .getAttribute(XMLConstants.TAG_KEYCODE));
056: } else {
057: Log.warn("Unhandled ID type: " + idtype);
058: }
059: ignoreCombo = false;
060: }
061:
062: public void actionPerformed(java.awt.event.ActionEvent ev) {
063: Object src = ev.getSource();
064: if (src == cref) {
065: event.setComponentID((String) cref.getSelectedItem());
066: fireStepChanged();
067: } else if (src == kind) {
068: if (!ignoreCombo) {
069: event.setAttribute(XMLConstants.TAG_KIND, (String) kind
070: .getSelectedItem());
071: fireStepChanged();
072: }
073: } else if (src == xValue) {
074: try {
075: int value = Integer.parseInt(xValue.getText());
076: event.setAttribute(XMLConstants.TAG_X, String
077: .valueOf(value));
078: xValue.setForeground(DEFAULT_FOREGROUND);
079: fireStepChanged();
080: } catch (NumberFormatException nfe) {
081: xValue.setForeground(ERROR_FOREGROUND);
082: }
083: } else if (src == yValue) {
084: try {
085: int value = Integer.parseInt(yValue.getText());
086: event.setAttribute(XMLConstants.TAG_Y, String
087: .valueOf(value));
088: yValue.setForeground(DEFAULT_FOREGROUND);
089: fireStepChanged();
090: } catch (NumberFormatException nfe) {
091: yValue.setForeground(ERROR_FOREGROUND);
092: }
093: } else if (src == keyCode) {
094: try {
095: String codestr = keyCode.getText().trim();
096: event.setAttribute(XMLConstants.TAG_KEYCODE, codestr);
097: keyCode.setForeground(DEFAULT_FOREGROUND);
098: fireStepChanged();
099: } catch (IllegalArgumentException iae) {
100: keyCode.setForeground(ERROR_FOREGROUND);
101: }
102: } else {
103: super.actionPerformed(ev);
104: }
105: }
106:
107: }
|