jdk/test/sanity/client/lib/jemmy/src/org/netbeans/jemmy/drivers/input/EventDriver.java
changeset 36744 a00905527ec2
equal deleted inserted replaced
36743:bdc3f1b79fb7 36744:a00905527ec2
       
     1 /*
       
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 package org.netbeans.jemmy.drivers.input;
       
    24 
       
    25 import java.awt.AWTEvent;
       
    26 import java.awt.Component;
       
    27 
       
    28 import org.netbeans.jemmy.ComponentIsNotVisibleException;
       
    29 import org.netbeans.jemmy.QueueTool;
       
    30 import org.netbeans.jemmy.drivers.LightSupportiveDriver;
       
    31 
       
    32 /**
       
    33  * Superclass for all drivers using event dispatching.
       
    34  *
       
    35  * @author Alexandre Iline(alexandre.iline@oracle.com)
       
    36  */
       
    37 public class EventDriver extends LightSupportiveDriver {
       
    38 
       
    39     /**
       
    40      * Constructs an EventDriver object.
       
    41      *
       
    42      * @param supported an array of supported class names
       
    43      */
       
    44     public EventDriver(String[] supported) {
       
    45         super(supported);
       
    46     }
       
    47 
       
    48     /**
       
    49      * Constructs an EventDriver object suporting ComponentOperator.
       
    50      */
       
    51     public EventDriver() {
       
    52         this(new String[]{"org.netbeans.jemmy.operators.ComponentOperator"});
       
    53     }
       
    54 
       
    55     /**
       
    56      * Dispatches an event to the component.
       
    57      *
       
    58      * @param comp Component to dispatch events to.
       
    59      * @param event an event to dispatch.
       
    60      */
       
    61     public void dispatchEvent(Component comp, AWTEvent event) {
       
    62 //        checkVisibility(comp);
       
    63         QueueTool.processEvent(event);
       
    64     }
       
    65 
       
    66     /**
       
    67      * Checks component visibility.
       
    68      *
       
    69      * @param component a component.
       
    70      */
       
    71     protected void checkVisibility(Component component) {
       
    72         if (!component.isVisible()) {
       
    73             throw (new ComponentIsNotVisibleException(component));
       
    74         }
       
    75     }
       
    76 
       
    77     /**
       
    78      * Class used fot execution of an event through the dispatching thread.
       
    79      */
       
    80     protected class Dispatcher extends QueueTool.QueueAction<Void> {
       
    81 
       
    82         AWTEvent event;
       
    83         Component component;
       
    84 
       
    85         /**
       
    86          * Constructs an EventDriver$Dispatcher object.
       
    87          *
       
    88          * @param component a component to dispatch event to.
       
    89          * @param e an event to dispatch.
       
    90          */
       
    91         public Dispatcher(Component component, AWTEvent e) {
       
    92             super(e.getClass().getName() + " event dispatching");
       
    93             this.component = component;
       
    94             event = e;
       
    95         }
       
    96 
       
    97         @Override
       
    98         public Void launch() {
       
    99             checkVisibility(component);
       
   100             component.dispatchEvent(event);
       
   101             return null;
       
   102         }
       
   103     }
       
   104 }