001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.editor;
025:
026: import jacareto.record.KeyEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031: import jacareto.toolkit.swing.IntegerTextField;
032:
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035: import java.awt.event.KeyEvent;
036:
037: import javax.swing.JComboBox;
038: import javax.swing.event.DocumentEvent;
039:
040: /**
041: * An editor for key event recordables.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.01
045: */
046: public class KeyEventRecordableEditor extends
047: InputEventRecordableEditor {
048: /** The text field for the keycode attribute. */
049: private IntegerTextField keyCodeField;
050:
051: /** The combo box for the event type (=id). */
052: private JComboBox typeBox;
053:
054: /**
055: * Create a new key event recordable editor.
056: *
057: * @param env the environment
058: */
059: public KeyEventRecordableEditor(Environment env) {
060: super (env);
061:
062: Language language = getLanguage();
063:
064: // The type box
065: typeBox = addComboBoxRow(language
066: .getString("Events.KeyEvent.Type"));
067: typeBox.addItem(language
068: .getString("Events.KeyEvent.KeyPressed"));
069: typeBox.addItem(language
070: .getString("Events.KeyEvent.KeyReleased"));
071: typeBox.addItem(language.getString("Events.KeyEvent.KeyTyped"));
072: typeBox.addActionListener(new ActionListener() {
073: public void actionPerformed(ActionEvent e) {
074: KeyEventRecordable kRecordable = (KeyEventRecordable) getElement();
075:
076: if (kRecordable != null) {
077: if (typeBox.getSelectedIndex() == 0) {
078: kRecordable.setID(KeyEvent.KEY_PRESSED);
079: } else if (typeBox.getSelectedIndex() == 1) {
080: kRecordable.setID(KeyEvent.KEY_RELEASED);
081: } else {
082: kRecordable.setID(KeyEvent.KEY_TYPED);
083: }
084: }
085: }
086: });
087:
088: // The key code field.
089: keyCodeField = addIntegerTextFieldRow(language
090: .getString("Events.KeyEvent.KeyCode"), 5);
091: keyCodeField.getDocument().addDocumentListener(
092: new TextValueListener() {
093: public void textValueChanged(DocumentEvent e) {
094: if (getElement() != null) {
095: ((KeyEventRecordable) getElement())
096: .setKeyCode(keyCodeField.getValue());
097: }
098: }
099: });
100: }
101:
102: /**
103: * Returns whether this editor is responsible for a given structure element. This editor is
104: * responsible for all key event recordables.
105: *
106: * @param element the structure element
107: *
108: * @return <code>true</code> if <i>element</i> is a key event recordable and not
109: * <code>null</code>, otherwise <code>false</code>
110: */
111: public boolean handlesElement(StructureElement element) {
112: return (element != null)
113: && (element instanceof KeyEventRecordable);
114: }
115:
116: /**
117: * Sets the structure element to edit.
118: *
119: * @param element the structure element
120: */
121: public void setElement(StructureElement element) {
122: super .setElement(element);
123:
124: KeyEventRecordable kRecordable = (KeyEventRecordable) element;
125: keyCodeField.setValue(kRecordable.getKeyCode());
126:
127: if (kRecordable.getID() == KeyEvent.KEY_PRESSED) {
128: typeBox.setSelectedIndex(0);
129: } else if (kRecordable.getID() == KeyEvent.KEY_RELEASED) {
130: typeBox.setSelectedIndex(1);
131: } else {
132: typeBox.setSelectedIndex(2);
133: }
134: }
135: }
|