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.ComponentEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031:
032: import javax.swing.JTextField;
033: import javax.swing.event.DocumentEvent;
034:
035: /**
036: * <p>
037: * An editor for component event recordables.
038: * </p>
039: *
040: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
041: * @version 1.01
042: */
043: public class ComponentEventRecordableEditor extends
044: AWTEventRecordableEditor {
045: /** The text field for the component's name. */
046: private JTextField rootField;
047:
048: /** The text field for the component's name. */
049: private JTextField userDefinedName;
050:
051: /**
052: * Create a new component event recordable editor.
053: *
054: * @param env the environment
055: */
056: public ComponentEventRecordableEditor(Environment env) {
057: super (env);
058:
059: Language language = getLanguage();
060:
061: // The root field.
062: rootField = addTextFieldRow(language
063: .getString("Events.ComponentEvent.Root"), 20);
064: rootField.getDocument().addDocumentListener(
065: new TextValueListener() {
066: public void textValueChanged(DocumentEvent e) {
067: if (isUpdateOnChange && (getElement() != null)) {
068: ((ComponentEventRecordable) getElement())
069: .setRootName(rootField.getText());
070: }
071: }
072: });
073:
074: // The user defined name of the component
075: userDefinedName = addTextFieldRow(language
076: .getString("Events.ComponentEvent.UserDefinedName"), 20);
077: userDefinedName.setEditable(false);
078: }
079:
080: /**
081: * Returns whether this editor is responsible for a given structure element. This editor is
082: * responsible for all component event recordables.
083: *
084: * @param element the structure element
085: *
086: * @return <code>true</code> if <i>element</i> is a component event recordable and not
087: * <code>null</code>, otherwise <code>false</code>
088: */
089: public boolean handlesElement(StructureElement element) {
090: return (element != null)
091: && (element instanceof ComponentEventRecordable);
092: }
093:
094: /**
095: * Sets the element to edit.
096: *
097: * @param element DOCUMENT ME!
098: */
099: public void setElement(StructureElement element) {
100: super .setElement(element);
101:
102: ComponentEventRecordable cRecordable = (ComponentEventRecordable) element;
103: rootField.setText(cRecordable.getRootName());
104: rootField.setCaretPosition(0);
105:
106: userDefinedName.setText(cRecordable.getComponentName());
107: userDefinedName.setCaretPosition(0);
108: }
109: }
|