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.FocusEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030:
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.awt.event.FocusEvent;
034:
035: import javax.swing.JComboBox;
036:
037: /**
038: * <p>
039: * An editor for focus event recordables.
040: * </p>
041: *
042: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
043: * @version 1.01
044: */
045: public class FocusEventRecordableEditor extends
046: ComponentEventRecordableEditor {
047: /** The combo box for the "is temporary" attribute. */
048: private JComboBox isTemporaryBox;
049:
050: /** The combo box for the event type (=id). */
051: private JComboBox typeBox;
052:
053: /**
054: * Create a new component event recordable editor.
055: *
056: * @param env the environment
057: */
058: public FocusEventRecordableEditor(Environment env) {
059: super (env);
060:
061: Language language = getLanguage();
062:
063: // The type box
064: typeBox = addComboBoxRow(language
065: .getString("Events.FocusEvent.Type"));
066: typeBox.addItem(language
067: .getString("Events.FocusEvent.FocusGained"));
068: typeBox.addItem(language
069: .getString("Events.FocusEvent.FocusLost"));
070: typeBox.addActionListener(new ActionListener() {
071: public void actionPerformed(ActionEvent e) {
072: FocusEventRecordable fRecordable = (FocusEventRecordable) getElement();
073:
074: if (isUpdateOnChange && (fRecordable != null)) {
075: if (typeBox.getSelectedIndex() == 0) {
076: fRecordable.setID(FocusEvent.FOCUS_GAINED);
077: } else if (typeBox.getSelectedIndex() == 1) {
078: fRecordable.setID(FocusEvent.FOCUS_LOST);
079: }
080: }
081: }
082: });
083:
084: // The is temporary box
085: isTemporaryBox = addComboBoxRow(language
086: .getString("Events.FocusEvent.Temporary"));
087: isTemporaryBox.addItem(language.getString("General.True"));
088: isTemporaryBox.addItem(language.getString("General.False"));
089: isTemporaryBox.addActionListener(new ActionListener() {
090: public void actionPerformed(ActionEvent e) {
091: if (isUpdateOnChange && (getElement() != null)) {
092: if (isTemporaryBox.getSelectedIndex() == 0) {
093: ((FocusEventRecordable) getElement())
094: .setTemporary(true);
095: } else {
096: ((FocusEventRecordable) getElement())
097: .setTemporary(false);
098: }
099: }
100: }
101: });
102: }
103:
104: /**
105: * Returns whether this editor is responsible for a given structure element. This editor is
106: * responsible for all focus event recordables.
107: *
108: * @param element the structure element
109: *
110: * @return <code>true</code> if <i>element</i> is an input event recordable and not
111: * <code>null</code>, otherwise <code>false</code>
112: */
113: public boolean handlesElement(StructureElement element) {
114: return (element != null)
115: && (element instanceof FocusEventRecordable);
116: }
117:
118: /**
119: * Sets the structure element to edit.
120: *
121: * @param element DOCUMENT ME!
122: */
123: public void setElement(StructureElement element) {
124: super .setElement(element);
125:
126: FocusEventRecordable fRecordable = (FocusEventRecordable) element;
127:
128: if (fRecordable.isTemporary()) {
129: isTemporaryBox.setSelectedIndex(0);
130: } else {
131: isTemporaryBox.setSelectedIndex(1);
132: }
133:
134: if (fRecordable.getID() == FocusEvent.FOCUS_GAINED) {
135: typeBox.setSelectedIndex(0);
136: } else {
137: typeBox.setSelectedIndex(1);
138: }
139: }
140: }
|