001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: EventDriver.java,v 1.12 2007/10/05 11:37:26 jskrivanek Exp $ $Revision: 1.12 $ $Date: 2007/10/05 11:37:26 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.input;
048:
049: import java.awt.AWTEvent;
050: import java.awt.Component;
051:
052: import java.awt.event.InputEvent;
053: import java.awt.event.KeyEvent;
054:
055: import org.netbeans.jemmy.ComponentIsNotVisibleException;
056: import org.netbeans.jemmy.JemmyException;
057: import org.netbeans.jemmy.QueueTool;
058: import org.netbeans.jemmy.Timeout;
059:
060: import org.netbeans.jemmy.drivers.KeyDriver;
061: import org.netbeans.jemmy.drivers.LightSupportiveDriver;
062:
063: import org.netbeans.jemmy.operators.ComponentOperator;
064: import org.netbeans.jemmy.operators.ContainerOperator;
065: import org.netbeans.jemmy.operators.JComponentOperator;
066:
067: /**
068: * Superclass for all drivers using event dispatching.
069: *
070: * @author Alexandre Iline(alexandre.iline@sun.com)
071: */
072: public class EventDriver extends LightSupportiveDriver {
073: QueueTool queueTool;
074:
075: /**
076: * Constructs an EventDriver object.
077: * @param supported an array of supported class names
078: */
079: public EventDriver(String[] supported) {
080: super (supported);
081: queueTool = new QueueTool();
082: }
083:
084: /**
085: * Constructs an EventDriver object suporting ComponentOperator.
086: */
087: public EventDriver() {
088: this (
089: new String[] { "org.netbeans.jemmy.operators.ComponentOperator" });
090: }
091:
092: /**
093: * Dispatches an event to the component.
094: * @param comp Component to dispatch events to.
095: * @param event an event to dispatch.
096: */
097: public void dispatchEvent(Component comp, AWTEvent event) {
098: // checkVisibility(comp);
099: QueueTool.processEvent(event);
100: }
101:
102: /**
103: * Checks component visibility.
104: * @param component a component.
105: */
106: protected void checkVisibility(Component component) {
107: if (!component.isVisible()) {
108: throw (new ComponentIsNotVisibleException(component));
109: }
110: }
111:
112: /**
113: * Class used fot execution of an event through the dispatching thread.
114: */
115: protected class Dispatcher extends QueueTool.QueueAction {
116: AWTEvent event;
117: Component component;
118:
119: /**
120: * Constructs an EventDriver$Dispatcher object.
121: * @param component a component to dispatch event to.
122: * @param e an event to dispatch.
123: */
124: public Dispatcher(Component component, AWTEvent e) {
125: super (e.getClass().getName() + " event dispatching");
126: this .component = component;
127: event = e;
128: }
129:
130: public Object launch() {
131: checkVisibility(component);
132: component.dispatchEvent(event);
133: return (null);
134: }
135: }
136: }
|