HyperlinkEventRecordableEditor.java :  » Testing » jacareto » jacareto » editor » Java Open Source

Java Open Source » Testing » jacareto 
jacareto » jacareto » editor » HyperlinkEventRecordableEditor.java
/*
 * Jacareto Copyright (c) 2002-2005
 * Applied Computer Science Research Group, Darmstadt University of
 * Technology, Institute of Mathematics & Computer Science,
 * Ludwigsburg University of Education, and Computer Based
 * Learning Research Group, Aachen University. All rights reserved.
 *
 * Jacareto is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * Jacareto is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Jacareto; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package jacareto.editor;


import jacareto.record.HyperlinkEventRecordable;
import jacareto.struct.StructureElement;
import jacareto.system.Environment;
import jacareto.system.Language;
import jacareto.toolkit.event.TextValueListener;

import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;

/**
 * An editor for hyperlink event recordables.
 *
 * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
 * @version 1.00
 */
public class HyperlinkEventRecordableEditor extends EventObjectRecordableEditor {
    /** The text field for the url. */
    private JTextField urlField;

    /** The text field for the description. */
    private JTextField descriptionField;

    /** The text field for the type. */
    private JTextField typeField;

    /**
     * Create a new hyperlink event recordable editor.
     *
     * @param env the environment
     */
    public HyperlinkEventRecordableEditor (Environment env) {
        super(env);

        Language language = getLanguage ();

        // The url field.
        urlField = addTextFieldRow (language.getString ("Events.HyperlinkEvent.URL"), 20);
        urlField.getDocument ().addDocumentListener (new TextValueListener() {
                public void textValueChanged (DocumentEvent e) {
                    if (isUpdateOnChange && (getElement () != null)) {
                        ((HyperlinkEventRecordable) getElement ()).setURL (urlField.getText ());
                    }
                }
            });

        // The description field.
        descriptionField = addTextFieldRow (language.getString ("Events.HyperlinkEvent.Description"),
                20);
        descriptionField.getDocument ().addDocumentListener (new TextValueListener() {
                public void textValueChanged (DocumentEvent e) {
                    if (isUpdateOnChange && (getElement () != null)) {
                        ((HyperlinkEventRecordable) getElement ()).setDescription (descriptionField.getText ());
                    }
                }
            });

        // The type field.
        typeField = addTextFieldRow (language.getString ("Events.HyperlinkEvent.Type"), 20);
        typeField.getDocument ().addDocumentListener (new TextValueListener() {
                public void textValueChanged (DocumentEvent e) {
                    if (isUpdateOnChange && (getElement () != null)) {
                        ((HyperlinkEventRecordable) getElement ()).setType (typeField.getText ());
                    }
                }
            });
    }

    /**
     * Returns whether this editor is responsible for a given structure element. This editor is
     * responsible for all list selection event recordables.
     *
     * @param element the structure element
     *
     * @return <code>true</code> if <i>element</i> is a list selection event recordable and not
     *         <code>null</code>, otherwise <code>false</code>
     */
    public boolean handlesElement (StructureElement element) {
        return (element != null) && (element instanceof HyperlinkEventRecordable);
    }

    /**
     * Sets the structure element to edit.
     *
     * @param element DOCUMENT ME!
     */
    public void setElement (StructureElement element) {
        super.setElement (element);

        HyperlinkEventRecordable hRecordable = (HyperlinkEventRecordable) element;
        urlField.setText (hRecordable.getURL ());
        descriptionField.setText (hRecordable.getDescription ());
        typeField.setText (hRecordable.getType ());
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.