PopupMenuOpenedAndClosed.java :  » Testing » jacareto » jacareto » struct » Java Open Source

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


import jacareto.parse.RecordTokenizer;
import jacareto.parse.RecordTokenizerState;
import jacareto.system.Environment;

/**
 * The popup menu has been opened and closed without selecting a menu item.
 *
 * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
 * @version 1.0
 */
public class PopupMenuOpenedAndClosed extends StructureElement {
    /**
     * Creates a new "popup menu opened and closed" structure element.
     *
     * @param env the environment
     * @param children the child structure elements
     */
    public PopupMenuOpenedAndClosed (Environment env, StructureElement[] children) {
        super(env, children);
    }

    /**
     * Parses a record which is tokenized by the given record tokenizer.
     *
     * @param env DOCUMENT ME!
     * @param recordTokenizer the record tokenizer
     *
     * @return a structure element, or <code>null</code> if this class cannot parse the record at
     *         the current position
     */
    public static StructureElement parse (Environment env, RecordTokenizer recordTokenizer) {
        StructureElement result = null;

        RecordTokenizerState rtState = recordTokenizer.saveState ();

        try {
            PopupMenuOpened opened = (PopupMenuOpened) PopupMenuOpened.parse (env, recordTokenizer);

            if (opened == null) {
                throw new Exception();
            }

            MouseMotionOverComponents motion = (MouseMotionOverComponents) MouseMotionOverComponents.parse (env,
                    recordTokenizer);

            if (motion == null) {
                throw new Exception();
            }

            MouseDrag drag = (MouseDrag) MouseDrag.parse (env, recordTokenizer);

            if ((drag == null) || (drag.getStartX () != drag.getStopX ()) ||
                    (drag.getStartY () != drag.getStopY ())) {
                throw new Exception();
            }

            StructureElement[] children = new StructureElement[3];

            // mouse clicked children
            children[0] = opened;
            children[1] = motion;
            children[2] = drag;
            result = new PopupMenuOpenedAndClosed(env, children);
        } catch (Throwable t) {
            recordTokenizer.restoreState (rtState);
        }

        return result;
    }

    /**
     * Returns the name of the element.
     *
     * @return the name
     */
    public String getElementName () {
        return language.getString ("Structures.PopupMenuOpenedAndClosed.Name");
    }

    /**
     * Returns a description of the element.
     *
     * @return the description
     */
    public String getElementDescription () {
        return language.getString ("Structures.PopupMenuOpenedAndClosed.Description");
    }

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

    /**
     * Clones the element.
     *
     * @return DOCUMENT ME!
     */
    public Object clone () {
        StructureElement[] clonedChildren = getClonedChildren ();

        return new PopupMenuOpenedAndClosed(env, clonedChildren);
    }
}
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.