jdk/src/solaris/classes/sun/awt/X11/XEmbedServerTester.java
author darcy
Thu, 13 Mar 2014 12:40:27 -0700
changeset 23647 41d22f2dbeb5
parent 22584 eed64ee05369
permissions -rw-r--r--
8033712: Fix more serial lint warnings in sun.awt Reviewed-by: alanb, serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 18178
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
//import static sun.awt.X11.XEmbed.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    31
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import static sun.awt.X11.XConstants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Test XEmbed server implementation. See file:///home/dom/bugs/4931668/test_plan.html for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * specification and references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class XEmbedServerTester implements XEventDispatcher {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    40
    private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedServerTester");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private final Object EVENT_LOCK = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static final int SYSTEM_EVENT_MASK = 0x8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int my_version, server_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    XEmbedHelper xembed = new XEmbedHelper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    boolean focused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    int focusedKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int focusedServerComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    boolean reparent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    long parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    boolean windowActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    boolean xembedActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    XBaseWindow window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    volatile int eventWaited = -1, eventReceived = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int mapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    int accel_key, accel_keysym, accel_mods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static Rectangle initialBounds = new Rectangle(0, 0, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    Robot robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Rectangle serverBounds[]; // first rectangle is for the server frame, second is for dummy frame, others are for its children
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final int SERVER_BOUNDS = 0, OTHER_FRAME = 1, SERVER_FOCUS = 2, SERVER_MODAL = 3, MODAL_CLOSE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    LinkedList<Integer> events = new LinkedList<Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private XEmbedServerTester(Rectangle serverBounds[], long parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        focusedKind = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        focusedServerComponent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        reparent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        windowActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        xembedActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        my_version = XEmbedHelper.XEMBED_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.serverBounds = serverBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (serverBounds.length < 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new IllegalArgumentException("There must be at least five areas: server-activation, server-deactivation, server-focus, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                               "server-modal show, modal-close");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            robot.setAutoDelay(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw new RuntimeException("Can't create robot");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        initAccel();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    84
        if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    85
            xembedLog.finer("XEmbed client(tester), embedder window: " + Long.toHexString(parent));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    86
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static XEmbedServerTester getTester(Rectangle serverBounds[], long parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return new XEmbedServerTester(serverBounds, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private void dumpReceivedEvents() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    94
        if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    95
            xembedLog.finer("Events received so far:");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    96
            int pos = 0;
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    97
            for (Integer event : events) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    98
                xembedLog.finer((pos++) + ":" + XEmbedHelper.msgidToString(event));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
    99
            }
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   100
            xembedLog.finer("End of event dump");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void test1_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        res = activateServer(getEventPos());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void test1_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void test1_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        requestFocusNoWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void test1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        requestFocusNoWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        activateServer(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void test1_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        checkWindowActivated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void test1_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        res = deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        checkFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void test1_7() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void test2_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        focusServerNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        checkFocusedServerNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public void test2_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        focusServerPrev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        checkFocusedServerPrev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void test3_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        reparent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void test3_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        reparent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void test3_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        my_version = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (server_version != XEmbedHelper.XEMBED_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new RuntimeException("Version " + server_version + " is not minimal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void test3_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        window.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // TODO: how can we detect that XEmbed ended?  So far we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // just checking that XEmbed server won't end up with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // exception, which should end up testing, hopefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // Sleep before exiting the tester application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void test3_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), XToolkit.getDefaultRootWindow(), 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        activateServerNoWait(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (checkEventList(res, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            throw new RuntimeException("Focus was been given to the client after XEmbed has ended");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void test4_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        checkMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void test4_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        checkMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public void test4_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        checkNotMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public void test4_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        sleep(1000);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   267
        if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throw new RuntimeException("Client has been mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void test6_1_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        waitForEvent(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void test6_1_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new RuntimeException("Accelerator has been activated in inactive embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void test6_1_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        unregisterAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            throw new RuntimeException("Accelerator has been activated after unregistering");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public void test6_1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            throw new RuntimeException("Accelerator has been activated in focused client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void test6_2_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        waitSystemEvent(res, KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public void test6_2_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            throw new RuntimeException("Accelerator has been activated in inactive embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public void test6_2_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        ungrabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            throw new RuntimeException("Accelerator has been activated after unregistering");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public void test6_2_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        int pos = checkEventList(res, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (pos != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            pos = checkEventList(pos+1, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (pos != -1) { // Second event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                throw new RuntimeException("Accelerator has been activated in focused client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public void test7_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int res = showModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public void test7_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int res = showModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        res = hideModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public void test9_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    private int embed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            XCreateWindowParams params =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                new XCreateWindowParams(new Object[] {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 120
diff changeset
   390
                    XBaseWindow.PARENT_WINDOW, Long.valueOf(reparent?XToolkit.getDefaultRootWindow():parent),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    XBaseWindow.BOUNDS, initialBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    XBaseWindow.EMBEDDED, Boolean.TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    XBaseWindow.VISIBLE, Boolean.valueOf(mapped == XEmbedHelper.XEMBED_MAPPED),
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 120
diff changeset
   394
                    XBaseWindow.EVENT_MASK, Long.valueOf(VisibilityChangeMask | StructureNotifyMask |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                                     SubstructureNotifyMask | KeyPressMask)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            window = new XBaseWindow(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   398
            if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   399
                xembedLog.finer("Created tester window: " + window);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   400
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            XToolkit.addEventDispatcher(window.getWindow(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (reparent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                xembedLog.finer("Reparenting to embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), parent, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    private void updateEmbedInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        long[] info = new long[] { my_version, mapped };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        long data = Native.card32ToData(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            XEmbedHelper.XEmbedInfo.setAtomData(window.getWindow(), data, info.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            XEmbedHelper.unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private int getEventPos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return events.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private int embedCompletely() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        xembedLog.fine("Embedding completely");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        embed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        waitEmbeddedNotify(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private int requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        xembedLog.fine("Requesting focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    private int requestFocusNoWait() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        xembedLog.fine("Requesting focus without wait");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    private int activateServer(int prev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        int res = activateServerNoWait(prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    private int activateServerNoWait(int prev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        xembedLog.fine("Activating server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            xembedLog.fine("Activation already received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        Point loc = serverBounds[SERVER_BOUNDS].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        loc.x += serverBounds[SERVER_BOUNDS].getWidth()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    private int deactivateServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        xembedLog.fine("Deactivating server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        Point loc = serverBounds[OTHER_FRAME].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        loc.x += serverBounds[OTHER_FRAME].getWidth()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        loc.y += serverBounds[OTHER_FRAME].getHeight()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        waitWindowDeactivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    private int focusServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        xembedLog.fine("Focusing server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        boolean weFocused = focused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Point loc = serverBounds[SERVER_FOCUS].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (weFocused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    private int focusServerNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        xembedLog.fine("Focusing next server component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    private int focusServerPrev() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        xembedLog.fine("Focusing previous server component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    private void waitEmbeddedNotify(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    private void waitFocusGained(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    private void waitFocusLost(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private void waitWindowActivated(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    private void waitWindowDeactivated(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private void waitSystemEvent(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        waitForEvent(position, event | SYSTEM_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    private void waitForEvent(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // Check for already received events after the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (checkEventList(position, event) != -1) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   538
                if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   539
                    xembedLog.finer("The event " + XEmbedHelper.msgidToString(event) + " has already been received");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   540
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if (eventReceived == event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                // Already received
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   546
                if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   547
                    xembedLog.finer("Already received " + XEmbedHelper.msgidToString(event));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   548
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            eventReceived = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            eventWaited = event;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   553
            if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   554
                xembedLog.finer("Waiting for " + XEmbedHelper.msgidToString(event) + " starting from " + position);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   555
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                EVENT_LOCK.wait(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            } catch (InterruptedException ie) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
   559
                xembedLog.warning("Event wait interrupted", ie);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            eventWaited = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            if (checkEventList(position, event) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                dumpReceivedEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                throw new RuntimeException("Didn't receive event " + XEmbedHelper.msgidToString(event) + " but recevied " + XEmbedHelper.msgidToString(eventReceived));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            } else {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   566
                if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   567
                    xembedLog.finer("Successfully recevied " + XEmbedHelper.msgidToString(event));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   568
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Checks if the <code>event</code> is already in a list at position >= <code>position</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private int checkEventList(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (position == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            for (int i = position; i < events.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                if (events.get(i) == event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    private void checkFocusedServerNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (focusedServerComponent != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            throw new RuntimeException("Wrong focused server component, should be 0, but it is " + focusedServerComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    private void checkFocusedServerPrev() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (focusedServerComponent != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw new RuntimeException("Wrong focused server component, should be 2, but it is " + focusedServerComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private void checkFocusGained(int kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (!focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw new RuntimeException("Didn't receive FOCUS_GAINED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (focusedKind != kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            throw new RuntimeException("Kinds don't match, required: " + kind + ", current: " + focusedKind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    private void checkNotFocused() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            throw new RuntimeException("Focused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private void checkFocused() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (!focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            throw new RuntimeException("Not Focused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    private void checkFocusLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            throw new RuntimeException("Didn't receive FOCUS_LOST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    private void checkWindowActivated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (!windowActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            throw new RuntimeException("Window is not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private void checkMapped() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   630
        if (XlibUtil.getWindowMapState(window.getWindow()) == IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            throw new RuntimeException("Client is not mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    private void checkNotMapped() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   635
        if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            throw new RuntimeException("Client is mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    private void sendMessage(int message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        xembed.sendMessage(parent, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    private void sendMessage(int message, int detail, long data1, long data2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        xembed.sendMessage(parent, message, detail, data1, data2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (ev.get_type() == ClientMessage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            XClientMessageEvent msg = ev.get_xclient();
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 18178
diff changeset
   650
            if (msg.get_message_type() == XEmbedHelper.XEmbed.getAtom()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   651
                if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   652
                    xembedLog.fine("Embedded message: " + XEmbedHelper.msgidToString((int)msg.get_data(1)));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   653
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                switch ((int)msg.get_data(1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                  case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                      xembedActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                      server_version = (int)msg.get_data(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                  case XEmbedHelper.XEMBED_WINDOW_ACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                      windowActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                  case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                      windowActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                  case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                      focused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                      focusedKind = (int)msg.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                  case XEmbedHelper.XEMBED_FOCUS_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                      focused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                      focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                      focusedServerComponent = (int)msg.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    events.add((int)msg.get_data(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   678
                    if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   679
                        xembedLog.finer("Tester is waiting for " +  XEmbedHelper.msgidToString(eventWaited));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   680
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    if ((int)msg.get_data(1) == eventWaited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                        eventReceived = (int)msg.get_data(1);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   683
                        if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   684
                            xembedLog.finer("Notifying waiting object for event " + System.identityHashCode(EVENT_LOCK));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   685
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        EVENT_LOCK.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            synchronized(EVENT_LOCK) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 22567
diff changeset
   692
                int eventID = ev.get_type() | SYSTEM_EVENT_MASK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                events.add(eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   695
                if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   696
                    xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited) + ", but we received " + ev + "(" + XEmbedHelper.msgidToString(eventID) + ")");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   697
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                if (eventID == eventWaited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    eventReceived = eventID;
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   700
                    if (xembedLog.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   701
                        xembedLog.finer("Notifying waiting object" + System.identityHashCode(EVENT_LOCK));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 5506
diff changeset
   702
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    EVENT_LOCK.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    private void sleep(int amount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            Thread.sleep(amount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    private void registerAccelerator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    private void unregisterAccelerator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    private int pressAccelKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        robot.keyPress(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        robot.keyRelease(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private void initAccel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        accel_key = KeyEvent.VK_A;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        accel_mods = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    private void grabKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    private void ungrabKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    private int showModalDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        xembedLog.fine("Showing modal dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        Point loc = serverBounds[SERVER_MODAL].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    private int hideModalDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        xembedLog.fine("Hide modal dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
//         Point loc = serverBounds[MODAL_CLOSE].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
//         loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
//         loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
//         robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
//         robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
//         robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
//         robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        robot.keyPress(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        robot.keyRelease(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
}