ActionEventRecordable.java :  » Testing » jacareto » jacareto » record » Java Open Source

Java Open Source » Testing » jacareto 
jacareto » jacareto » record » ActionEventRecordable.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.record;


import jacareto.comp.Components;
import jacareto.system.Environment;

import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;

/**
 * This class represents list selection event
 *
 * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
 * @version 1.01
 */
public class ActionEventRecordable extends AWTEventRecordable {
    /** The modifiers. */
    private int modifiers;

    /** The action command. */
    private String action;

    /**
     * Creates a new action event recordable with the specified values.
     *
     * @param env the environment
     * @param ID the event id
     * @param sourceName the name of the event's source
     * @param sourceClass the classname of the source
     * @param duration the duration of replaying including the relativeTime
     * @param procTime DOCUMENT ME!
     * @param modifiers the modifiers of the event
     * @param action the command of the action
     */
    public ActionEventRecordable (Environment env, int ID, String sourceName, String sourceClass,
        long duration, long procTime, int modifiers, String action) {
        super(env, ID, sourceName, sourceClass, duration, procTime);
        setModifiers (modifiers);
        setActionCommand (action);
    }

    /**
     * Creates a new action event recordable with the values of the given event and additional
     * information.
     *
     * @param env the environment
     * @param actionEvent the action event to take the main information from
     * @param components the instance which knows the components
     * @param duration the duration
     * @param procTime DOCUMENT ME!
     */
    public ActionEventRecordable (Environment env, ActionEvent actionEvent, Components components,
        long duration, long procTime) {
        this(env, actionEvent.getID (), components.getName ((Component) actionEvent.getSource ()),
            Components.getClassName (actionEvent.getSource ()), duration, procTime,
            actionEvent.getModifiers (), actionEvent.getActionCommand ());
    }

    /**
     * Creates an empty action event recordable with default values and no environment. The
     * environment should be defined with the method {@link
     * jacareto.system.EnvironmentMember#setEnvironment(Environment)} before environment instances
     * will be accessed.
     */
    public ActionEventRecordable () {
        this(null, 0, "", "", 0, 0, 0, "");
    }

    /**
     * Sets the modifiers.
     *
     * @param modifiers the modifiers
     */
    public void setModifiers (int modifiers) {
        this.modifiers = modifiers;
        fireValuesChanged ();
    }

    /**
     * Returns the modifiers.
     *
     * @return the modifiers
     */
    public int getModifiers () {
        return modifiers;
    }

    /**
     * Sets the action command.
     *
     * @param action the action command
     */
    public void setActionCommand (String action) {
        this.action = action;
        fireValuesChanged ();
    }

    /**
     * Returns the action command.
     *
     * @return the action command
     */
    public String getActionCommand () {
        return action;
    }

    /**
     * Returns the name of the mouse event recordable
     *
     * @return the name
     */
    public String getElementName () {
        return getLanguage ().getString ("Recordables.ActionEventRecordable.Name");
    }

    /**
     * Returns a description of the recordable.
     *
     * @return the description
     */
    public String getElementDescription () {
        return getLanguage ().getString ("Recordables.ActionEventRecordable.Description");
    }

    /**
     * Returns a String which describes the content of the recordable shortly.
     *
     * @return a string with a short description of the recordable
     */
    public String toShortString () {
        return getElementName () + " (" + action + ")";
    }

    /**
     * Returns a string representation.
     *
     * @return the string representation
     */
    public String toString () {
        return "ActionEventRecordable[" + getSourceName () + ",ID=" + getID () + ",modifiers=" +
        getModifiers () + ",actionCommand=" + getActionCommand () + "," + getDuration () + "]";
    }

    /**
     * Returns the event with the attributes specified by this recordable (except for the component
     * attributes which will be dummy components).
     *
     * @return DOCUMENT ME!
     */
    public AWTEvent getEvent () {
        return new ActionEvent(new JLabel(), getID (), action, modifiers);
    }

    public boolean hasProcTime () {
        return true;
    }
}
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.