author | mdoerr |
Tue, 12 Nov 2019 16:13:16 +0100 | |
changeset 59032 | ad05ed6f2a77 |
parent 50656 | 362e45aeb983 |
permissions | -rw-r--r-- |
50656
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
1 |
/* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
4 |
* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
10 |
* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
15 |
* accompanied this code). |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
16 |
* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
20 |
* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
23 |
* questions. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
24 |
*/ |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
25 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
26 |
package jdk.swing.interop; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
27 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
28 |
import java.awt.Toolkit; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
29 |
import java.awt.Window; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
30 |
import java.awt.AWTEvent; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
31 |
import sun.awt.SunToolkit; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
32 |
import sun.awt.AppContext; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
33 |
import sun.awt.UngrabEvent; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
34 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
35 |
/** |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
36 |
* This class provides static utility methods to be used by FX swing interop |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
37 |
* to access and use jdk internal classes like SunToolkit, AppContext |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
38 |
* and UngrabEvent. |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
39 |
* |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
40 |
* @since 11 |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
41 |
*/ |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
42 |
public class SwingInterOpUtils { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
43 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
44 |
public static void postEvent(Object target, java.awt.AWTEvent e) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
45 |
AppContext context = SunToolkit.targetToAppContext(target); |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
46 |
if (context != null) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
47 |
SunToolkit.postEvent(context, e); |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
48 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
49 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
50 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
51 |
public static void grab(Toolkit toolkit, Window window) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
52 |
if (toolkit instanceof SunToolkit) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
53 |
((SunToolkit)toolkit).grab(window); |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
54 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
55 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
56 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
57 |
public static void ungrab(Toolkit toolkit, Window window) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
58 |
if (toolkit instanceof SunToolkit) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
59 |
((SunToolkit)toolkit).ungrab(window); |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
60 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
61 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
62 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
63 |
public static boolean isUngrabEvent(AWTEvent e) { |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
64 |
return e instanceof UngrabEvent; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
65 |
} |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
66 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
67 |
public static final int GRAB_EVENT_MASK = SunToolkit.GRAB_EVENT_MASK; |
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
68 |
|
362e45aeb983
8202199: Provide public, unsupported JDK API for JavaFX/Swing interop
psadhukhan
parents:
diff
changeset
|
69 |
} |