jdk/test/java/awt/regtesthelpers/Util.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 36511 9d0388c6b336
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
     2
 * Copyright (c) 2006, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1171
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1171
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1171
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
package test.java.awt.regtesthelpers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * <p>This class contains utilities useful for regression testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * <p>When using jtreg you would include this class into the build
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * list via something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
     @library ../../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
     @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
     @run main YourTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
   </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Note that if you are about to create a test based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Applet-template, then put those lines into html-file, not in java-file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p> And put an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * into the java source of test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.Robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.IllegalComponentStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.AWTEvent;
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
    54
import java.awt.Color;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.event.WindowAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.awt.event.WindowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.awt.event.WindowFocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.awt.event.FocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import java.util.concurrent.atomic.AtomicBoolean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public final class Util {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Util() {} // this is a helper class with static methods :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
28535
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    79
    private volatile static Robot robot;
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @throws RuntimeException when creation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static Robot createRobot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
28535
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    86
            if (robot == null) {
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    87
                robot = new Robot();
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    88
            }
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
    89
            return robot;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (AWTException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new RuntimeException("Error: unable to create robot", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
    97
     * Makes the window visible and waits until it's shown.
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
    98
     */
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
    99
    public static void showWindowWait(Window win) {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   100
        win.setVisible(true);
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   101
        waitTillShown(win);
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   102
    }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   103
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   104
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Moves mouse pointer in the center of given {@code comp} component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * using {@code robot} parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static void pointOnComp(final Component comp, final Robot robot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Moves mouse pointer in the center of a given {@code comp} component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * and performs a left mouse button click using the {@code robot} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * with the {@code delay} delay between press and release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static void clickOnComp(final Component comp, final Robot robot, int delay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        pointOnComp(comp, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        robot.delay(delay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        robot.delay(delay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Moves mouse pointer in the center of a given {@code comp} component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * and performs a left mouse button click using the {@code robot} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * with the default delay between press and release.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static void clickOnComp(final Component comp, final Robot robot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        clickOnComp(comp, robot, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   135
    public static Point getTitlePoint(Window decoratedWindow) {
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   136
        Point p = decoratedWindow.getLocationOnScreen();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   137
        Dimension d = decoratedWindow.getSize();
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   138
        return new Point(p.x + (int)(d.getWidth()/2),
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   139
                         p.y + (int)(decoratedWindow.getInsets().top/2));
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   140
    }
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   141
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Clicks on a title of Frame/Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * WARNING: it may fail on some platforms when the window is not wide enough.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   148
            Point p = getTitlePoint(decoratedWindow);
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   149
            robot.mouseMove(p.x, p.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
23274
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   157
    /**
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   158
     * Tests whether screen pixel has the expected color performing several
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   159
     * attempts. This method is useful for asynchronous window manager where
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   160
     * it's impossible to determine when drawing actually takes place.
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   161
     *
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   162
     * @param x X position of pixel
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   163
     * @param y Y position of pixel
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   164
     * @param color expected color
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   165
     * @param attempts number of attempts to undertake
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   166
     * @param delay delay before each attempt
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   167
     * @param robot a robot to use for retrieving pixel color
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   168
     * @return true if pixel color matches the color expected, otherwise false
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   169
     */
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   170
    public static boolean testPixelColor(int x, int y, final Color color, int attempts, int delay, final Robot robot) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   171
        while (attempts-- > 0) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   172
            robot.delay(delay);
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   173
            Color screen = robot.getPixelColor(x, y);
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   174
            if (screen.equals(color)) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   175
                return true;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   176
            }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   177
        }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   178
        return false;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   179
    }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   180
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   181
    /**
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   182
     * Tests whether the area within boundaries has the expected color
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   183
     * performing several attempts. This method is useful for asynchronous
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   184
     * window manager where it's impossible to determine when drawing actually
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   185
     * takes place.
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   186
     *
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   187
     * @param bounds position of area
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   188
     * @param color expected color
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   189
     * @param attempts number of attempts to undertake
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   190
     * @param delay delay before each attempt
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   191
     * @param robot a robot to use for retrieving pixel color
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   192
     * @return true if area color matches the color expected, otherwise false
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   193
     */
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   194
    public static boolean testBoundsColor(final Rectangle bounds, final Color color, int attempts, int delay, final Robot robot) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   195
        int right = bounds.x + bounds.width - 1;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   196
        int bottom = bounds.y + bounds.height - 1;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   197
        while (attempts-- > 0) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   198
            if (testPixelColor(bounds.x, bounds.y, color, 1, delay, robot)
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   199
                && testPixelColor(right, bounds.y, color, 1, 0, robot)
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   200
                && testPixelColor(right, bottom, color, 1, 0, robot)
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   201
                && testPixelColor(bounds.x, bottom, color, 1, 0, robot)) {
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   202
                return true;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   203
            }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   204
        }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   205
        return false;
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   206
    }
3b6993da89df 8013116: Robot moves mouse to point which differs from set in mouseMove on Unity shell
bagiras
parents: 15638
diff changeset
   207
28535
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
   208
    public static void waitForIdle(Robot robot) {
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
   209
        if (robot == null) {
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
   210
            robot = createRobot();
74115b2c211f 8068275: Some tests failed after JDK-8063104
serb
parents: 28087
diff changeset
   211
        }
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 23328
diff changeset
   212
        robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Waits for a notification and for a boolean condition to become true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * The method returns when the above conditions are fullfilled or when the timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param condition the object to be notified and the booelan condition to wait for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param timeout the maximum time to wait in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param catchExceptions if {@code true} the method catches InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return the final boolean value of the {@code condition}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @throws InterruptedException if the awaiting proccess has been interrupted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            synchronized (condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                long startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                while (!condition.get()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    condition.wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    if (System.currentTimeMillis() - startTime >= timeout ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return condition.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * The same as {@code waitForConditionEx(AtomicBoolean, long)} except that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * doesn't throw InterruptedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public static boolean waitForCondition(final AtomicBoolean condition, long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return waitForConditionEx(condition, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            throw new RuntimeException("Error: unexpected exception caught!", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * The same as {@code waitForConditionEx(AtomicBoolean, long)} but without a timeout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public static void waitForConditionEx(final AtomicBoolean condition)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            synchronized (condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                while (!condition.get()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    condition.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * The same as {@code waitForConditionEx(AtomicBoolean)} except that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * doesn't throw InterruptedException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public static void waitForCondition(final AtomicBoolean condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            waitForConditionEx(condition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            throw new RuntimeException("Error: unexpected exception caught!", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public static void waitTillShownEx(final Component comp) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                comp.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            } catch (IllegalComponentStateException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public static void waitTillShown(final Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            waitTillShownEx(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throw new RuntimeException("Error: unexpected exception caught!", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Drags from one point to another with the specified mouse button pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param robot a robot to use for moving the mouse, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param startPoint a start point of the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param endPoint an end point of the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param button one of {@code InputEvent.BUTTON1_MASK},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *     {@code InputEvent.BUTTON2_MASK}, {@code InputEvent.BUTTON3_MASK}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @throws IllegalArgumentException if {@code button} is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *     {@code InputEvent.BUTTON1_MASK}, {@code InputEvent.BUTTON2_MASK},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *     {@code InputEvent.BUTTON3_MASK}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public static void drag(Robot robot, Point startPoint, Point endPoint, int button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (!(button == InputEvent.BUTTON1_MASK || button == InputEvent.BUTTON2_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                || button == InputEvent.BUTTON3_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            throw new IllegalArgumentException("invalid mouse button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        robot.mouseMove(startPoint.x, startPoint.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        robot.mousePress(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            mouseMove(robot, startPoint, endPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            robot.mouseRelease(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Moves the mouse pointer from one point to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Uses Bresenham's algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param robot a robot to use for moving the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param startPoint a start point of the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param endPoint an end point of the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public static void mouseMove(Robot robot, Point startPoint, Point endPoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        int dx = endPoint.x - startPoint.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        int dy = endPoint.y - startPoint.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int ax = Math.abs(dx) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int ay = Math.abs(dy) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        int sx = signWOZero(dx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        int sy = signWOZero(dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        int x = startPoint.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int y = startPoint.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        int d = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (ax > ay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            d = ay - ax/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            while (true){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                robot.mouseMove(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                if (x == endPoint.x){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                if (d >= 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    y = y + sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    d = d - ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                x = x + sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                d = d + ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            d = ax - ay/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            while (true){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                robot.mouseMove(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                if (y == endPoint.y){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                if (d >= 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    x = x + sx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    d = d - ay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                y = y + sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                d = d + ax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private static int signWOZero(int i){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return (i > 0)? 1: -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private static int sign(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return n < 0 ? -1 : n == 0 ? 0 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /** Returns {@code WindowListener} instance that diposes {@code Window} on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *  "window closing" event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @return    the {@code WindowListener} instance that could be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *            on a {@code Window}. After that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *            the {@code Window} is disposed when "window closed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *            event is sent to the {@code Window}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public static WindowListener getClosingWindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return new WindowAdapter () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            public void windowClosing(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                e.getWindow().dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * The values directly map to the ones of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * sun.awt.X11.XWM & sun.awt.motif.MToolkit classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        UNDETERMINED_WM = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        NO_WM = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        OTHER_WM = 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        OPENLOOK_WM = 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        MOTIF_WM = 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        CDE_WM = 6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        ENLIGHTEN_WM = 7,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        KDE2_WM = 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        SAWFISH_WM = 9,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        ICE_WM = 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        METACITY_WM = 11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        COMPIZ_WM = 12,
12829
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   424
        LG3D_WM = 13,
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   425
        CWM_WM = 14,
506020af237a 7043963: AWT workaround missing for Mutter.
omajid
parents: 12535
diff changeset
   426
        MUTTER_WM = 15;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Returns -1 in case of not X Window or any problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public static int getWMID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        Class clazz = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if ("sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                clazz = Class.forName("sun.awt.X11.XWM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            } else if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                clazz = Class.forName("sun.awt.motif.MToolkit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        } catch (ClassNotFoundException cnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            cnfe.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            final Class _clazz = clazz;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 36511
diff changeset
   448
            Method m_addExports = Class.forName("java.awt.Helper").getDeclaredMethod("addExports", String.class, java.lang.Module.class);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   449
            // No MToolkit anymore: nothing to do about it.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   450
            // We may be called from non-X11 system, and this permission cannot be delegated to a test.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   451
            m_addExports.invoke(null, "sun.awt.X11", Util.class.getModule());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            Method m_getWMID = (Method)AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                            Method method = _clazz.getDeclaredMethod("getWMID", new Class[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                            if (method != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                method.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                            return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return ((Integer)m_getWMID.invoke(null, new Object[] {})).intValue();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   469
        } catch (ClassNotFoundException cnfe) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   470
            cnfe.printStackTrace();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   471
        } catch (NoSuchMethodException nsme) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 28535
diff changeset
   472
            nsme.printStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            iae.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   481
    //Cleans all the references
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   482
    public static void cleanUp() {
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   483
        apListener = null;
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   484
        fgListener = null;
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   485
        wgfListener = null;
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   486
    }
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 12829
diff changeset
   487
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    ////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    // Some stuff to test focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    ////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private static WindowGainedFocusListener wgfListener = new WindowGainedFocusListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private static FocusGainedListener fgListener = new FocusGainedListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    private static ActionPerformedListener apListener = new ActionPerformedListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    private abstract static class EventListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        AtomicBoolean notifier = new AtomicBoolean(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        boolean printEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        public void listen(Component comp, boolean printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            this.comp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            this.printEvent = printEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            notifier.set(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            setListener(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public AtomicBoolean getNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            return notifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        abstract void setListener(Component comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        void printAndNotify(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                System.err.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            synchronized (notifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                notifier.set(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                notifier.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    private static class WindowGainedFocusListener extends EventListener implements WindowFocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        void setListener(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            ((Window)comp).addWindowFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        public void windowGainedFocus(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            ((Window)comp).removeWindowFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            printAndNotify(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        public void windowLostFocus(WindowEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    private static class FocusGainedListener extends EventListener implements FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        void setListener(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            comp.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            comp.removeFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            printAndNotify(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        public void focusLost(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    private static class ActionPerformedListener extends EventListener implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        void setListener(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            ((Button)comp).addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            ((Button)comp).removeActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            printAndNotify(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        EventListener listener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        switch (eventID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        case WindowEvent.WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            listener = wgfListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            listener = fgListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        case ActionEvent.ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            listener = apListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        listener.listen(comp, printEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        action.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return Util.waitForCondition(listener.getNotifier(), time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Tracks WINDOW_GAINED_FOCUS event for a window caused by an action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @param window the window to track the event for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @param action the action to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @param time the max time to wait for the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param printEvent should the event received be printed or doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @return true if the event has been received, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public static boolean trackWindowGainedFocus(Window window, Runnable action, int time, boolean printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        return trackEvent(WindowEvent.WINDOW_GAINED_FOCUS, window, action, time, printEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Tracks FOCUS_GAINED event for a component caused by an action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see #trackWindowGainedFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public static boolean trackFocusGained(Component comp, Runnable action, int time, boolean printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return trackEvent(FocusEvent.FOCUS_GAINED, comp, action, time, printEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Tracks ACTION_PERFORMED event for a button caused by an action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see #trackWindowGainedFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public static boolean trackActionPerformed(Button button, Runnable action, int time, boolean printEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return trackEvent(ActionEvent.ACTION_PERFORMED, button, action, time, printEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   614
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   615
    /*
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   616
     * Requests focus on the component provided and waits for the result.
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   617
     * @return true if the component has been focused, false otherwise.
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   618
     */
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   619
    public static boolean focusComponent(Component comp, int time) {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   620
        return focusComponent(comp, time, false);
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   621
    }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   622
    public static boolean focusComponent(final Component comp, int time, boolean printEvent) {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   623
        return trackFocusGained(comp,
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   624
                                new Runnable() {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   625
                                    public void run() {
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   626
                                        comp.requestFocus();
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   627
                                    }
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   628
                                },
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   629
                                time, printEvent);
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   630
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 2
diff changeset
   631
    }
12535
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   632
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   633
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   634
    /**
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   635
     * Invokes the <code>task</code> on the EDT thread.
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   636
     *
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   637
     * @return result of the <code>task</code>
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   638
     */
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   639
    public static <T> T invokeOnEDT(final java.util.concurrent.Callable<T> task) throws Exception {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   640
        final java.util.List<T> result = new java.util.ArrayList<T>(1);
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   641
        final Exception[] exception = new Exception[1];
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   642
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   643
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   644
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   645
            @Override
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   646
            public void run() {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   647
                try {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   648
                    result.add(task.call());
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   649
                } catch (Exception e) {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   650
                    exception[0] = e;
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   651
                }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   652
            }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   653
        });
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   654
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   655
        if (exception[0] != null) {
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   656
            throw exception[0];
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   657
        }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   658
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   659
        return result.get(0);
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   660
    }
6d2ee83614e8 7154048: [macosx] At least drag twice, the toolbar can be dragged to the left side
alexsch
parents: 5506
diff changeset
   661
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
}