test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.java
author serb
Wed, 27 Feb 2019 18:46:55 -0800
changeset 54231 e4813eded7cb
parent 50834 9cf279436b9d
permissions -rw-r--r--
8213110: Remove the use of applets in automatic tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50834
9cf279436b9d 8205153: Delete "standard instructions" machinery in the open automated tests
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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: 4368
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4368
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4368
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
/*
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    25
  @test
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    26
  @key headful
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    27
  @bug 4799136
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    28
  @summary Tests that type-ahead for dialog works and doesn't block program
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    29
  @library    ../../regtesthelpers
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    30
  @modules java.desktop/sun.awt
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    31
  @build      Util
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    32
  @run main TestDialogTypeAhead
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    39
public class TestDialogTypeAhead {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    //Declare things used in the test, like buttons and labels here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static Frame f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static Button b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static Dialog d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static Button ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static Semaphore pressSema = new Semaphore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static Semaphore robotSema = new Semaphore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static volatile boolean gotFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static Robot robot;
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    49
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    50
    public static void main(final String[] args) {
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    51
        TestDialogTypeAhead app = new TestDialogTypeAhead();
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    52
        app.init();
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    53
        app.start();
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    54
    }
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                public void eventDispatched(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    System.err.println(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            }, AWTEvent.KEY_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
4368
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
    64
        KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
    65
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        f = new Frame("frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        b = new Button("press");
4368
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
    68
        d = new Dialog(f, "dialog", true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        ok = new Button("ok");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        d.add(ok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        d.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        ok.addKeyListener(new KeyAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    System.err.println("OK pressed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    d.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    f.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    // Typed-ahead key events should only be accepted if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    // they arrive after FOCUS_GAINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    if (gotFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                        pressSema.raise();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        ok.addFocusListener(new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    gotFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    System.err.println("Ok got focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        f.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        f.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        b.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    System.err.println("B pressed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                waitTillShown(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                TestDialogTypeAhead.this.d.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                TestDialogTypeAhead.this.moveMouseOver(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    d.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }//End  init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void start ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new RuntimeException("Can't create robot:" + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
54231
e4813eded7cb 8213110: Remove the use of applets in automatic tests
serb
parents: 50834
diff changeset
   118
        f.setLocationRelativeTo(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        f.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        waitTillShown(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        System.err.println("b is shown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        f.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        moveMouseOver(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        waitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        makeFocused(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        waitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        System.err.println("b is focused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        robot.keyPress(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        robot.keyRelease(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            robotSema.doWait(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            throw new RuntimeException("Interrupted!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
4368
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   136
        if (!robotSema.getState()) {
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   137
            throw new RuntimeException("robotSema hasn't been triggered");
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   138
        }
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   139
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   140
        System.err.println("typing ahead");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        robot.keyPress(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        robot.keyRelease(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        waitForIdle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            pressSema.doWait(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new RuntimeException("Interrupted!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (!pressSema.getState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw new RuntimeException("Type-ahead doesn't work");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }// start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private void moveMouseOver(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        Point p = c.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Dimension d = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private void waitForIdle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        try {
29731
33a67f0e4374 8074807: Fix some tests unnecessary using internal API
yan
parents: 5506
diff changeset
   162
            robot.waitForIdle();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            EventQueue.invokeAndWait( new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                // dummy implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                        } );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        } catch(InterruptedException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            ite.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } catch(InvocationTargetException ine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            System.err.println("Robot.waitForIdle, non-fatal exception caught:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            ine.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private void waitTillShown(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                c.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                ie.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private void makeFocused(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (comp.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        final Semaphore sema = new Semaphore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        final FocusAdapter fa = new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                public void focusGained(FocusEvent fe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    sema.raise();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        comp.addFocusListener(fa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (comp.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            sema.doWait(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (InterruptedException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            ie.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        comp.removeFocusListener(fa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (!comp.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new RuntimeException("Can't make " + comp + " focused, current owner is " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
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
    static class Semaphore {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        boolean state = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int waiting = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public Semaphore() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        public synchronized void doWait() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            waiting++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            waiting--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        public synchronized void doWait(int timeout) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            waiting++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            waiting--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        public synchronized void raise() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            state = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (waiting > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        public synchronized boolean getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
4368
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   248
    class TestKFM extends DefaultKeyboardFocusManager {
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   249
        protected synchronized void enqueueKeyEvents(long after,
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   250
                                                     Component untilFocused)
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   251
        {
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   252
            super.enqueueKeyEvents(after, untilFocused);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
4368
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   254
            if (untilFocused == TestDialogTypeAhead.this.ok) {
84218580baac 6566375: PIT : test/java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html
ant
parents: 2
diff changeset
   255
                TestDialogTypeAhead.this.robotSema.raise();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}// class TestDialogTypeAhead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260