src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventQueueMonitor.java
author herrick
Tue, 12 Nov 2019 10:18:11 -0500
branchJDK-8200758-branch
changeset 59033 5ac41b9db9da
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29883
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     1
/*
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     4
 *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    10
 *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    15
 * accompanied this code).
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    16
 *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    20
 *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    23
 * questions.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    24
 */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    25
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    26
package com.sun.java.accessibility.util;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    27
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    28
import java.util.*;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    29
import java.awt.*;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    30
import java.awt.event.*;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    31
import javax.accessibility.*;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    32
import java.security.AccessController;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    33
import java.security.PrivilegedAction;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    34
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    35
/**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    36
 * The {@code EventQueueMonitor} class provides key core functionality for Assistive
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    37
 * Technologies (and other system-level technologies that need some of the same
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    38
 * things that Assistive Technology needs).
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    39
 *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    40
 * @see AWTEventMonitor
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    41
 * @see SwingEventMonitor
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    42
 */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    43
public class EventQueueMonitor
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    44
        implements AWTEventListener {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    45
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    46
    // NOTE:  All of the following properties are static.  The reason
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    47
    //        for this is that there may be multiple EventQueue instances
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    48
    //        in use in the same VM.  By making these properties static,
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    49
    //        we can guarantee we get the information from all of the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    50
    //        EventQueue instances.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    51
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    52
    // The stuff that is cached.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    53
    //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    54
    static Vector<Container>topLevelWindows = new Vector<>();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    55
    static Window topLevelWindowWithFocus  = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    56
    static Point currentMousePosition      = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    57
    static Component currentMouseComponent = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    58
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    59
    // Low-level listener interfaces
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    60
    //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    61
    static GUIInitializedListener guiInitializedListener = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    62
    static TopLevelWindowListener topLevelWindowListener = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    63
    static MouseMotionListener    mouseMotionListener    = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    64
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    65
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    66
     * Class variable stating whether the assistive technologies have
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    67
     * been loaded yet or not.  The assistive technologies won't be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    68
     * loaded until the first event is posted to the EventQueue.  This
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    69
     * gives the toolkit a chance to do all the necessary initialization
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    70
     * it needs to do.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    71
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    72
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    73
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    74
     * Class variable stating whether the GUI subsystem has been initialized
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    75
     * or not.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    76
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    77
     * @see #isGUIInitialized
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    78
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    79
    static boolean guiInitialized = false;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    80
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    81
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    82
     * Queue that holds events for later processing.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    83
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    84
    static EventQueueMonitorItem componentEventQueue = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    85
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    86
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    87
     * Class that tells us what the component event dispatch thread is.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    88
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    89
    static private ComponentEvtDispatchThread cedt = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    90
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    91
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    92
     * Handle the synchronization between the thing that populates the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    93
     * component event dispatch thread ({@link #queueComponentEvent})
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    94
     * and the thing that processes the events ({@link ComponentEvtDispatchThread}).
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    95
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    96
    static Object componentEventQueueLock = new Object();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    97
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    98
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
    99
     * Create a new {@code EventQueueMonitor} instance.  Normally, this will
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   100
     * be called only by the AWT Toolkit during initialization time.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   101
     * Assistive technologies should not create instances of
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   102
     * EventQueueMonitor by themselves.  Instead, they should either
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   103
     * refer to it directly via the static methods in this class, e.g.,
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   104
     * {@link #getCurrentMousePosition} or obtain the instance by asking the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   105
     * Toolkit, e.g., {@link java.awt.Toolkit#getSystemEventQueue}.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   106
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   107
    public EventQueueMonitor() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   108
        if (cedt == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   109
            cedt = new ComponentEvtDispatchThread("EventQueueMonitor-ComponentEvtDispatch");
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   110
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   111
            cedt.setDaemon(true);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   112
            cedt.start();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   113
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   114
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   115
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   116
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   117
     * Queue up a {@link java.awt.event.ComponentEvent ComponentEvent} for later
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   118
     * processing by the {@link ComponentEvtDispatch} thread.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   119
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   120
     * @param e a {@code ComponentEvent}
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   121
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   122
    static void queueComponentEvent(ComponentEvent e) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   123
        synchronized(componentEventQueueLock) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   124
            EventQueueMonitorItem eqi = new EventQueueMonitorItem(e);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   125
            if (componentEventQueue == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   126
                componentEventQueue = eqi;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   127
            } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   128
                EventQueueMonitorItem q = componentEventQueue;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   129
                while (true) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   130
                    if (q.next != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   131
                        q = q.next;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   132
                    } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   133
                        break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   134
                    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   135
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   136
                q.next = eqi;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   137
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   138
            componentEventQueueLock.notifyAll();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   139
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   140
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   141
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   142
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   143
     * Tell the {@code EventQueueMonitor} to start listening for events.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   144
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   145
    public static void maybeInitialize() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   146
        if (cedt == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   147
            java.security.AccessController.doPrivileged(
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   148
                new java.security.PrivilegedAction<Void>() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   149
                    public Void run() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   150
                        try {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   151
                            long eventMask = AWTEvent.WINDOW_EVENT_MASK |
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   152
                                AWTEvent.FOCUS_EVENT_MASK |
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   153
                                AWTEvent.MOUSE_MOTION_EVENT_MASK;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   154
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   155
                            Toolkit.getDefaultToolkit().addAWTEventListener(new EventQueueMonitor(), eventMask);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   156
                        } catch (Exception e) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   157
                        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   158
                        return null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   159
                    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   160
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   161
            );
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   162
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   163
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   164
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   165
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   166
     * Handle events as a result of registering a listener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   167
     * on the {@link java.awt.EventQueue EventQueue} in {@link #maybeInitialize}.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   168
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   169
    public void eventDispatched(AWTEvent theEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   170
        processEvent(theEvent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   171
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   172
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   173
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   174
     * Assisitive technologies that have
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   175
     * registered a {@link GUIInitializedListener} will be notified.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   176
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   177
     * @see #addGUIInitializedListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   178
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   179
    static void maybeNotifyAssistiveTechnologies() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   180
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   181
        if (!guiInitialized) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   182
            guiInitialized = true;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   183
            if (guiInitializedListener != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   184
                guiInitializedListener.guiInitialized();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   185
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   186
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   187
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   188
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   189
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   190
    /********************************************************************/
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   191
    /*                                                                  */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   192
    /* Package Private Methods                                          */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   193
    /*                                                                  */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   194
    /********************************************************************/
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   195
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   196
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   197
     * Add a Container to the list of top-level containers
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   198
     * in the cache.  This follows the object's hierarchy up the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   199
     * tree until it finds the top most parent.  If the parent is
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   200
     * not already in the list of Containers, it adds it to the list.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   201
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   202
     * @param c the Container
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   203
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   204
    static void addTopLevelWindow(Component c) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   205
        Container parent;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   206
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   207
        if (c == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   208
            return;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   209
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   210
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   211
        if (!(c instanceof Window)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   212
            addTopLevelWindow(c.getParent());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   213
            return;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   214
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   215
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   216
        if ((c instanceof Dialog) || (c instanceof Window)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   217
            parent = (Container) c;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   218
        } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   219
            parent = c.getParent();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   220
            if (parent != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   221
                addTopLevelWindow(parent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   222
                return;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   223
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   224
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   225
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   226
        if (parent == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   227
            parent = (Container) c;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   228
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   229
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   230
        // Because this method is static, do not make it synchronized because
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   231
        // it can lock the whole class.  Instead, just lock what needs to be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   232
        // locked.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   233
        //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   234
        synchronized (topLevelWindows) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   235
            if ((parent != null) && !topLevelWindows.contains(parent)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   236
                topLevelWindows.addElement(parent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   237
                if (topLevelWindowListener != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   238
                    topLevelWindowListener.topLevelWindowCreated((Window) parent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   239
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   240
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   241
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   242
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   243
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   244
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   245
     * Removes a container from the list of top level containers in the cache.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   246
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   247
     * @param c the top level container to remove
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   248
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   249
    static void removeTopLevelWindow(Window w) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   250
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   251
        // Because this method is static, do not make it synchronized because
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   252
        // it can lock the whole class.  Instead, just lock what needs to be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   253
        // locked.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   254
        //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   255
        synchronized (topLevelWindows) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   256
            if (topLevelWindows.contains(w)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   257
                topLevelWindows.removeElement(w);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   258
                if (topLevelWindowListener != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   259
                    topLevelWindowListener.topLevelWindowDestroyed(w);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   260
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   261
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   262
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   263
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   264
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   265
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   266
     * Update current mouse position.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   267
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   268
     * @param mouseEvent the MouseEvent that holds the new mouse position.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   269
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   270
    static void updateCurrentMousePosition(MouseEvent mouseEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   271
        Point oldMousePos = currentMousePosition;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   272
        // Be careful here.  The component in the event might be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   273
        // hidden by the time we process the event.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   274
        try {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   275
            Point eventPoint      = mouseEvent.getPoint();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   276
            currentMouseComponent = (Component) (mouseEvent.getSource());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   277
            currentMousePosition  = currentMouseComponent.getLocationOnScreen();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   278
            currentMousePosition.translate(eventPoint.x,eventPoint.y);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   279
        } catch (Exception e) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   280
            currentMousePosition = oldMousePos;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   281
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   282
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   283
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   284
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   285
     * Process the event.  This maintains the event cache in addition
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   286
     * to calling all the registered listeners.  NOTE: The events that
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   287
     * come through here are from peered Components.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   288
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   289
     * @param theEvent the AWTEvent
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   290
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   291
    static void processEvent(AWTEvent theEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   292
        switch (theEvent.getID()) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   293
        case MouseEvent.MOUSE_MOVED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   294
        case MouseEvent.MOUSE_DRAGGED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   295
        case FocusEvent.FOCUS_GAINED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   296
        case WindowEvent.WINDOW_DEACTIVATED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   297
            queueComponentEvent((ComponentEvent) theEvent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   298
            break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   299
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   300
        case WindowEvent.WINDOW_ACTIVATED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   301
            // Dialogs fire WINDOW_ACTIVATED and FOCUS_GAINED events
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   302
            // before WINDOW_OPENED so we need to add topLevelListeners
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   303
            // for the dialog when it is first activated to get a
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   304
            // focus gained event for the focus component in the dialog.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   305
            if (theEvent instanceof ComponentEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   306
                ComponentEvent ce = (ComponentEvent)theEvent;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   307
                if (ce.getComponent() instanceof Window) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   308
                    EventQueueMonitor.addTopLevelWindow(ce.getComponent());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   309
                    EventQueueMonitor.maybeNotifyAssistiveTechnologies();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   310
                } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   311
                    EventQueueMonitor.maybeNotifyAssistiveTechnologies();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   312
                    EventQueueMonitor.addTopLevelWindow(ce.getComponent());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   313
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   314
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   315
            queueComponentEvent((ComponentEvent) theEvent);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   316
            break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   317
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   318
            // handle WINDOW_OPENED and WINDOW_CLOSED events synchronously
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   319
        case WindowEvent.WINDOW_OPENED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   320
            if (theEvent instanceof ComponentEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   321
                ComponentEvent ce = (ComponentEvent)theEvent;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   322
                if (ce.getComponent() instanceof Window) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   323
                    EventQueueMonitor.addTopLevelWindow(ce.getComponent());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   324
                    EventQueueMonitor.maybeNotifyAssistiveTechnologies();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   325
                } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   326
                    EventQueueMonitor.maybeNotifyAssistiveTechnologies();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   327
                    EventQueueMonitor.addTopLevelWindow(ce.getComponent());
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   328
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   329
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   330
            break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   331
        case WindowEvent.WINDOW_CLOSED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   332
            if (theEvent instanceof ComponentEvent) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   333
                ComponentEvent ce = (ComponentEvent)theEvent;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   334
                EventQueueMonitor.removeTopLevelWindow((Window) (ce.getComponent()));
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   335
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   336
            break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   337
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   338
        default:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   339
            break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   340
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   341
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   342
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   343
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   344
     * Internal test
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   345
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   346
    static synchronized Component getShowingComponentAt(Container c, int x, int y) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   347
        if (!c.contains(x, y)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   348
            return null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   349
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   350
        int ncomponents = c.getComponentCount();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   351
        for (int i = 0 ; i < ncomponents ; i++) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   352
            Component comp = c.getComponent(i);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   353
            if (comp != null && comp.isShowing()) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   354
                Point location = comp.getLocation();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   355
                if (comp.contains(x - location.x, y - location.y)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   356
                    return comp;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   357
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   358
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   359
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   360
        return c;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   361
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   362
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   363
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   364
     * Return the Component at the given Point on the screen in the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   365
     * given Container.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   366
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   367
     * @param c the Container to search
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   368
     * @param p the Point in screen coordinates
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   369
     * @return the Component at the given Point on the screen in the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   370
     * given Container -- can be null if no Component is at that Point
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   371
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   372
    static synchronized Component getComponentAt(Container c, Point p) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   373
        if (!c.isShowing()) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   374
            return null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   375
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   376
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   377
        Component comp;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   378
        Point containerLoc = c.getLocationOnScreen();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   379
        Point containerPoint = new Point(p.x - containerLoc.x,
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   380
                                         p.y - containerLoc.y);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   381
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   382
        comp = getShowingComponentAt(c, containerPoint.x, containerPoint.y);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   383
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   384
        if ((comp != c) && (comp instanceof Container)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   385
            return getComponentAt((Container)comp,p);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   386
        } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   387
            return comp;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   388
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   389
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   390
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   391
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   392
     * Obtain the {@link javax.accessibility.Accessible Accessible} object at the given point on the Screen.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   393
     * The return value may be null if an {@code Accessible} object cannot be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   394
     * found at the particular point.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   395
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   396
     * @param p the point to be accessed
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   397
     * @return the {@code Accessible} at the specified point
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   398
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   399
    static public Accessible getAccessibleAt(Point p) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   400
        Window w = getTopLevelWindowWithFocus();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   401
        Window[] wins = getTopLevelWindows();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   402
        Component c = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   403
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   404
        // See if the point we're being asked about is the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   405
        // currentMousePosition.  If so, start with the component
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   406
        // that we know the currentMousePostion is over
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   407
        //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   408
        if (currentMousePosition == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   409
            return null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   410
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   411
        if (currentMousePosition.equals(p)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   412
            if (currentMouseComponent instanceof Container) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   413
                c = getComponentAt((Container) currentMouseComponent, p);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   414
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   415
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   416
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   417
        // Try the window with focus next
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   418
        //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   419
        if (c == null && w != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   420
            c = getComponentAt(w,p);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   421
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   422
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   423
        // Try the other windows next.  [[[WDW: Stacking order???]]]
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   424
        if (c == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   425
            for (int i = 0; i < wins.length; i++) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   426
                c = getComponentAt(wins[i],p);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   427
                if (c != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   428
                    break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   429
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   430
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   431
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   432
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   433
        if (c instanceof Accessible) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   434
            AccessibleContext ac = ((Accessible) c).getAccessibleContext();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   435
            if (ac != null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   436
                AccessibleComponent acmp = ac.getAccessibleComponent();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   437
                if ((acmp != null) && (ac.getAccessibleChildrenCount() != 0)) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   438
                    Point location = acmp.getLocationOnScreen();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   439
                    location.move(p.x - location.x, p.y - location.y);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   440
                    return acmp.getAccessibleAt(location);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   441
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   442
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   443
            return (Accessible) c;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   444
        } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   445
            return Translator.getAccessible(c);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   446
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   447
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   448
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   449
    /********************************************************************/
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   450
    /*                                                                  */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   451
    /* Public Methods                                                   */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   452
    /*                                                                  */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   453
    /********************************************************************/
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   454
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   455
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   456
     * Says whether the GUI subsystem has been initialized or not.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   457
     * If this returns true, the assistive technology can freely
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   458
     * create GUI component instances.  If the return value is false,
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   459
     * the assistive technology should register a {@link GUIInitializedListener}
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   460
     * and wait to create GUI component instances until the listener is
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   461
     * called.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   462
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   463
     * @return true if the GUI subsystem has been initialized
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   464
     * @see #addGUIInitializedListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   465
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   466
    static public boolean isGUIInitialized() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   467
        maybeInitialize();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   468
        return guiInitialized;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   469
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   470
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   471
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   472
     * Adds the specified listener to be notified when the GUI subsystem
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   473
     * is initialized.  Assistive technologies should get the results of
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   474
     * {@link #isGUIInitialized} before calling this method.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   475
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   476
     * @param l the listener to add
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   477
     * @see #isGUIInitialized
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   478
     * @see #removeTopLevelWindowListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   479
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   480
    static public void addGUIInitializedListener(GUIInitializedListener l) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   481
        maybeInitialize();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   482
        guiInitializedListener =
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   483
            GUIInitializedMulticaster.add(guiInitializedListener,l);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   484
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   485
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   486
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   487
     * Removes the specified listener to be notified when the GUI subsystem
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   488
     * is initialized.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   489
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   490
     * @param l the listener to remove
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   491
     * @see #addGUIInitializedListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   492
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   493
    static public void removeGUIInitializedListener(GUIInitializedListener l) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   494
        guiInitializedListener =
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   495
            GUIInitializedMulticaster.remove(guiInitializedListener,l);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   496
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   497
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   498
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   499
     * Adds the specified listener to be notified when a top level window
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   500
     * is created or destroyed.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   501
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   502
     * @param l the listener to add
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   503
     * @see #removeTopLevelWindowListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   504
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   505
    static public void addTopLevelWindowListener(TopLevelWindowListener l) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   506
        topLevelWindowListener =
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   507
            TopLevelWindowMulticaster.add(topLevelWindowListener,l);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   508
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   509
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   510
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   511
     * Removes the specified listener to be notified when a top level window
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   512
     * is created or destroyed.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   513
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   514
     * @param l the listener to remove
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   515
     * @see #addTopLevelWindowListener
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   516
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   517
    static public void removeTopLevelWindowListener(TopLevelWindowListener l) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   518
        topLevelWindowListener =
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   519
            TopLevelWindowMulticaster.remove(topLevelWindowListener,l);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   520
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   521
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   522
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   523
     * Return the last recorded position of the mouse in screen coordinates.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   524
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   525
     * @return the last recorded position of the mouse in screen coordinates
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   526
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   527
    static public Point getCurrentMousePosition() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   528
        return currentMousePosition;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   529
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   530
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   531
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   532
     * Return the list of top level Windows in use in the Java Virtual Machine.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   533
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   534
     * @return an array of top level {@code Window}s in use in the Java Virtual Machine
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   535
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   536
    static public Window[] getTopLevelWindows() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   537
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   538
        // Because this method is static, do not make it synchronized because
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   539
        // it can lock the whole class.  Instead, just lock what needs to be
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   540
        // locked.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   541
        //
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   542
        synchronized (topLevelWindows) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   543
            int count = topLevelWindows.size();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   544
            if (count > 0) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   545
                Window[] w = new Window[count];
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   546
                for (int i = 0; i < count; i++) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   547
                    w[i] = (Window)topLevelWindows.elementAt(i);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   548
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   549
                return w;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   550
            } else {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   551
                return new Window[0];
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   552
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   553
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   554
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   555
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   556
    /**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   557
     * Return the top level {@code Window} that currently has keyboard focus.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   558
     *
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   559
     * @return the top level {@code Window} that currently has keyboard focus
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   560
     */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   561
    static public Window getTopLevelWindowWithFocus() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   562
        return topLevelWindowWithFocus;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   563
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   564
}
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   565
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   566
/**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   567
 * Handle all Component events in a separate thread.  The reason for this is
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   568
 * that WindowEvents tend to be used to do lots of processing on the Window
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   569
 * hierarchy.  As a result, it can frequently result in deadlock situations.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   570
 */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   571
class ComponentEvtDispatchThread extends Thread {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   572
    public ComponentEvtDispatchThread(String name) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   573
        super(name);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   574
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   575
    public void run() {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   576
        ComponentEvent ce = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   577
        while (true) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   578
            synchronized(EventQueueMonitor.componentEventQueueLock) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   579
                while (EventQueueMonitor.componentEventQueue == null) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   580
                    try {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   581
                        EventQueueMonitor.componentEventQueueLock.wait();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   582
                    } catch (InterruptedException e) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   583
                    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   584
                }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   585
                ce = (ComponentEvent)EventQueueMonitor.componentEventQueue.event;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   586
                EventQueueMonitor.componentEventQueue =
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   587
                    EventQueueMonitor.componentEventQueue.next;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   588
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   589
            switch (ce.getID()) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   590
            case MouseEvent.MOUSE_MOVED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   591
            case MouseEvent.MOUSE_DRAGGED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   592
                EventQueueMonitor.updateCurrentMousePosition((MouseEvent) ce);
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   593
                break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   594
            case WindowEvent.WINDOW_ACTIVATED:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   595
                EventQueueMonitor.maybeNotifyAssistiveTechnologies();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   596
                EventQueueMonitor.topLevelWindowWithFocus = ((WindowEvent) ce).getWindow();
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   597
                break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   598
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   599
            default:
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   600
                break;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   601
            }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   602
        }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   603
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   604
}
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   605
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   606
/**
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   607
 * EventQueueMonitorItem is the basic type that handles the
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   608
 * queue for queueComponentEvent and the ComponentEvtDispatchThread.
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   609
 */
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   610
class EventQueueMonitorItem {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   611
    AWTEvent event;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   612
    EventQueueMonitorItem next;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   613
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   614
    EventQueueMonitorItem(AWTEvent evt) {
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   615
        event = evt;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   616
            next = null;
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   617
    }
e02d168adbc6 8076182: Open Source Java Access Bridge - Create Patch for JEP C127 8055831
ptbrunet
parents:
diff changeset
   618
}