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.InputEventRecordable;
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: import jacareto.toolkit.swing.LongTextField;
033:
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.JComboBox;
038: import javax.swing.event.DocumentEvent;
039:
040: /**
041: * An editor for input event recordables.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.02
045: */
046: public class InputEventRecordableEditor extends
047: ComponentEventRecordableEditor {
048: /** The text field for the when attribute. */
049: private LongTextField whenField;
050:
051: /** The text field for the modifiers attribute. */
052: private IntegerTextField modifiersField;
053:
054: /** The combo box for the "is consumed" attribute. */
055: private JComboBox isConsumedBox;
056:
057: /**
058: * Create a new input event recordable editor.
059: *
060: * @param env the environment
061: */
062: public InputEventRecordableEditor(Environment env) {
063: super (env);
064:
065: Language language = getLanguage();
066:
067: // The when field.
068: whenField = addLongTextFieldRow(language
069: .getString("Events.InputEvent.When"), 10);
070: whenField.getDocument().addDocumentListener(
071: new TextValueListener() {
072: public void textValueChanged(DocumentEvent e) {
073: if (isUpdateOnChange && (getElement() != null)) {
074: ((InputEventRecordable) getElement())
075: .setWhen(whenField.getValue());
076: }
077: }
078: });
079:
080: // The modifiers field.
081: modifiersField = addIntegerTextFieldRow(language
082: .getString("Events.InputEvent.Modifiers"), 10);
083: modifiersField.getDocument().addDocumentListener(
084: new TextValueListener() {
085: public void textValueChanged(DocumentEvent e) {
086: if (isUpdateOnChange && (getElement() != null)) {
087: ((InputEventRecordable) getElement())
088: .setModifiers(modifiersField
089: .getValue());
090: }
091: }
092: });
093:
094: // The is consumed box
095: isConsumedBox = addComboBoxRow(language
096: .getString("Events.InputEvent.Consumed"));
097: isConsumedBox.addItem(language.getString("General.True"));
098: isConsumedBox.addItem(language.getString("General.False"));
099: isConsumedBox.addActionListener(new ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: if (isUpdateOnChange && (getElement() != null)) {
102: if (isConsumedBox.getSelectedIndex() == 0) {
103: ((InputEventRecordable) getElement())
104: .setConsumed(true);
105: } else {
106: ((InputEventRecordable) getElement())
107: .setConsumed(false);
108: }
109: }
110: }
111: });
112: }
113:
114: /**
115: * Returns whether this editor is responsible for a given structure element This editor is
116: * responsible for all input event recordables.
117: *
118: * @param element the structure element
119: *
120: * @return <code>true</code> if <i>element</i> is an input event recordable and not
121: * <code>null</code>, otherwise <code>false</code>
122: */
123: public boolean handlesElement(StructureElement element) {
124: return (element != null)
125: && (element instanceof InputEventRecordable);
126: }
127:
128: /**
129: * Sets the structure element to edit.
130: *
131: * @param element DOCUMENT ME!
132: */
133: public void setElement(StructureElement element) {
134: super .setElement(element);
135:
136: InputEventRecordable iRecordable = (InputEventRecordable) element;
137: whenField.setValue(iRecordable.getWhen());
138: modifiersField.setValue(iRecordable.getModifiers());
139:
140: if (iRecordable.isConsumed()) {
141: isConsumedBox.setSelectedIndex(0);
142: } else {
143: isConsumedBox.setSelectedIndex(1);
144: }
145: }
146: }
|