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.struct.RootElement;
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 root elements.
038: * </p>
039: *
040: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
041: * @version 1.01
042: */
043: public class RootElementEditor extends InputFieldRowsEditor {
044: /** The text field for the record name. */
045: private JTextField recordNameField;
046:
047: /** the stored element. */
048: private StructureElement element;
049:
050: /**
051: * Create a new root element editor.
052: *
053: * @param env the environment
054: */
055: public RootElementEditor(Environment env) {
056: super (env);
057:
058: Language language = getLanguage();
059:
060: // The field for the record name
061: recordNameField = addTextFieldRow(language
062: .getString("Record.Name"), 20);
063: recordNameField.getDocument().addDocumentListener(
064: new TextValueListener() {
065: public void textValueChanged(DocumentEvent e) {
066: if (isUpdateOnChange && (getElement() != null)) {
067: ((RootElement) getElement()).getRecord()
068: .setRecordName(
069: recordNameField.getText());
070: }
071: }
072: });
073: }
074:
075: /**
076: * Returns whether this editor is responsible for a given structure element. This editor is
077: * responsible for all focus event recordables.
078: *
079: * @param element the structure element
080: *
081: * @return <code>true</code> if <i>element</i> is an root element and not <code>null</code>,
082: * otherwise <code>false</code>
083: */
084: public boolean handlesElement(StructureElement element) {
085: return (element != null) && (element instanceof RootElement);
086: }
087:
088: /**
089: * Sets the structure element to edit.
090: *
091: * @param element must be a root element!
092: */
093: public void setElement(StructureElement element) {
094: this .element = element;
095:
096: RootElement root = (RootElement) element;
097:
098: recordNameField.setText(root.getRecord().getRecordName());
099: }
100:
101: /**
102: * Returns the element.
103: *
104: * @return the root element
105: */
106: public StructureElement getElement() {
107: return element;
108: }
109: }
|