author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 44149 | jdk/src/java.desktop/share/classes/sun/awt/SunToolkit.java@92b8963f6498 |
child 47384 | 3b244a98d5ab |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36903 | 2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt; |
|
27 |
||
28 |
import java.awt.*; |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
29 |
import java.awt.event.InputEvent; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
30 |
import java.awt.event.KeyEvent; |
2 | 31 |
import java.awt.event.WindowEvent; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
32 |
import java.awt.image.BufferedImage; |
44149
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
33 |
import java.awt.image.ColorModel; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
34 |
import java.awt.image.DataBuffer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
35 |
import java.awt.image.DataBufferInt; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
36 |
import java.awt.image.ImageObserver; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
37 |
import java.awt.image.ImageProducer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
38 |
import java.awt.image.Raster; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
39 |
import java.awt.peer.FramePeer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
40 |
import java.awt.peer.KeyboardFocusManagerPeer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
41 |
import java.awt.peer.MouseInfoPeer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
42 |
import java.awt.peer.SystemTrayPeer; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
43 |
import java.awt.peer.TrayIconPeer; |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
44 |
import java.io.File; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
45 |
import java.io.IOException; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
46 |
import java.io.InputStream; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
47 |
import java.lang.reflect.InvocationTargetException; |
2 | 48 |
import java.net.URL; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
49 |
import java.security.AccessController; |
41395
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
50 |
import java.util.ArrayList; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
51 |
import java.util.Collections; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
52 |
import java.util.Iterator; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
53 |
import java.util.Locale; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
54 |
import java.util.Map; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
55 |
import java.util.Vector; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
56 |
import java.util.WeakHashMap; |
2 | 57 |
import java.util.concurrent.TimeUnit; |
58 |
import java.util.concurrent.locks.Condition; |
|
59 |
import java.util.concurrent.locks.ReentrantLock; |
|
12529
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
60 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
61 |
import sun.awt.im.InputContext; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
62 |
import sun.awt.image.ByteArrayImageSource; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
63 |
import sun.awt.image.FileImageSource; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
64 |
import sun.awt.image.ImageRepresentation; |
32682
6f1200d8999d
8029339: Custom MultiResolution image support on HiDPI displays
alexsch
parents:
32486
diff
changeset
|
65 |
import java.awt.image.MultiResolutionImage; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
66 |
import sun.awt.image.MultiResolutionToolkitImage; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
67 |
import sun.awt.image.ToolkitImage; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
68 |
import sun.awt.image.URLImageSource; |
2 | 69 |
import sun.font.FontDesignMetrics; |
31716
6617d14f647d
8033530: [regression] Applet fails to load resources or connect back to server under some scenarios
dtitov
parents:
31447
diff
changeset
|
70 |
import sun.net.util.URLUtil; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
71 |
import sun.security.action.GetBooleanAction; |
2 | 72 |
import sun.security.action.GetPropertyAction; |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
73 |
import sun.util.logging.PlatformLogger; |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
74 |
|
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
75 |
import static java.awt.RenderingHints.*; |
2 | 76 |
|
77 |
public abstract class SunToolkit extends Toolkit |
|
25554 | 78 |
implements ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider { |
2 | 79 |
|
18271
228440e64512
8014718: Netbeans IDE begins to throw a lot exceptions since 7u25 b10
leonidr
parents:
18247
diff
changeset
|
80 |
// 8014718: logging has been removed from SunToolkit |
2 | 81 |
|
82 |
/* Load debug settings for native code */ |
|
83 |
static { |
|
84 |
if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.nativedebug"))) { |
|
85 |
DebugSettings.init(); |
|
86 |
} |
|
87 |
}; |
|
88 |
||
89 |
/** |
|
90 |
* Special mask for the UngrabEvent events, in addition to the |
|
91 |
* public masks defined in AWTEvent. Should be used as the mask |
|
92 |
* value for Toolkit.addAWTEventListener. |
|
93 |
*/ |
|
94 |
public static final int GRAB_EVENT_MASK = 0x80000000; |
|
95 |
||
96 |
/* The key to put()/get() the PostEventQueue into/from the AppContext. |
|
97 |
*/ |
|
98 |
private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue"; |
|
99 |
||
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
100 |
/** |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
101 |
* Number of buttons. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
102 |
* By default it's taken from the system. If system value does not |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
103 |
* fit into int type range, use our own MAX_BUTTONS_SUPPORT value. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
104 |
*/ |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
105 |
protected static int numberOfButtons = 0; |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
106 |
|
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
107 |
|
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
108 |
/* XFree standard mention 24 buttons as maximum: |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
109 |
* http://www.xfree86.org/current/mouse.4.html |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
110 |
* We workaround systems supporting more than 24 buttons. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
111 |
* Otherwise, we have to use long type values as masks |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
112 |
* which leads to API change. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
113 |
* InputEvent.BUTTON_DOWN_MASK may contain only 21 masks due to |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
114 |
* the 4-bytes limit for the int type. (CR 6799099) |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
115 |
* One more bit is reserved for FIRST_HIGH_BIT. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
116 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32682
diff
changeset
|
117 |
public static final int MAX_BUTTONS_SUPPORTED = 20; |
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
118 |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
119 |
/** |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
120 |
* Creates and initializes EventQueue instance for the specified |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
121 |
* AppContext. |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
122 |
* Note that event queue must be created from createNewAppContext() |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
123 |
* only in order to ensure that EventQueue constructor obtains |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
124 |
* the correct AppContext. |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
125 |
* @param appContext AppContext to associate with the event queue |
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
18202
diff
changeset
|
126 |
*/ |
11272
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
127 |
private static void initEQ(AppContext appContext) { |
32486 | 128 |
EventQueue eventQueue = new EventQueue(); |
11272
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
129 |
appContext.put(AppContext.EVENT_QUEUE_KEY, eventQueue); |
2 | 130 |
|
11272
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
131 |
PostEventQueue postEventQueue = new PostEventQueue(eventQueue); |
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
132 |
appContext.put(POST_EVENT_QUEUE_KEY, postEventQueue); |
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
133 |
} |
2 | 134 |
|
11272
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
135 |
public SunToolkit() { |
2 | 136 |
} |
137 |
||
138 |
public boolean useBufferPerWindow() { |
|
139 |
return false; |
|
140 |
} |
|
141 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
13775
diff
changeset
|
142 |
public abstract FramePeer createLightweightFrame(LightweightFrame target) |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
13775
diff
changeset
|
143 |
throws HeadlessException; |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
13775
diff
changeset
|
144 |
|
2 | 145 |
public abstract TrayIconPeer createTrayIcon(TrayIcon target) |
146 |
throws HeadlessException, AWTException; |
|
147 |
||
148 |
public abstract SystemTrayPeer createSystemTray(SystemTray target); |
|
149 |
||
150 |
public abstract boolean isTraySupported(); |
|
151 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
152 |
@Override |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13240
diff
changeset
|
153 |
public abstract KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2451
diff
changeset
|
154 |
throws HeadlessException; |
2 | 155 |
|
156 |
/** |
|
157 |
* The AWT lock is typically only used on Unix platforms to synchronize |
|
158 |
* access to Xlib, OpenGL, etc. However, these methods are implemented |
|
159 |
* in SunToolkit so that they can be called from shared code (e.g. |
|
160 |
* from the OGL pipeline) or from the X11 pipeline regardless of whether |
|
161 |
* XToolkit or MToolkit is currently in use. There are native macros |
|
162 |
* (such as AWT_LOCK) defined in awt.h, so if the implementation of these |
|
163 |
* methods is changed, make sure it is compatible with the native macros. |
|
164 |
* |
|
165 |
* Note: The following methods (awtLock(), awtUnlock(), etc) should be |
|
166 |
* used in place of: |
|
167 |
* synchronized (getAWTLock()) { |
|
168 |
* ... |
|
169 |
* } |
|
170 |
* |
|
171 |
* By factoring these methods out specially, we are able to change the |
|
172 |
* implementation of these methods (e.g. use more advanced locking |
|
173 |
* mechanisms) without impacting calling code. |
|
174 |
* |
|
175 |
* Sample usage: |
|
176 |
* private void doStuffWithXlib() { |
|
177 |
* assert !SunToolkit.isAWTLockHeldByCurrentThread(); |
|
178 |
* SunToolkit.awtLock(); |
|
179 |
* try { |
|
180 |
* ... |
|
181 |
* XlibWrapper.XDoStuff(); |
|
182 |
* } finally { |
|
183 |
* SunToolkit.awtUnlock(); |
|
184 |
* } |
|
185 |
* } |
|
186 |
*/ |
|
187 |
||
188 |
private static final ReentrantLock AWT_LOCK = new ReentrantLock(); |
|
189 |
private static final Condition AWT_LOCK_COND = AWT_LOCK.newCondition(); |
|
190 |
||
191 |
public static final void awtLock() { |
|
192 |
AWT_LOCK.lock(); |
|
193 |
} |
|
194 |
||
195 |
public static final boolean awtTryLock() { |
|
196 |
return AWT_LOCK.tryLock(); |
|
197 |
} |
|
198 |
||
199 |
public static final void awtUnlock() { |
|
200 |
AWT_LOCK.unlock(); |
|
201 |
} |
|
202 |
||
203 |
public static final void awtLockWait() |
|
204 |
throws InterruptedException |
|
205 |
{ |
|
206 |
AWT_LOCK_COND.await(); |
|
207 |
} |
|
208 |
||
209 |
public static final void awtLockWait(long timeout) |
|
210 |
throws InterruptedException |
|
211 |
{ |
|
212 |
AWT_LOCK_COND.await(timeout, TimeUnit.MILLISECONDS); |
|
213 |
} |
|
214 |
||
215 |
public static final void awtLockNotify() { |
|
216 |
AWT_LOCK_COND.signal(); |
|
217 |
} |
|
218 |
||
219 |
public static final void awtLockNotifyAll() { |
|
220 |
AWT_LOCK_COND.signalAll(); |
|
221 |
} |
|
222 |
||
223 |
public static final boolean isAWTLockHeldByCurrentThread() { |
|
224 |
return AWT_LOCK.isHeldByCurrentThread(); |
|
225 |
} |
|
226 |
||
227 |
/* |
|
228 |
* Create a new AppContext, along with its EventQueue, for a |
|
229 |
* new ThreadGroup. Browser code, for example, would use this |
|
230 |
* method to create an AppContext & EventQueue for an Applet. |
|
231 |
*/ |
|
232 |
public static AppContext createNewAppContext() { |
|
233 |
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); |
|
18202 | 234 |
return createNewAppContext(threadGroup); |
235 |
} |
|
236 |
||
237 |
static final AppContext createNewAppContext(ThreadGroup threadGroup) { |
|
6821
f5949f5159ec
6979541: closed/javax/swing/plaf/basic/AWTEventListenerLeak/AWTEventListenerLeak.java fails
art
parents:
5944
diff
changeset
|
238 |
// Create appContext before initialization of EventQueue, so all |
f5949f5159ec
6979541: closed/javax/swing/plaf/basic/AWTEventListenerLeak/AWTEventListenerLeak.java fails
art
parents:
5944
diff
changeset
|
239 |
// the calls to AppContext.getAppContext() from EventQueue ctor |
f5949f5159ec
6979541: closed/javax/swing/plaf/basic/AWTEventListenerLeak/AWTEventListenerLeak.java fails
art
parents:
5944
diff
changeset
|
240 |
// return correct values |
f5949f5159ec
6979541: closed/javax/swing/plaf/basic/AWTEventListenerLeak/AWTEventListenerLeak.java fails
art
parents:
5944
diff
changeset
|
241 |
AppContext appContext = new AppContext(threadGroup); |
11272
d890af1d95b7
7122796: SunToolkit constructor should create the EventQueue for the Main AppContext
anthony
parents:
11264
diff
changeset
|
242 |
initEQ(appContext); |
2 | 243 |
|
244 |
return appContext; |
|
245 |
} |
|
246 |
||
247 |
static void wakeupEventQueue(EventQueue q, boolean isShutdown){ |
|
13604 | 248 |
AWTAccessor.getEventQueueAccessor().wakeup(q, isShutdown); |
2 | 249 |
} |
250 |
||
251 |
/* |
|
252 |
* Fetch the peer associated with the given target (as specified |
|
253 |
* in the peer creation method). This can be used to determine |
|
254 |
* things like what the parent peer is. If the target is null |
|
255 |
* or the target can't be found (either because the a peer was |
|
256 |
* never created for it or the peer was disposed), a null will |
|
257 |
* be returned. |
|
258 |
*/ |
|
259 |
protected static Object targetToPeer(Object target) { |
|
260 |
if (target != null && !GraphicsEnvironment.isHeadless()) { |
|
261 |
return AWTAutoShutdown.getInstance().getPeer(target); |
|
262 |
} |
|
263 |
return null; |
|
264 |
} |
|
265 |
||
266 |
protected static void targetCreatedPeer(Object target, Object peer) { |
|
267 |
if (target != null && peer != null && |
|
268 |
!GraphicsEnvironment.isHeadless()) |
|
269 |
{ |
|
270 |
AWTAutoShutdown.getInstance().registerPeer(target, peer); |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
protected static void targetDisposedPeer(Object target, Object peer) { |
|
275 |
if (target != null && peer != null && |
|
276 |
!GraphicsEnvironment.isHeadless()) |
|
277 |
{ |
|
278 |
AWTAutoShutdown.getInstance().unregisterPeer(target, peer); |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
// Maps from non-Component/MenuComponent to AppContext. |
|
283 |
// WeakHashMap<Component,AppContext> |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
284 |
private static final Map<Object, AppContext> appContextMap = |
31447
a5d56b872e3a
6519182: SunToolkit.appContextMap should be IdentityMap
ssadetsky
parents:
30948
diff
changeset
|
285 |
Collections.synchronizedMap(new WeakIdentityHashMap<Object, AppContext>()); |
2 | 286 |
|
287 |
/** |
|
288 |
* Sets the appContext field of target. If target is not a Component or |
|
289 |
* MenuComponent, this returns false. |
|
290 |
*/ |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
291 |
private static boolean setAppContext(Object target, |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
292 |
AppContext context) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
293 |
if (target instanceof Component) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
294 |
AWTAccessor.getComponentAccessor(). |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
295 |
setAppContext((Component)target, context); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
296 |
} else if (target instanceof MenuComponent) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
297 |
AWTAccessor.getMenuComponentAccessor(). |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
298 |
setAppContext((MenuComponent)target, context); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
299 |
} else { |
2 | 300 |
return false; |
301 |
} |
|
302 |
return true; |
|
303 |
} |
|
304 |
||
305 |
/** |
|
306 |
* Returns the appContext field for target. If target is not a |
|
307 |
* Component or MenuComponent this returns null. |
|
308 |
*/ |
|
309 |
private static AppContext getAppContext(Object target) { |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
310 |
if (target instanceof Component) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
311 |
return AWTAccessor.getComponentAccessor(). |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
312 |
getAppContext((Component)target); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
313 |
} else if (target instanceof MenuComponent) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
314 |
return AWTAccessor.getMenuComponentAccessor(). |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
315 |
getAppContext((MenuComponent)target); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
316 |
} else { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
317 |
return null; |
2 | 318 |
} |
319 |
} |
|
320 |
||
321 |
/* |
|
322 |
* Fetch the AppContext associated with the given target. |
|
323 |
* This can be used to determine things like which EventQueue |
|
324 |
* to use for posting events to a Component. If the target is |
|
325 |
* null or the target can't be found, a null with be returned. |
|
326 |
*/ |
|
327 |
public static AppContext targetToAppContext(Object target) { |
|
26031
812d3082ba6f
8051359: JPopupMenu creation in headless mode with JDK9b23 causes NPE
alexsch
parents:
26011
diff
changeset
|
328 |
if (target == null) { |
2 | 329 |
return null; |
330 |
} |
|
331 |
AppContext context = getAppContext(target); |
|
332 |
if (context == null) { |
|
333 |
// target is not a Component/MenuComponent, try the |
|
334 |
// appContextMap. |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
335 |
context = appContextMap.get(target); |
2 | 336 |
} |
337 |
return context; |
|
338 |
} |
|
339 |
||
340 |
/** |
|
341 |
* Sets the synchronous status of focus requests on lightweight |
|
342 |
* components in the specified window to the specified value. |
|
35667 | 343 |
* If the boolean parameter is {@code true} then the focus |
2 | 344 |
* requests on lightweight components will be performed |
35667 | 345 |
* synchronously, if it is {@code false}, then asynchronously. |
2 | 346 |
* By default, all windows have their lightweight request status |
347 |
* set to asynchronous. |
|
348 |
* <p> |
|
349 |
* The application can only set the status of lightweight focus |
|
350 |
* requests to synchronous for any of its windows if it doesn't |
|
351 |
* perform focus transfers between different heavyweight containers. |
|
352 |
* In this case the observable focus behaviour is the same as with |
|
353 |
* asynchronous status. |
|
354 |
* <p> |
|
355 |
* If the application performs focus transfer between different |
|
356 |
* heavyweight containers and sets the lightweight focus request |
|
357 |
* status to synchronous for any of its windows, then further focus |
|
358 |
* behaviour is unspecified. |
|
359 |
* <p> |
|
30948
0a0972d3b58d
6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents:
30479
diff
changeset
|
360 |
* @param changed the window for which the lightweight focus request |
0a0972d3b58d
6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents:
30479
diff
changeset
|
361 |
* status should be set |
2 | 362 |
* @param status the value of lightweight focus request status |
363 |
*/ |
|
364 |
||
365 |
public static void setLWRequestStatus(Window changed,boolean status){ |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
366 |
AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status); |
2 | 367 |
}; |
368 |
||
12661
6cf8b7116579
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents:
12529
diff
changeset
|
369 |
public static void checkAndSetPolicy(Container cont) { |
6cf8b7116579
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents:
12529
diff
changeset
|
370 |
FocusTraversalPolicy defaultPolicy = KeyboardFocusManager. |
6cf8b7116579
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents:
12529
diff
changeset
|
371 |
getCurrentKeyboardFocusManager(). |
6cf8b7116579
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents:
12529
diff
changeset
|
372 |
getDefaultFocusTraversalPolicy(); |
2 | 373 |
|
374 |
cont.setFocusTraversalPolicy(defaultPolicy); |
|
375 |
} |
|
376 |
||
377 |
/* |
|
378 |
* Insert a mapping from target to AppContext, for later retrieval |
|
379 |
* via targetToAppContext() above. |
|
380 |
*/ |
|
381 |
public static void insertTargetMapping(Object target, AppContext appContext) { |
|
26031
812d3082ba6f
8051359: JPopupMenu creation in headless mode with JDK9b23 causes NPE
alexsch
parents:
26011
diff
changeset
|
382 |
if (!setAppContext(target, appContext)) { |
812d3082ba6f
8051359: JPopupMenu creation in headless mode with JDK9b23 causes NPE
alexsch
parents:
26011
diff
changeset
|
383 |
// Target is not a Component/MenuComponent, use the private Map |
812d3082ba6f
8051359: JPopupMenu creation in headless mode with JDK9b23 causes NPE
alexsch
parents:
26011
diff
changeset
|
384 |
// instead. |
812d3082ba6f
8051359: JPopupMenu creation in headless mode with JDK9b23 causes NPE
alexsch
parents:
26011
diff
changeset
|
385 |
appContextMap.put(target, appContext); |
2 | 386 |
} |
387 |
} |
|
388 |
||
389 |
/* |
|
390 |
* Post an AWTEvent to the Java EventQueue, using the PostEventQueue |
|
391 |
* to avoid possibly calling client code (EventQueueSubclass.postEvent()) |
|
392 |
* on the toolkit (AWT-Windows/AWT-Motif) thread. This function should |
|
393 |
* not be called under another lock since it locks the EventQueue. |
|
394 |
* See bugids 4632918, 4526597. |
|
395 |
*/ |
|
396 |
public static void postEvent(AppContext appContext, AWTEvent event) { |
|
397 |
if (event == null) { |
|
398 |
throw new NullPointerException(); |
|
399 |
} |
|
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
400 |
|
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
401 |
AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
402 |
if (sea != null && sea.isSequencedEvent(event)) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
403 |
AWTEvent nested = sea.getNested(event); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
404 |
if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS && |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
405 |
nested instanceof TimedWindowEvent) |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
406 |
{ |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
407 |
TimedWindowEvent twe = (TimedWindowEvent)nested; |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
408 |
((SunToolkit)Toolkit.getDefaultToolkit()). |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
409 |
setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen()); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
410 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
411 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
412 |
|
6826
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
413 |
// All events posted via this method are system-generated. |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
414 |
// Placing the following call here reduces considerably the |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
415 |
// number of places throughout the toolkit that would |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
416 |
// otherwise have to be modified to precisely identify |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
417 |
// system-generated events. |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
418 |
setSystemGenerated(event); |
2 | 419 |
AppContext eventContext = targetToAppContext(event.getSource()); |
420 |
if (eventContext != null && !eventContext.equals(appContext)) { |
|
18271
228440e64512
8014718: Netbeans IDE begins to throw a lot exceptions since 7u25 b10
leonidr
parents:
18247
diff
changeset
|
421 |
throw new RuntimeException("Event posted on wrong app context : " + event); |
2 | 422 |
} |
423 |
PostEventQueue postEventQueue = |
|
424 |
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY); |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
425 |
if (postEventQueue != null) { |
2 | 426 |
postEventQueue.postEvent(event); |
427 |
} |
|
428 |
} |
|
429 |
||
430 |
/* |
|
431 |
* Post AWTEvent of high priority. |
|
432 |
*/ |
|
433 |
public static void postPriorityEvent(final AWTEvent e) { |
|
434 |
PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
435 |
@Override |
2 | 436 |
public void run() { |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
437 |
AWTAccessor.getAWTEventAccessor().setPosted(e); |
2 | 438 |
((Component)e.getSource()).dispatchEvent(e); |
439 |
} |
|
440 |
}, PeerEvent.ULTIMATE_PRIORITY_EVENT); |
|
441 |
postEvent(targetToAppContext(e.getSource()), pe); |
|
442 |
} |
|
443 |
||
444 |
/* |
|
445 |
* Flush any pending events which haven't been posted to the AWT |
|
446 |
* EventQueue yet. |
|
447 |
*/ |
|
448 |
public static void flushPendingEvents() { |
|
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
449 |
AppContext appContext = AppContext.getAppContext(); |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
450 |
flushPendingEvents(appContext); |
2 | 451 |
} |
452 |
||
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
453 |
/* |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
454 |
* Flush the PostEventQueue for the right AppContext. |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
455 |
* The default flushPendingEvents only flushes the thread-local context, |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
456 |
* which is not always correct, c.f. 3746956 |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
457 |
*/ |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
458 |
public static void flushPendingEvents(AppContext appContext) { |
2 | 459 |
PostEventQueue postEventQueue = |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
460 |
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY); |
2 | 461 |
if (postEventQueue != null) { |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
462 |
postEventQueue.flush(); |
2 | 463 |
} |
464 |
} |
|
465 |
||
466 |
/* |
|
467 |
* Execute a chunk of code on the Java event handler thread for the |
|
468 |
* given target. Does not wait for the execution to occur before |
|
469 |
* returning to the caller. |
|
470 |
*/ |
|
471 |
public static void executeOnEventHandlerThread(Object target, |
|
472 |
Runnable runnable) { |
|
473 |
executeOnEventHandlerThread(new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT)); |
|
474 |
} |
|
475 |
||
476 |
/* |
|
477 |
* Fixed 5064013: the InvocationEvent time should be equals |
|
478 |
* the time of the ActionEvent |
|
479 |
*/ |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
480 |
@SuppressWarnings("serial") |
2 | 481 |
public static void executeOnEventHandlerThread(Object target, |
482 |
Runnable runnable, |
|
483 |
final long when) { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
484 |
executeOnEventHandlerThread( |
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
485 |
new PeerEvent(target, runnable, PeerEvent.PRIORITY_EVENT) { |
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
486 |
@Override |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
487 |
public long getWhen() { |
2 | 488 |
return when; |
489 |
} |
|
490 |
}); |
|
491 |
} |
|
492 |
||
493 |
/* |
|
494 |
* Execute a chunk of code on the Java event handler thread for the |
|
495 |
* given target. Does not wait for the execution to occur before |
|
496 |
* returning to the caller. |
|
497 |
*/ |
|
498 |
public static void executeOnEventHandlerThread(PeerEvent peerEvent) { |
|
499 |
postEvent(targetToAppContext(peerEvent.getSource()), peerEvent); |
|
500 |
} |
|
501 |
||
502 |
/* |
|
503 |
* Execute a chunk of code on the Java event handler thread. The |
|
504 |
* method takes into account provided AppContext and sets |
|
35667 | 505 |
* {@code SunToolkit.getDefaultToolkit()} as a target of the |
2 | 506 |
* event. See 6451487 for detailes. |
507 |
* Does not wait for the execution to occur before returning to |
|
508 |
* the caller. |
|
509 |
*/ |
|
510 |
public static void invokeLaterOnAppContext( |
|
511 |
AppContext appContext, Runnable dispatcher) |
|
512 |
{ |
|
513 |
postEvent(appContext, |
|
514 |
new PeerEvent(Toolkit.getDefaultToolkit(), dispatcher, |
|
515 |
PeerEvent.PRIORITY_EVENT)); |
|
516 |
} |
|
517 |
||
518 |
/* |
|
519 |
* Execute a chunk of code on the Java event handler thread for the |
|
520 |
* given target. Waits for the execution to occur before returning |
|
521 |
* to the caller. |
|
522 |
*/ |
|
523 |
public static void executeOnEDTAndWait(Object target, Runnable runnable) |
|
524 |
throws InterruptedException, InvocationTargetException |
|
525 |
{ |
|
526 |
if (EventQueue.isDispatchThread()) { |
|
527 |
throw new Error("Cannot call executeOnEDTAndWait from any event dispatcher thread"); |
|
528 |
} |
|
529 |
||
530 |
class AWTInvocationLock {} |
|
531 |
Object lock = new AWTInvocationLock(); |
|
532 |
||
533 |
PeerEvent event = new PeerEvent(target, runnable, lock, true, PeerEvent.PRIORITY_EVENT); |
|
534 |
||
535 |
synchronized (lock) { |
|
536 |
executeOnEventHandlerThread(event); |
|
7955
4faac2af1f6e
7011443: ./share/classes/sun/awt/SunToolkit.java needs to avoid spurious wakeup
dcherepanov
parents:
7775
diff
changeset
|
537 |
while(!event.isDispatched()) { |
4faac2af1f6e
7011443: ./share/classes/sun/awt/SunToolkit.java needs to avoid spurious wakeup
dcherepanov
parents:
7775
diff
changeset
|
538 |
lock.wait(); |
4faac2af1f6e
7011443: ./share/classes/sun/awt/SunToolkit.java needs to avoid spurious wakeup
dcherepanov
parents:
7775
diff
changeset
|
539 |
} |
2 | 540 |
} |
541 |
||
542 |
Throwable eventThrowable = event.getThrowable(); |
|
543 |
if (eventThrowable != null) { |
|
544 |
throw new InvocationTargetException(eventThrowable); |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
/* |
|
549 |
* Returns true if the calling thread is the event dispatch thread |
|
550 |
* contained within AppContext which associated with the given target. |
|
551 |
* Use this call to ensure that a given task is being executed |
|
552 |
* (or not being) on the event dispatch thread for the given target. |
|
553 |
*/ |
|
554 |
public static boolean isDispatchThreadForAppContext(Object target) { |
|
555 |
AppContext appContext = targetToAppContext(target); |
|
556 |
EventQueue eq = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); |
|
557 |
||
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
558 |
AWTAccessor.EventQueueAccessor accessor = AWTAccessor.getEventQueueAccessor(); |
4365 | 559 |
return accessor.isDispatchThreadImpl(eq); |
2 | 560 |
} |
561 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
562 |
@Override |
2 | 563 |
public Dimension getScreenSize() { |
44149
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
564 |
return GraphicsEnvironment.getLocalGraphicsEnvironment() |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
565 |
.getDefaultScreenDevice().getDefaultConfiguration() |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
566 |
.getBounds().getSize(); |
2 | 567 |
} |
44149
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
568 |
|
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
569 |
@Override |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
570 |
public ColorModel getColorModel() throws HeadlessException { |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
571 |
return GraphicsEnvironment.getLocalGraphicsEnvironment() |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
572 |
.getDefaultScreenDevice().getDefaultConfiguration() |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
573 |
.getColorModel(); |
92b8963f6498
8168307: Toolkit.getScreenSize() returns incorrect size on unix in multiscreen systems
serb
parents:
43722
diff
changeset
|
574 |
} |
2 | 575 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
576 |
@Override |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
577 |
@SuppressWarnings("deprecation") |
2 | 578 |
public FontMetrics getFontMetrics(Font font) { |
579 |
return FontDesignMetrics.getMetrics(font); |
|
580 |
} |
|
581 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
582 |
@Override |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
583 |
@SuppressWarnings("deprecation") |
2 | 584 |
public String[] getFontList() { |
585 |
String[] hardwiredFontList = { |
|
586 |
Font.DIALOG, Font.SANS_SERIF, Font.SERIF, Font.MONOSPACED, |
|
587 |
Font.DIALOG_INPUT |
|
588 |
||
589 |
// -- Obsolete font names from 1.0.2. It was decided that |
|
590 |
// -- getFontList should not return these old names: |
|
591 |
// "Helvetica", "TimesRoman", "Courier", "ZapfDingbats" |
|
592 |
}; |
|
593 |
return hardwiredFontList; |
|
594 |
} |
|
595 |
||
596 |
/** |
|
2451 | 597 |
* Disables erasing of background on the canvas before painting if |
598 |
* this is supported by the current toolkit. It is recommended to |
|
599 |
* call this method early, before the Canvas becomes displayable, |
|
600 |
* because some Toolkit implementations do not support changing |
|
601 |
* this property once the Canvas becomes displayable. |
|
2 | 602 |
*/ |
603 |
public void disableBackgroundErase(Canvas canvas) { |
|
2451 | 604 |
disableBackgroundEraseImpl(canvas); |
605 |
} |
|
606 |
||
607 |
/** |
|
608 |
* Disables the native erasing of the background on the given |
|
609 |
* component before painting if this is supported by the current |
|
610 |
* toolkit. This only has an effect for certain components such as |
|
611 |
* Canvas, Panel and Window. It is recommended to call this method |
|
612 |
* early, before the Component becomes displayable, because some |
|
613 |
* Toolkit implementations do not support changing this property |
|
614 |
* once the Component becomes displayable. |
|
615 |
*/ |
|
616 |
public void disableBackgroundErase(Component component) { |
|
617 |
disableBackgroundEraseImpl(component); |
|
618 |
} |
|
619 |
||
620 |
private void disableBackgroundEraseImpl(Component component) { |
|
621 |
AWTAccessor.getComponentAccessor().setBackgroundEraseDisabled(component, true); |
|
2 | 622 |
} |
623 |
||
624 |
/** |
|
625 |
* Returns the value of "sun.awt.noerasebackground" property. Default |
|
626 |
* value is {@code false}. |
|
627 |
*/ |
|
628 |
public static boolean getSunAwtNoerasebackground() { |
|
629 |
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.noerasebackground")); |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Returns the value of "sun.awt.erasebackgroundonresize" property. Default |
|
634 |
* value is {@code false}. |
|
635 |
*/ |
|
636 |
public static boolean getSunAwtErasebackgroundonresize() { |
|
637 |
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize")); |
|
638 |
} |
|
639 |
||
1190
f27065d0d9f0
6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents:
1181
diff
changeset
|
640 |
|
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
27715
diff
changeset
|
641 |
@SuppressWarnings("deprecation") |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
642 |
static final SoftCache fileImgCache = new SoftCache(); |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
643 |
|
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
644 |
@SuppressWarnings("deprecation") |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
645 |
static final SoftCache urlImgCache = new SoftCache(); |
2 | 646 |
|
4369
18b883ed2b58
6903354: deadlock involving Component.show & SunToolkit.getImageFromHash
ant
parents:
4366
diff
changeset
|
647 |
static Image getImageFromHash(Toolkit tk, URL url) { |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
648 |
checkPermissions(url); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
649 |
synchronized (urlImgCache) { |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
650 |
String key = url.toString(); |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
651 |
Image img = (Image)urlImgCache.get(key); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
652 |
if (img == null) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
653 |
try { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
654 |
img = tk.createImage(new URLImageSource(url)); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
655 |
urlImgCache.put(key, img); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
656 |
} catch (Exception e) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
657 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
658 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
659 |
return img; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
660 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
661 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
662 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
663 |
static Image getImageFromHash(Toolkit tk, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
664 |
String filename) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
665 |
checkPermissions(filename); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
666 |
synchronized (fileImgCache) { |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
667 |
Image img = (Image)fileImgCache.get(filename); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
668 |
if (img == null) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
669 |
try { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
670 |
img = tk.createImage(new FileImageSource(filename)); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
671 |
fileImgCache.put(filename, img); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
672 |
} catch (Exception e) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
673 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
674 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
675 |
return img; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
676 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
677 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
678 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
679 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
680 |
public Image getImage(String filename) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
681 |
return getImageFromHash(this, filename); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
682 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
683 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
684 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
685 |
public Image getImage(URL url) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
686 |
return getImageFromHash(this, url); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
687 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
688 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
689 |
protected Image getImageWithResolutionVariant(String fileName, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
690 |
String resolutionVariantName) { |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
691 |
synchronized (fileImgCache) { |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
692 |
Image image = getImageFromHash(this, fileName); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
693 |
if (image instanceof MultiResolutionImage) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
694 |
return image; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
695 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
696 |
Image resolutionVariant = getImageFromHash(this, resolutionVariantName); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
697 |
image = createImageWithResolutionVariant(image, resolutionVariant); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
698 |
fileImgCache.put(fileName, image); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
699 |
return image; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
700 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
701 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
702 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
703 |
protected Image getImageWithResolutionVariant(URL url, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
704 |
URL resolutionVariantURL) { |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
705 |
synchronized (urlImgCache) { |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
706 |
Image image = getImageFromHash(this, url); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
707 |
if (image instanceof MultiResolutionImage) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
708 |
return image; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
709 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
710 |
Image resolutionVariant = getImageFromHash(this, resolutionVariantURL); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
711 |
image = createImageWithResolutionVariant(image, resolutionVariant); |
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
712 |
String key = url.toString(); |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
713 |
urlImgCache.put(key, image); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
714 |
return image; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
715 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
716 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
717 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
718 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
719 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
720 |
public Image createImage(String filename) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
721 |
checkPermissions(filename); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
722 |
return createImage(new FileImageSource(filename)); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
723 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
724 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
725 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
726 |
public Image createImage(URL url) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
727 |
checkPermissions(url); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
728 |
return createImage(new URLImageSource(url)); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
729 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
730 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
731 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
732 |
public Image createImage(byte[] data, int offset, int length) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
733 |
return createImage(new ByteArrayImageSource(data, offset, length)); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
734 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
735 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
736 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
737 |
public Image createImage(ImageProducer producer) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
738 |
return new ToolkitImage(producer); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
739 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
740 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
741 |
public static Image createImageWithResolutionVariant(Image image, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
742 |
Image resolutionVariant) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
743 |
return new MultiResolutionToolkitImage(image, resolutionVariant); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
744 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
745 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
746 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
747 |
public int checkImage(Image img, int w, int h, ImageObserver o) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
748 |
if (!(img instanceof ToolkitImage)) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
749 |
return ImageObserver.ALLBITS; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
750 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
751 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
752 |
ToolkitImage tkimg = (ToolkitImage)img; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
753 |
int repbits; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
754 |
if (w == 0 || h == 0) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
755 |
repbits = ImageObserver.ALLBITS; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
756 |
} else { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
757 |
repbits = tkimg.getImageRep().check(o); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
758 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
759 |
return (tkimg.check(o) | repbits) & checkResolutionVariant(img, w, h, o); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
760 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
761 |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
762 |
@Override |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
763 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
764 |
if (w == 0 || h == 0) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
765 |
return true; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
766 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
767 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
768 |
// Must be a ToolkitImage |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
769 |
if (!(img instanceof ToolkitImage)) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
770 |
return true; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
771 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
772 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
773 |
ToolkitImage tkimg = (ToolkitImage)img; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
774 |
if (tkimg.hasError()) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
775 |
if (o != null) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
776 |
o.imageUpdate(img, ImageObserver.ERROR|ImageObserver.ABORT, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
777 |
-1, -1, -1, -1); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
778 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
779 |
return false; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
780 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
781 |
ImageRepresentation ir = tkimg.getImageRep(); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
782 |
return ir.prepare(o) & prepareResolutionVariant(img, w, h, o); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
783 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
784 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
785 |
private int checkResolutionVariant(Image img, int w, int h, ImageObserver o) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
786 |
ToolkitImage rvImage = getResolutionVariant(img); |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
787 |
int rvw = getRVSize(w); |
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
788 |
int rvh = getRVSize(h); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
789 |
// Ignore the resolution variant in case of error |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
790 |
return (rvImage == null || rvImage.hasError()) ? 0xFFFF : |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
791 |
checkImage(rvImage, rvw, rvh, MultiResolutionToolkitImage. |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
792 |
getResolutionVariantObserver( |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
793 |
img, o, w, h, rvw, rvh, true)); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
794 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
795 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
796 |
private boolean prepareResolutionVariant(Image img, int w, int h, |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
797 |
ImageObserver o) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
798 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
799 |
ToolkitImage rvImage = getResolutionVariant(img); |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
800 |
int rvw = getRVSize(w); |
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
801 |
int rvh = getRVSize(h); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
802 |
// Ignore the resolution variant in case of error |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
803 |
return rvImage == null || rvImage.hasError() || prepareImage( |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
804 |
rvImage, rvw, rvh, |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
805 |
MultiResolutionToolkitImage.getResolutionVariantObserver( |
25107
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
806 |
img, o, w, h, rvw, rvh, true)); |
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
807 |
} |
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
808 |
|
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
809 |
private static int getRVSize(int size){ |
9a16a601de25
8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents:
24538
diff
changeset
|
810 |
return size == -1 ? -1 : 2 * size; |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
811 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
812 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
813 |
private static ToolkitImage getResolutionVariant(Image image) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
814 |
if (image instanceof MultiResolutionToolkitImage) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
815 |
Image resolutionVariant = ((MultiResolutionToolkitImage) image). |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
816 |
getResolutionVariant(); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
817 |
if (resolutionVariant instanceof ToolkitImage) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
818 |
return (ToolkitImage) resolutionVariant; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
819 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
820 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
821 |
return null; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
822 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
823 |
|
33284
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
824 |
protected static boolean imageCached(String fileName) { |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
825 |
return fileImgCache.containsKey(fileName); |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
826 |
} |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
827 |
|
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
828 |
protected static boolean imageCached(URL url) { |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
829 |
String key = url.toString(); |
dd3488738c7a
8080246: JNLP app cannot be launched due to deadlock
dtitov
parents:
32865
diff
changeset
|
830 |
return urlImgCache.containsKey(key); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
831 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
832 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
833 |
protected static boolean imageExists(String filename) { |
30479
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
834 |
if (filename != null) { |
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
835 |
checkPermissions(filename); |
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
836 |
return new File(filename).exists(); |
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
837 |
} |
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
838 |
return false; |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
839 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
840 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
841 |
@SuppressWarnings("try") |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
842 |
protected static boolean imageExists(URL url) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
843 |
if (url != null) { |
30479
09cccadb5831
8078165: [macosx] NPE when attempting to get image from toolkit
anashaty
parents:
30471
diff
changeset
|
844 |
checkPermissions(url); |
23256
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
845 |
try (InputStream is = url.openStream()) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
846 |
return true; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
847 |
}catch(IOException e){ |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
848 |
return false; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
849 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
850 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
851 |
return false; |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
852 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
853 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
854 |
private static void checkPermissions(String filename) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
855 |
SecurityManager security = System.getSecurityManager(); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
856 |
if (security != null) { |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
857 |
security.checkRead(filename); |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
858 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
859 |
} |
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
860 |
|
d71287a532f8
8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents:
18275
diff
changeset
|
861 |
private static void checkPermissions(URL url) { |
2 | 862 |
SecurityManager sm = System.getSecurityManager(); |
863 |
if (sm != null) { |
|
864 |
try { |
|
865 |
java.security.Permission perm = |
|
31716
6617d14f647d
8033530: [regression] Applet fails to load resources or connect back to server under some scenarios
dtitov
parents:
31447
diff
changeset
|
866 |
URLUtil.getConnectPermission(url); |
2 | 867 |
if (perm != null) { |
868 |
try { |
|
869 |
sm.checkPermission(perm); |
|
870 |
} catch (SecurityException se) { |
|
871 |
// fallback to checkRead/checkConnect for pre 1.2 |
|
872 |
// security managers |
|
873 |
if ((perm instanceof java.io.FilePermission) && |
|
874 |
perm.getActions().indexOf("read") != -1) { |
|
875 |
sm.checkRead(perm.getName()); |
|
876 |
} else if ((perm instanceof |
|
877 |
java.net.SocketPermission) && |
|
878 |
perm.getActions().indexOf("connect") != -1) { |
|
879 |
sm.checkConnect(url.getHost(), url.getPort()); |
|
880 |
} else { |
|
881 |
throw se; |
|
882 |
} |
|
883 |
} |
|
884 |
} |
|
885 |
} catch (java.io.IOException ioe) { |
|
886 |
sm.checkConnect(url.getHost(), url.getPort()); |
|
887 |
} |
|
888 |
} |
|
889 |
} |
|
890 |
||
891 |
/** |
|
892 |
* Scans {@code imageList} for best-looking image of specified dimensions. |
|
893 |
* Image can be scaled and/or padded with transparency. |
|
894 |
*/ |
|
895 |
public static BufferedImage getScaledIconImage(java.util.List<Image> imageList, int width, int height) { |
|
896 |
if (width == 0 || height == 0) { |
|
897 |
return null; |
|
898 |
} |
|
41395
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
899 |
java.util.List<Image> multiResAndnormalImages = new ArrayList<>(imageList.size()); |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
900 |
for (Image image : imageList) { |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
901 |
if ((image instanceof MultiResolutionImage)) { |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
902 |
Image im = ((MultiResolutionImage) image).getResolutionVariant(width, height); |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
903 |
multiResAndnormalImages.add(im); |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
904 |
} else { |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
905 |
multiResAndnormalImages.add(image); |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
906 |
} |
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
907 |
} |
2 | 908 |
Image bestImage = null; |
909 |
int bestWidth = 0; |
|
910 |
int bestHeight = 0; |
|
911 |
double bestSimilarity = 3; //Impossibly high value |
|
912 |
double bestScaleFactor = 0; |
|
41395
2a6f7eb1dc23
8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents:
40719
diff
changeset
|
913 |
for (Iterator<Image> i = multiResAndnormalImages.iterator();i.hasNext();) { |
2 | 914 |
//Iterate imageList looking for best matching image. |
915 |
//'Similarity' measure is defined as good scale factor and small insets. |
|
916 |
//best possible similarity is 0 (no scale, no insets). |
|
917 |
//It's found while the experiments that good-looking result is achieved |
|
918 |
//with scale factors x1, x3/4, x2/3, xN, x1/N. |
|
919 |
Image im = i.next(); |
|
920 |
if (im == null) { |
|
921 |
continue; |
|
922 |
} |
|
923 |
if (im instanceof ToolkitImage) { |
|
924 |
ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); |
|
925 |
ir.reconstruct(ImageObserver.ALLBITS); |
|
926 |
} |
|
927 |
int iw; |
|
928 |
int ih; |
|
929 |
try { |
|
930 |
iw = im.getWidth(null); |
|
931 |
ih = im.getHeight(null); |
|
932 |
} catch (Exception e){ |
|
933 |
continue; |
|
934 |
} |
|
935 |
if (iw > 0 && ih > 0) { |
|
936 |
//Calc scale factor |
|
937 |
double scaleFactor = Math.min((double)width / (double)iw, |
|
938 |
(double)height / (double)ih); |
|
939 |
//Calculate scaled image dimensions |
|
940 |
//adjusting scale factor to nearest "good" value |
|
941 |
int adjw = 0; |
|
942 |
int adjh = 0; |
|
943 |
double scaleMeasure = 1; //0 - best (no) scale, 1 - impossibly bad |
|
944 |
if (scaleFactor >= 2) { |
|
945 |
//Need to enlarge image more than twice |
|
946 |
//Round down scale factor to multiply by integer value |
|
947 |
scaleFactor = Math.floor(scaleFactor); |
|
948 |
adjw = iw * (int)scaleFactor; |
|
949 |
adjh = ih * (int)scaleFactor; |
|
950 |
scaleMeasure = 1.0 - 0.5 / scaleFactor; |
|
951 |
} else if (scaleFactor >= 1) { |
|
952 |
//Don't scale |
|
953 |
scaleFactor = 1.0; |
|
954 |
adjw = iw; |
|
955 |
adjh = ih; |
|
956 |
scaleMeasure = 0; |
|
957 |
} else if (scaleFactor >= 0.75) { |
|
958 |
//Multiply by 3/4 |
|
959 |
scaleFactor = 0.75; |
|
960 |
adjw = iw * 3 / 4; |
|
961 |
adjh = ih * 3 / 4; |
|
962 |
scaleMeasure = 0.3; |
|
963 |
} else if (scaleFactor >= 0.6666) { |
|
964 |
//Multiply by 2/3 |
|
965 |
scaleFactor = 0.6666; |
|
966 |
adjw = iw * 2 / 3; |
|
967 |
adjh = ih * 2 / 3; |
|
968 |
scaleMeasure = 0.33; |
|
969 |
} else { |
|
970 |
//Multiply size by 1/scaleDivider |
|
971 |
//where scaleDivider is minimum possible integer |
|
972 |
//larger than 1/scaleFactor |
|
973 |
double scaleDivider = Math.ceil(1.0 / scaleFactor); |
|
974 |
scaleFactor = 1.0 / scaleDivider; |
|
975 |
adjw = (int)Math.round((double)iw / scaleDivider); |
|
976 |
adjh = (int)Math.round((double)ih / scaleDivider); |
|
977 |
scaleMeasure = 1.0 - 1.0 / scaleDivider; |
|
978 |
} |
|
979 |
double similarity = ((double)width - (double)adjw) / (double)width + |
|
980 |
((double)height - (double)adjh) / (double)height + //Large padding is bad |
|
981 |
scaleMeasure; //Large rescale is bad |
|
982 |
if (similarity < bestSimilarity) { |
|
983 |
bestSimilarity = similarity; |
|
984 |
bestScaleFactor = scaleFactor; |
|
985 |
bestImage = im; |
|
986 |
bestWidth = adjw; |
|
987 |
bestHeight = adjh; |
|
988 |
} |
|
989 |
if (similarity == 0) break; |
|
990 |
} |
|
991 |
} |
|
992 |
if (bestImage == null) { |
|
993 |
//No images were found, possibly all are broken |
|
994 |
return null; |
|
995 |
} |
|
996 |
BufferedImage bimage = |
|
997 |
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
|
998 |
Graphics2D g = bimage.createGraphics(); |
|
999 |
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
|
1000 |
RenderingHints.VALUE_INTERPOLATION_BILINEAR); |
|
1001 |
try { |
|
1002 |
int x = (width - bestWidth) / 2; |
|
1003 |
int y = (height - bestHeight) / 2; |
|
1004 |
g.drawImage(bestImage, x, y, bestWidth, bestHeight, null); |
|
1005 |
} finally { |
|
1006 |
g.dispose(); |
|
1007 |
} |
|
1008 |
return bimage; |
|
1009 |
} |
|
1010 |
||
1011 |
public static DataBufferInt getScaledIconData(java.util.List<Image> imageList, int width, int height) { |
|
1012 |
BufferedImage bimage = getScaledIconImage(imageList, width, height); |
|
1013 |
if (bimage == null) { |
|
1014 |
return null; |
|
1015 |
} |
|
1016 |
Raster raster = bimage.getRaster(); |
|
1017 |
DataBuffer buffer = raster.getDataBuffer(); |
|
1018 |
return (DataBufferInt)buffer; |
|
1019 |
} |
|
1020 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1021 |
@Override |
2 | 1022 |
protected EventQueue getSystemEventQueueImpl() { |
1023 |
return getSystemEventQueueImplPP(); |
|
1024 |
} |
|
1025 |
||
1026 |
// Package private implementation |
|
1027 |
static EventQueue getSystemEventQueueImplPP() { |
|
1028 |
return getSystemEventQueueImplPP(AppContext.getAppContext()); |
|
1029 |
} |
|
1030 |
||
1031 |
public static EventQueue getSystemEventQueueImplPP(AppContext appContext) { |
|
1032 |
EventQueue theEventQueue = |
|
1033 |
(EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY); |
|
1034 |
return theEventQueue; |
|
1035 |
} |
|
1036 |
||
1037 |
/** |
|
1038 |
* Give native peers the ability to query the native container |
|
1039 |
* given a native component (eg the direct parent may be lightweight). |
|
1040 |
*/ |
|
1041 |
public static Container getNativeContainer(Component c) { |
|
1042 |
return Toolkit.getNativeContainer(c); |
|
1043 |
} |
|
1044 |
||
1045 |
/** |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1046 |
* Gives native peers the ability to query the closest HW component. |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1047 |
* If the given component is heavyweight, then it returns this. Otherwise, |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1048 |
* it goes one level up in the hierarchy and tests next component. |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1049 |
*/ |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1050 |
public static Component getHeavyweightComponent(Component c) { |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1051 |
while (c != null && AWTAccessor.getComponentAccessor().isLightweight(c)) { |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1052 |
c = AWTAccessor.getComponentAccessor().getParent(c); |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1053 |
} |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1054 |
return c; |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1055 |
} |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1056 |
|
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4369
diff
changeset
|
1057 |
/** |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1058 |
* Returns key modifiers used by Swing to set up a focus accelerator key stroke. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1059 |
*/ |
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
42739
diff
changeset
|
1060 |
@SuppressWarnings("deprecation") |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1061 |
public int getFocusAcceleratorKeyMask() { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1062 |
return InputEvent.ALT_MASK; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1063 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1064 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11272
diff
changeset
|
1065 |
/** |
12418
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1066 |
* Tests whether specified key modifiers mask can be used to enter a printable |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1067 |
* character. This is a default implementation of this method, which reflects |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1068 |
* the way things work on Windows: here, pressing ctrl + alt allows user to enter |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1069 |
* characters from the extended character set (like euro sign or math symbols) |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1070 |
*/ |
43722
25ba19c20260
8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents:
42739
diff
changeset
|
1071 |
@SuppressWarnings("deprecation") |
12418
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1072 |
public boolean isPrintableCharacterModifiersMask(int mods) { |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1073 |
return ((mods & InputEvent.ALT_MASK) == (mods & InputEvent.CTRL_MASK)); |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1074 |
} |
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1075 |
|
f749f1ed92ca
7124286: [macosx] Option modifier should work like AltGr as in Apple jdk
leonidr
parents:
12047
diff
changeset
|
1076 |
/** |
12529
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1077 |
* Returns whether popup is allowed to be shown above the task bar. |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1078 |
* This is a default implementation of this method, which checks |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1079 |
* corresponding security permission. |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1080 |
*/ |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1081 |
public boolean canPopupOverlapTaskBar() { |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1082 |
boolean result = true; |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1083 |
try { |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1084 |
SecurityManager sm = System.getSecurityManager(); |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1085 |
if (sm != null) { |
22060
cd4f9d7dbeda
8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents:
18275
diff
changeset
|
1086 |
sm.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION); |
12529
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1087 |
} |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1088 |
} catch (SecurityException se) { |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1089 |
// There is no permission to show popups over the task bar |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1090 |
result = false; |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1091 |
} |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1092 |
return result; |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1093 |
} |
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1094 |
|
6da056faf511
7154480: [macosx] Not all popup menu items are visible
leonidr
parents:
12418
diff
changeset
|
1095 |
/** |
2 | 1096 |
* Returns a new input method window, with behavior as specified in |
1097 |
* {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}. |
|
1098 |
* If the inputContext is not null, the window should return it from its |
|
1099 |
* getInputContext() method. The window needs to implement |
|
1100 |
* sun.awt.im.InputMethodWindow. |
|
1101 |
* <p> |
|
1102 |
* SunToolkit subclasses can override this method to return better input |
|
1103 |
* method windows. |
|
1104 |
*/ |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1105 |
@Override |
2 | 1106 |
public Window createInputMethodWindow(String title, InputContext context) { |
1107 |
return new sun.awt.im.SimpleInputMethodWindow(title, context); |
|
1108 |
} |
|
1109 |
||
1110 |
/** |
|
1111 |
* Returns whether enableInputMethods should be set to true for peered |
|
1112 |
* TextComponent instances on this platform. False by default. |
|
1113 |
*/ |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1114 |
@Override |
2 | 1115 |
public boolean enableInputMethodsForTextComponent() { |
1116 |
return false; |
|
1117 |
} |
|
1118 |
||
1119 |
private static Locale startupLocale = null; |
|
1120 |
||
1121 |
/** |
|
1122 |
* Returns the locale in which the runtime was started. |
|
1123 |
*/ |
|
1124 |
public static Locale getStartupLocale() { |
|
1125 |
if (startupLocale == null) { |
|
1126 |
String language, region, country, variant; |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1127 |
language = AccessController.doPrivileged( |
2 | 1128 |
new GetPropertyAction("user.language", "en")); |
1129 |
// for compatibility, check for old user.region property |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1130 |
region = AccessController.doPrivileged( |
2 | 1131 |
new GetPropertyAction("user.region")); |
1132 |
if (region != null) { |
|
1133 |
// region can be of form country, country_variant, or _variant |
|
1134 |
int i = region.indexOf('_'); |
|
1135 |
if (i >= 0) { |
|
1136 |
country = region.substring(0, i); |
|
1137 |
variant = region.substring(i + 1); |
|
1138 |
} else { |
|
1139 |
country = region; |
|
1140 |
variant = ""; |
|
1141 |
} |
|
1142 |
} else { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1143 |
country = AccessController.doPrivileged( |
2 | 1144 |
new GetPropertyAction("user.country", "")); |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1145 |
variant = AccessController.doPrivileged( |
2 | 1146 |
new GetPropertyAction("user.variant", "")); |
1147 |
} |
|
1148 |
startupLocale = new Locale(language, country, variant); |
|
1149 |
} |
|
1150 |
return startupLocale; |
|
1151 |
} |
|
1152 |
||
1153 |
/** |
|
1154 |
* Returns the default keyboard locale of the underlying operating system |
|
1155 |
*/ |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1156 |
@Override |
2 | 1157 |
public Locale getDefaultKeyboardLocale() { |
1158 |
return getStartupLocale(); |
|
1159 |
} |
|
1160 |
||
1161 |
/** |
|
1162 |
* Returns whether default toolkit needs the support of the xembed |
|
1163 |
* from embedding host(if any). |
|
35667 | 1164 |
* @return {@code true}, if XEmbed is needed, {@code false} otherwise |
2 | 1165 |
*/ |
1166 |
public static boolean needsXEmbed() { |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1167 |
String noxembed = AccessController. |
2 | 1168 |
doPrivileged(new GetPropertyAction("sun.awt.noxembed", "false")); |
1169 |
if ("true".equals(noxembed)) { |
|
1170 |
return false; |
|
1171 |
} |
|
1172 |
||
1173 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1174 |
if (tk instanceof SunToolkit) { |
|
1175 |
// SunToolkit descendants should override this method to specify |
|
1176 |
// concrete behavior |
|
1177 |
return ((SunToolkit)tk).needsXEmbedImpl(); |
|
1178 |
} else { |
|
1179 |
// Non-SunToolkit doubtly might support XEmbed |
|
1180 |
return false; |
|
1181 |
} |
|
1182 |
} |
|
1183 |
||
1184 |
/** |
|
1185 |
* Returns whether this toolkit needs the support of the xembed |
|
1186 |
* from embedding host(if any). |
|
35667 | 1187 |
* @return {@code true}, if XEmbed is needed, {@code false} otherwise |
2 | 1188 |
*/ |
1189 |
protected boolean needsXEmbedImpl() { |
|
1190 |
return false; |
|
1191 |
} |
|
1192 |
||
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1193 |
private static Dialog.ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE = null; |
2 | 1194 |
|
1195 |
/** |
|
1196 |
* Returns whether the XEmbed server feature is requested by |
|
1197 |
* developer. If true, Toolkit should return an |
|
1198 |
* XEmbed-server-enabled CanvasPeer instead of the ordinary CanvasPeer. |
|
1199 |
*/ |
|
1200 |
protected final boolean isXEmbedServerRequested() { |
|
1201 |
return AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembedserver")); |
|
1202 |
} |
|
1203 |
||
1204 |
/** |
|
1205 |
* Returns whether the modal exclusion API is supported by the current toolkit. |
|
35667 | 1206 |
* When it isn't supported, calling {@code setModalExcluded} has no |
1207 |
* effect, and {@code isModalExcluded} returns false for all windows. |
|
2 | 1208 |
* |
1209 |
* @return true if modal exclusion is supported by the toolkit, false otherwise |
|
1210 |
* |
|
1211 |
* @see sun.awt.SunToolkit#setModalExcluded(java.awt.Window) |
|
1212 |
* @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window) |
|
1213 |
* |
|
1214 |
* @since 1.5 |
|
1215 |
*/ |
|
1216 |
public static boolean isModalExcludedSupported() |
|
1217 |
{ |
|
1218 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1219 |
return tk.isModalExclusionTypeSupported(DEFAULT_MODAL_EXCLUSION_TYPE); |
|
1220 |
} |
|
1221 |
/* |
|
1222 |
* Default implementation for isModalExcludedSupportedImpl(), returns false. |
|
1223 |
* |
|
1224 |
* @see sun.awt.windows.WToolkit#isModalExcludeSupportedImpl |
|
1225 |
* @see sun.awt.X11.XToolkit#isModalExcludeSupportedImpl |
|
1226 |
* |
|
1227 |
* @since 1.5 |
|
1228 |
*/ |
|
1229 |
protected boolean isModalExcludedSupportedImpl() |
|
1230 |
{ |
|
1231 |
return false; |
|
1232 |
} |
|
1233 |
||
1234 |
/* |
|
1235 |
* Sets this window to be excluded from being modally blocked. When the |
|
1236 |
* toolkit supports modal exclusion and this method is called, input |
|
1237 |
* events, focus transfer and z-order will continue to work for the |
|
1238 |
* window, it's owned windows and child components, even in the |
|
1239 |
* presence of a modal dialog. |
|
35667 | 1240 |
* For details on which {@code Window}s are normally blocked |
2 | 1241 |
* by modal dialog, see {@link java.awt.Dialog}. |
1242 |
* Invoking this method when the modal exclusion API is not supported by |
|
1243 |
* the current toolkit has no effect. |
|
1244 |
* @param window Window to be marked as not modally blocked |
|
1245 |
* @see java.awt.Dialog |
|
1246 |
* @see java.awt.Dialog#setModal(boolean) |
|
1247 |
* @see sun.awt.SunToolkit#isModalExcludedSupported |
|
1248 |
* @see sun.awt.SunToolkit#isModalExcluded(java.awt.Window) |
|
1249 |
*/ |
|
1250 |
public static void setModalExcluded(Window window) |
|
1251 |
{ |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1252 |
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1253 |
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1254 |
} |
2 | 1255 |
window.setModalExclusionType(DEFAULT_MODAL_EXCLUSION_TYPE); |
1256 |
} |
|
1257 |
||
1258 |
/* |
|
1259 |
* Returns whether the specified window is blocked by modal dialogs. |
|
1260 |
* If the modal exclusion API isn't supported by the current toolkit, |
|
1261 |
* it returns false for all windows. |
|
1262 |
* |
|
1263 |
* @param window Window to test for modal exclusion |
|
1264 |
* |
|
1265 |
* @return true if the window is modal excluded, false otherwise. If |
|
1266 |
* the modal exclusion isn't supported by the current Toolkit, false |
|
1267 |
* is returned |
|
1268 |
* |
|
1269 |
* @see sun.awt.SunToolkit#isModalExcludedSupported |
|
1270 |
* @see sun.awt.SunToolkit#setModalExcluded(java.awt.Window) |
|
1271 |
* |
|
1272 |
* @since 1.5 |
|
1273 |
*/ |
|
1274 |
public static boolean isModalExcluded(Window window) |
|
1275 |
{ |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1276 |
if (DEFAULT_MODAL_EXCLUSION_TYPE == null) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1277 |
DEFAULT_MODAL_EXCLUSION_TYPE = Dialog.ModalExclusionType.APPLICATION_EXCLUDE; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1278 |
} |
2 | 1279 |
return window.getModalExclusionType().compareTo(DEFAULT_MODAL_EXCLUSION_TYPE) >= 0; |
1280 |
} |
|
1281 |
||
1282 |
/** |
|
1283 |
* Overridden in XToolkit and WToolkit |
|
1284 |
*/ |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1285 |
@Override |
2 | 1286 |
public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { |
1287 |
return (modalityType == Dialog.ModalityType.MODELESS) || |
|
1288 |
(modalityType == Dialog.ModalityType.APPLICATION_MODAL); |
|
1289 |
} |
|
1290 |
||
1291 |
/** |
|
1292 |
* Overridden in XToolkit and WToolkit |
|
1293 |
*/ |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1294 |
@Override |
2 | 1295 |
public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) { |
1296 |
return (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE); |
|
1297 |
} |
|
1298 |
||
1299 |
/////////////////////////////////////////////////////////////////////////// |
|
1300 |
// |
|
1301 |
// The following is used by the Java Plug-in to coordinate dialog modality |
|
1302 |
// between containing applications (browsers, ActiveX containers etc) and |
|
1303 |
// the AWT. |
|
1304 |
// |
|
1305 |
/////////////////////////////////////////////////////////////////////////// |
|
1306 |
||
1307 |
private ModalityListenerList modalityListeners = new ModalityListenerList(); |
|
1308 |
||
1309 |
public void addModalityListener(ModalityListener listener) { |
|
1310 |
modalityListeners.add(listener); |
|
1311 |
} |
|
1312 |
||
1313 |
public void removeModalityListener(ModalityListener listener) { |
|
1314 |
modalityListeners.remove(listener); |
|
1315 |
} |
|
1316 |
||
1317 |
public void notifyModalityPushed(Dialog dialog) { |
|
1318 |
notifyModalityChange(ModalityEvent.MODALITY_PUSHED, dialog); |
|
1319 |
} |
|
1320 |
||
1321 |
public void notifyModalityPopped(Dialog dialog) { |
|
1322 |
notifyModalityChange(ModalityEvent.MODALITY_POPPED, dialog); |
|
1323 |
} |
|
1324 |
||
1325 |
final void notifyModalityChange(int id, Dialog source) { |
|
1326 |
ModalityEvent ev = new ModalityEvent(source, modalityListeners, id); |
|
1327 |
ev.dispatch(); |
|
1328 |
} |
|
1329 |
||
1330 |
static class ModalityListenerList implements ModalityListener { |
|
1331 |
||
1332 |
Vector<ModalityListener> listeners = new Vector<ModalityListener>(); |
|
1333 |
||
1334 |
void add(ModalityListener listener) { |
|
1335 |
listeners.addElement(listener); |
|
1336 |
} |
|
1337 |
||
1338 |
void remove(ModalityListener listener) { |
|
1339 |
listeners.removeElement(listener); |
|
1340 |
} |
|
1341 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1342 |
@Override |
2 | 1343 |
public void modalityPushed(ModalityEvent ev) { |
1344 |
Iterator<ModalityListener> it = listeners.iterator(); |
|
1345 |
while (it.hasNext()) { |
|
1346 |
it.next().modalityPushed(ev); |
|
1347 |
} |
|
1348 |
} |
|
1349 |
||
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1350 |
@Override |
2 | 1351 |
public void modalityPopped(ModalityEvent ev) { |
1352 |
Iterator<ModalityListener> it = listeners.iterator(); |
|
1353 |
while (it.hasNext()) { |
|
1354 |
it.next().modalityPopped(ev); |
|
1355 |
} |
|
1356 |
} |
|
1357 |
} // end of class ModalityListenerList |
|
1358 |
||
1359 |
/////////////////////////////////////////////////////////////////////////// |
|
1360 |
// End Plug-in code |
|
1361 |
/////////////////////////////////////////////////////////////////////////// |
|
1362 |
||
1363 |
public static boolean isLightweightOrUnknown(Component comp) { |
|
1364 |
if (comp.isLightweight() |
|
1365 |
|| !(getDefaultToolkit() instanceof SunToolkit)) |
|
1366 |
{ |
|
1367 |
return true; |
|
1368 |
} |
|
1369 |
return !(comp instanceof Button |
|
1370 |
|| comp instanceof Canvas |
|
1371 |
|| comp instanceof Checkbox |
|
1372 |
|| comp instanceof Choice |
|
1373 |
|| comp instanceof Label |
|
1374 |
|| comp instanceof java.awt.List |
|
1375 |
|| comp instanceof Panel |
|
1376 |
|| comp instanceof Scrollbar |
|
1377 |
|| comp instanceof ScrollPane |
|
1378 |
|| comp instanceof TextArea |
|
1379 |
|| comp instanceof TextField |
|
1380 |
|| comp instanceof Window); |
|
1381 |
} |
|
1382 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1383 |
@SuppressWarnings("serial") |
2 | 1384 |
public static class OperationTimedOut extends RuntimeException { |
1385 |
public OperationTimedOut(String msg) { |
|
1386 |
super(msg); |
|
1387 |
} |
|
1388 |
public OperationTimedOut() { |
|
1389 |
} |
|
1390 |
} |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1391 |
|
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1392 |
@SuppressWarnings("serial") |
2 | 1393 |
public static class InfiniteLoop extends RuntimeException { |
1394 |
} |
|
1395 |
||
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1396 |
@SuppressWarnings("serial") |
2 | 1397 |
public static class IllegalThreadException extends RuntimeException { |
1398 |
public IllegalThreadException(String msg) { |
|
1399 |
super(msg); |
|
1400 |
} |
|
1401 |
public IllegalThreadException() { |
|
1402 |
} |
|
1403 |
} |
|
1404 |
||
1405 |
public static final int DEFAULT_WAIT_TIME = 10000; |
|
1406 |
private static final int MAX_ITERS = 20; |
|
1407 |
private static final int MIN_ITERS = 0; |
|
1408 |
private static final int MINIMAL_EDELAY = 0; |
|
1409 |
||
1410 |
/** |
|
1411 |
* Parameterless version of realsync which uses default timout (see DEFAUL_WAIT_TIME). |
|
1412 |
*/ |
|
1413 |
public void realSync() throws OperationTimedOut, InfiniteLoop { |
|
1414 |
realSync(DEFAULT_WAIT_TIME); |
|
1415 |
} |
|
1416 |
||
1417 |
/** |
|
1418 |
* Forces toolkit to synchronize with the native windowing |
|
1419 |
* sub-system, flushing all pending work and waiting for all the |
|
1420 |
* events to be processed. This method guarantees that after |
|
1421 |
* return no additional Java events will be generated, unless |
|
1422 |
* cause by user. Obviously, the method cannot be used on the |
|
1423 |
* event dispatch thread (EDT). In case it nevertheless gets |
|
1424 |
* invoked on this thread, the method throws the |
|
1425 |
* IllegalThreadException runtime exception. |
|
1426 |
* |
|
1427 |
* <p> This method allows to write tests without explicit timeouts |
|
1428 |
* or wait for some event. Example: |
|
35667 | 1429 |
* <pre>{@code |
2 | 1430 |
* Frame f = ...; |
1431 |
* f.setVisible(true); |
|
1432 |
* ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); |
|
35667 | 1433 |
* }</pre> |
2 | 1434 |
* |
35667 | 1435 |
* <p> After realSync, {@code f} will be completely visible |
2 | 1436 |
* on the screen, its getLocationOnScreen will be returning the |
1437 |
* right result and it will be the focus owner. |
|
1438 |
* |
|
1439 |
* <p> Another example: |
|
35667 | 1440 |
* <pre>{@code |
2 | 1441 |
* b.requestFocus(); |
1442 |
* ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); |
|
35667 | 1443 |
* }</pre> |
2 | 1444 |
* |
35667 | 1445 |
* <p> After realSync, {@code b} will be focus owner. |
2 | 1446 |
* |
1447 |
* <p> Notice that realSync isn't guaranteed to work if recurring |
|
1448 |
* actions occur, such as if during processing of some event |
|
1449 |
* another request which may generate some events occurs. By |
|
30948
0a0972d3b58d
6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents:
30479
diff
changeset
|
1450 |
* default, sync tries to perform as much as {@value #MAX_ITERS} |
2 | 1451 |
* cycles of event processing, allowing for roughly {@value |
30948
0a0972d3b58d
6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents:
30479
diff
changeset
|
1452 |
* #MAX_ITERS} additional requests. |
2 | 1453 |
* |
1454 |
* <p> For example, requestFocus() generates native request, which |
|
1455 |
* generates one or two Java focus events, which then generate a |
|
1456 |
* serie of paint events, a serie of Java focus events, which then |
|
1457 |
* generate a serie of paint events which then are processed - |
|
1458 |
* three cycles, minimum. |
|
1459 |
* |
|
1460 |
* @param timeout the maximum time to wait in milliseconds, negative means "forever". |
|
1461 |
*/ |
|
1462 |
public void realSync(final long timeout) throws OperationTimedOut, InfiniteLoop |
|
1463 |
{ |
|
1464 |
if (EventQueue.isDispatchThread()) { |
|
1465 |
throw new IllegalThreadException("The SunToolkit.realSync() method cannot be used on the event dispatch thread (EDT)."); |
|
1466 |
} |
|
1467 |
int bigLoop = 0; |
|
1468 |
do { |
|
1469 |
// Let's do sync first |
|
1470 |
sync(); |
|
1471 |
||
1472 |
// During the wait process, when we were processing incoming |
|
1473 |
// events, we could have made some new request, which can |
|
1474 |
// generate new events. Example: MapNotify/XSetInputFocus. |
|
1475 |
// Therefore, we dispatch them as long as there is something |
|
1476 |
// to dispatch. |
|
1477 |
int iters = 0; |
|
1478 |
while (iters < MIN_ITERS) { |
|
1479 |
syncNativeQueue(timeout); |
|
1480 |
iters++; |
|
1481 |
} |
|
1482 |
while (syncNativeQueue(timeout) && iters < MAX_ITERS) { |
|
1483 |
iters++; |
|
1484 |
} |
|
1485 |
if (iters >= MAX_ITERS) { |
|
1486 |
throw new InfiniteLoop(); |
|
1487 |
} |
|
1488 |
||
1489 |
// native requests were dispatched by X/Window Manager or Windows |
|
1490 |
// Moreover, we processed them all on Toolkit thread |
|
1491 |
// Now wait while EDT processes them. |
|
1492 |
// |
|
1493 |
// During processing of some events (focus, for example), |
|
1494 |
// some other events could have been generated. So, after |
|
1495 |
// waitForIdle, we may end up with full EventQueue |
|
1496 |
iters = 0; |
|
1497 |
while (iters < MIN_ITERS) { |
|
1498 |
waitForIdle(timeout); |
|
1499 |
iters++; |
|
1500 |
} |
|
1501 |
while (waitForIdle(timeout) && iters < MAX_ITERS) { |
|
1502 |
iters++; |
|
1503 |
} |
|
1504 |
if (iters >= MAX_ITERS) { |
|
1505 |
throw new InfiniteLoop(); |
|
1506 |
} |
|
1507 |
||
1508 |
bigLoop++; |
|
1509 |
// Again, for Java events, it was simple to check for new Java |
|
1510 |
// events by checking event queue, but what if Java events |
|
1511 |
// resulted in native requests? Therefor, check native events again. |
|
1512 |
} while ((syncNativeQueue(timeout) || waitForIdle(timeout)) && bigLoop < MAX_ITERS); |
|
1513 |
} |
|
1514 |
||
1515 |
/** |
|
1516 |
* Platform toolkits need to implement this method to perform the |
|
1517 |
* sync of the native queue. The method should wait until native |
|
1518 |
* requests are processed, all native events are processed and |
|
1519 |
* corresponding Java events are generated. Should return |
|
35667 | 1520 |
* {@code true} if some events were processed, |
1521 |
* {@code false} otherwise. |
|
2 | 1522 |
*/ |
1523 |
protected abstract boolean syncNativeQueue(final long timeout); |
|
1524 |
||
41803
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1525 |
private boolean eventDispatched; |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1526 |
private boolean queueEmpty; |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1527 |
private final Object waitLock = new Object(); |
2 | 1528 |
|
1529 |
private boolean isEQEmpty() { |
|
1530 |
EventQueue queue = getSystemEventQueueImpl(); |
|
13604 | 1531 |
return AWTAccessor.getEventQueueAccessor().noEvents(queue); |
2 | 1532 |
} |
1533 |
||
1534 |
/** |
|
1535 |
* Waits for the Java event queue to empty. Ensures that all |
|
1536 |
* events are processed (including paint events), and that if |
|
1537 |
* recursive events were generated, they are also processed. |
|
35667 | 1538 |
* Should return {@code true} if more processing is |
1539 |
* necessary, {@code false} otherwise. |
|
2 | 1540 |
*/ |
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1541 |
@SuppressWarnings("serial") |
2 | 1542 |
protected final boolean waitForIdle(final long timeout) { |
1543 |
flushPendingEvents(); |
|
41803
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1544 |
final boolean queueWasEmpty; |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1545 |
synchronized (waitLock) { |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1546 |
queueWasEmpty = isEQEmpty(); |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1547 |
queueEmpty = false; |
635c82908fdf
8166673: The new implementation of Robot.waitForIdle() may hang
serb
parents:
41395
diff
changeset
|
1548 |
eventDispatched = false; |
2 | 1549 |
postEvent(AppContext.getAppContext(), |
1550 |
new PeerEvent(getSystemEventQueueImpl(), null, PeerEvent.LOW_PRIORITY_EVENT) { |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
28231
diff
changeset
|
1551 |
@Override |
2 | 1552 |
public void dispatch() { |
1553 |
// Here we block EDT. It could have some |
|
1554 |
// events, it should have dispatched them by |
|
1555 |
// now. So native requests could have been |
|
1556 |
// generated. First, dispatch them. Then, |
|
1557 |
// flush Java events again. |
|
1558 |
int iters = 0; |
|
1559 |
while (iters < MIN_ITERS) { |
|
1560 |
syncNativeQueue(timeout); |
|
1561 |
iters++; |
|
1562 |
} |
|
1563 |
while (syncNativeQueue(timeout) && iters < MAX_ITERS) { |
|
1564 |
iters++; |
|
1565 |
} |
|
1566 |
flushPendingEvents(); |
|
1567 |
||
1568 |
synchronized(waitLock) { |
|
1569 |
queueEmpty = isEQEmpty(); |
|
1570 |
eventDispatched = true; |
|
1571 |
waitLock.notifyAll(); |
|
1572 |
} |
|
1573 |
} |
|
1574 |
}); |
|
1575 |
try { |
|
1576 |
while (!eventDispatched) { |
|
1577 |
waitLock.wait(); |
|
1578 |
} |
|
1579 |
} catch (InterruptedException ie) { |
|
1580 |
return false; |
|
1581 |
} |
|
1582 |
} |
|
1583 |
||
1584 |
try { |
|
1585 |
Thread.sleep(MINIMAL_EDELAY); |
|
1586 |
} catch (InterruptedException ie) { |
|
1587 |
throw new RuntimeException("Interrupted"); |
|
1588 |
} |
|
1589 |
||
1590 |
flushPendingEvents(); |
|
1591 |
||
1592 |
// Lock to force write-cache flush for queueEmpty. |
|
1593 |
synchronized (waitLock) { |
|
1594 |
return !(queueEmpty && isEQEmpty() && queueWasEmpty); |
|
1595 |
} |
|
1596 |
} |
|
1597 |
||
1598 |
/** |
|
1599 |
* Grabs the mouse input for the given window. The window must be |
|
1600 |
* visible. The window or its children do not receive any |
|
1601 |
* additional mouse events besides those targeted to them. All |
|
1602 |
* other events will be dispatched as before - to the respective |
|
1603 |
* targets. This Window will receive UngrabEvent when automatic |
|
1604 |
* ungrab is about to happen. The event can be listened to by |
|
1605 |
* installing AWTEventListener with WINDOW_EVENT_MASK. See |
|
1606 |
* UngrabEvent class for the list of conditions when ungrab is |
|
1607 |
* about to happen. |
|
1608 |
* @see UngrabEvent |
|
1609 |
*/ |
|
1610 |
public abstract void grab(Window w); |
|
1611 |
||
1612 |
/** |
|
1613 |
* Forces ungrab. No event will be sent. |
|
1614 |
*/ |
|
1615 |
public abstract void ungrab(Window w); |
|
1616 |
||
1617 |
||
1618 |
/** |
|
1619 |
* Locates the splash screen library in a platform dependent way and closes |
|
1620 |
* the splash screen. Should be invoked on first top-level frame display. |
|
1621 |
* @see java.awt.SplashScreen |
|
1622 |
* @since 1.6 |
|
1623 |
*/ |
|
1624 |
public static native void closeSplashScreen(); |
|
1625 |
||
1626 |
/* The following methods and variables are to support retrieving |
|
1627 |
* desktop text anti-aliasing settings |
|
1628 |
*/ |
|
1629 |
||
1630 |
/* Need an instance method because setDesktopProperty(..) is protected. */ |
|
1631 |
private void fireDesktopFontPropertyChanges() { |
|
1632 |
setDesktopProperty(SunToolkit.DESKTOPFONTHINTS, |
|
1633 |
SunToolkit.getDesktopFontHints()); |
|
1634 |
} |
|
1635 |
||
1636 |
private static boolean checkedSystemAAFontSettings; |
|
1637 |
private static boolean useSystemAAFontSettings; |
|
1638 |
private static boolean lastExtraCondition = true; |
|
1639 |
private static RenderingHints desktopFontHints; |
|
1640 |
||
1641 |
/* Since Swing is the reason for this "extra condition" logic its |
|
1642 |
* worth documenting it in some detail. |
|
1643 |
* First, a goal is for Swing and applications to both retrieve and |
|
1644 |
* use the same desktop property value so that there is complete |
|
1645 |
* consistency between the settings used by JDK's Swing implementation |
|
1646 |
* and 3rd party custom Swing components, custom L&Fs and any general |
|
1647 |
* text rendering that wants to be consistent with these. |
|
1648 |
* But by default on Solaris & Linux Swing will not use AA text over |
|
1649 |
* remote X11 display (unless Xrender can be used which is TBD and may not |
|
1650 |
* always be available anyway) as that is a noticeable performance hit. |
|
1651 |
* So there needs to be a way to express that extra condition so that |
|
1652 |
* it is seen by all clients of the desktop property API. |
|
1653 |
* If this were the only condition it could be handled here as it would |
|
1654 |
* be the same for any L&F and could reasonably be considered to be |
|
1655 |
* a static behaviour of those systems. |
|
1656 |
* But GTK currently has an additional test based on locale which is |
|
1657 |
* not applied by Metal. So mixing GTK in a few locales with Metal |
|
1658 |
* would mean the last one wins. |
|
1659 |
* This could be stored per-app context which would work |
|
1660 |
* for different applets, but wouldn't help for a single application |
|
1661 |
* using GTK and some other L&F concurrently. |
|
1662 |
* But it is expected this will be addressed within GTK and the font |
|
1663 |
* system so is a temporary and somewhat unlikely harmless corner case. |
|
1664 |
*/ |
|
1665 |
public static void setAAFontSettingsCondition(boolean extraCondition) { |
|
1666 |
if (extraCondition != lastExtraCondition) { |
|
1667 |
lastExtraCondition = extraCondition; |
|
1668 |
if (checkedSystemAAFontSettings) { |
|
1669 |
/* Someone already asked for this info, under a different |
|
1670 |
* condition. |
|
1671 |
* We'll force re-evaluation instead of replicating the |
|
1672 |
* logic, then notify any listeners of any change. |
|
1673 |
*/ |
|
1674 |
checkedSystemAAFontSettings = false; |
|
1675 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1676 |
if (tk instanceof SunToolkit) { |
|
1677 |
((SunToolkit)tk).fireDesktopFontPropertyChanges(); |
|
1678 |
} |
|
1679 |
} |
|
1680 |
} |
|
1681 |
} |
|
1682 |
||
1683 |
/* "false", "off", ""default" aren't explicitly tested, they |
|
1684 |
* just fall through to produce a null return which all are equated to |
|
1685 |
* "false". |
|
1686 |
*/ |
|
1687 |
private static RenderingHints getDesktopAAHintsByName(String hintname) { |
|
1688 |
Object aaHint = null; |
|
1689 |
hintname = hintname.toLowerCase(Locale.ENGLISH); |
|
1690 |
if (hintname.equals("on")) { |
|
1691 |
aaHint = VALUE_TEXT_ANTIALIAS_ON; |
|
1692 |
} else if (hintname.equals("gasp")) { |
|
1693 |
aaHint = VALUE_TEXT_ANTIALIAS_GASP; |
|
1694 |
} else if (hintname.equals("lcd") || hintname.equals("lcd_hrgb")) { |
|
1695 |
aaHint = VALUE_TEXT_ANTIALIAS_LCD_HRGB; |
|
1696 |
} else if (hintname.equals("lcd_hbgr")) { |
|
1697 |
aaHint = VALUE_TEXT_ANTIALIAS_LCD_HBGR; |
|
1698 |
} else if (hintname.equals("lcd_vrgb")) { |
|
1699 |
aaHint = VALUE_TEXT_ANTIALIAS_LCD_VRGB; |
|
1700 |
} else if (hintname.equals("lcd_vbgr")) { |
|
1701 |
aaHint = VALUE_TEXT_ANTIALIAS_LCD_VBGR; |
|
1702 |
} |
|
1703 |
if (aaHint != null) { |
|
1704 |
RenderingHints map = new RenderingHints(null); |
|
1705 |
map.put(KEY_TEXT_ANTIALIASING, aaHint); |
|
1706 |
return map; |
|
1707 |
} else { |
|
1708 |
return null; |
|
1709 |
} |
|
1710 |
} |
|
1711 |
||
1712 |
/* This method determines whether to use the system font settings, |
|
1713 |
* or ignore them if a L&F has specified they should be ignored, or |
|
1714 |
* to override both of these with a system property specified value. |
|
1715 |
* If the toolkit isn't a SunToolkit, (eg may be headless) then that |
|
1716 |
* system property isn't applied as desktop properties are considered |
|
1717 |
* to be inapplicable in that case. In that headless case although |
|
1718 |
* this method will return "true" the toolkit will return a null map. |
|
1719 |
*/ |
|
1720 |
private static boolean useSystemAAFontSettings() { |
|
1721 |
if (!checkedSystemAAFontSettings) { |
|
1722 |
useSystemAAFontSettings = true; /* initially set this true */ |
|
1723 |
String systemAAFonts = null; |
|
1724 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1725 |
if (tk instanceof SunToolkit) { |
|
1726 |
systemAAFonts = |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1727 |
AccessController.doPrivileged( |
2 | 1728 |
new GetPropertyAction("awt.useSystemAAFontSettings")); |
1729 |
} |
|
1730 |
if (systemAAFonts != null) { |
|
1731 |
useSystemAAFontSettings = |
|
1732 |
Boolean.valueOf(systemAAFonts).booleanValue(); |
|
1733 |
/* If it is anything other than "true", then it may be |
|
1734 |
* a hint name , or it may be "off, "default", etc. |
|
1735 |
*/ |
|
1736 |
if (!useSystemAAFontSettings) { |
|
1737 |
desktopFontHints = getDesktopAAHintsByName(systemAAFonts); |
|
1738 |
} |
|
1739 |
} |
|
1740 |
/* If its still true, apply the extra condition */ |
|
1741 |
if (useSystemAAFontSettings) { |
|
1742 |
useSystemAAFontSettings = lastExtraCondition; |
|
1743 |
} |
|
1744 |
checkedSystemAAFontSettings = true; |
|
1745 |
} |
|
1746 |
return useSystemAAFontSettings; |
|
1747 |
} |
|
1748 |
||
1749 |
/* A variable defined for the convenience of JDK code */ |
|
1750 |
public static final String DESKTOPFONTHINTS = "awt.font.desktophints"; |
|
1751 |
||
1752 |
/* Overridden by subclasses to return platform/desktop specific values */ |
|
1753 |
protected RenderingHints getDesktopAAHints() { |
|
1754 |
return null; |
|
1755 |
} |
|
1756 |
||
1757 |
/* Subclass desktop property loading methods call this which |
|
1758 |
* in turn calls the appropriate subclass implementation of |
|
1759 |
* getDesktopAAHints() when system settings are being used. |
|
1760 |
* Its public rather than protected because subclasses may delegate |
|
1761 |
* to a helper class. |
|
1762 |
*/ |
|
1763 |
public static RenderingHints getDesktopFontHints() { |
|
1764 |
if (useSystemAAFontSettings()) { |
|
1765 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
1766 |
if (tk instanceof SunToolkit) { |
|
1767 |
Object map = ((SunToolkit)tk).getDesktopAAHints(); |
|
1768 |
return (RenderingHints)map; |
|
1769 |
} else { /* Headless Toolkit */ |
|
1770 |
return null; |
|
1771 |
} |
|
1772 |
} else if (desktopFontHints != null) { |
|
1773 |
/* cloning not necessary as the return value is cloned later, but |
|
1774 |
* its harmless. |
|
1775 |
*/ |
|
1776 |
return (RenderingHints)(desktopFontHints.clone()); |
|
1777 |
} else { |
|
1778 |
return null; |
|
1779 |
} |
|
1780 |
} |
|
1781 |
||
1782 |
||
1783 |
public abstract boolean isDesktopSupported(); |
|
36903 | 1784 |
public abstract boolean isTaskbarSupported(); |
2 | 1785 |
|
1786 |
/* |
|
1787 |
* consumeNextKeyTyped() method is not currently used, |
|
1788 |
* however Swing could use it in the future. |
|
1789 |
*/ |
|
1790 |
public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) { |
|
1791 |
try { |
|
13604 | 1792 |
AWTAccessor.getDefaultKeyboardFocusManagerAccessor().consumeNextKeyTyped( |
1793 |
(DefaultKeyboardFocusManager)KeyboardFocusManager. |
|
1794 |
getCurrentKeyboardFocusManager(), |
|
1795 |
keyEvent); |
|
1796 |
} catch (ClassCastException cce) { |
|
1797 |
cce.printStackTrace(); |
|
2 | 1798 |
} |
1799 |
} |
|
1800 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3237
diff
changeset
|
1801 |
protected static void dumpPeers(final PlatformLogger aLog) { |
2 | 1802 |
AWTAutoShutdown.getInstance().dumpPeers(aLog); |
1803 |
} |
|
1804 |
||
2451 | 1805 |
/** |
35667 | 1806 |
* Returns the {@code Window} ancestor of the component {@code comp}. |
2451 | 1807 |
* @return Window ancestor of the component or component by itself if it is Window; |
1808 |
* null, if component is not a part of window hierarchy |
|
1809 |
*/ |
|
1810 |
public static Window getContainingWindow(Component comp) { |
|
1811 |
while (comp != null && !(comp instanceof Window)) { |
|
1812 |
comp = comp.getParent(); |
|
1813 |
} |
|
1814 |
return (Window)comp; |
|
1815 |
} |
|
1816 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1817 |
private static Boolean sunAwtDisableMixing = null; |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1818 |
|
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1819 |
/** |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1820 |
* Returns the value of "sun.awt.disableMixing" property. Default |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1821 |
* value is {@code false}. |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1822 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32682
diff
changeset
|
1823 |
public static synchronized boolean getSunAwtDisableMixing() { |
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1824 |
if (sunAwtDisableMixing == null) { |
13604 | 1825 |
sunAwtDisableMixing = AccessController.doPrivileged( |
1826 |
new GetBooleanAction("sun.awt.disableMixing")); |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1827 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1828 |
return sunAwtDisableMixing.booleanValue(); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1829 |
} |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1973
diff
changeset
|
1830 |
|
2 | 1831 |
/** |
1832 |
* Returns true if the native GTK libraries are available. The |
|
1833 |
* default implementation returns false, but UNIXToolkit overrides this |
|
1834 |
* method to provide a more specific answer. |
|
1835 |
*/ |
|
1836 |
public boolean isNativeGTKAvailable() { |
|
1837 |
return false; |
|
1838 |
} |
|
2451 | 1839 |
|
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1840 |
private static final Object DEACTIVATION_TIMES_MAP_KEY = new Object(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1841 |
|
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1842 |
public synchronized void setWindowDeactivationTime(Window w, long time) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1843 |
AppContext ctx = getAppContext(w); |
27715
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1844 |
if (ctx == null) { |
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1845 |
return; |
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1846 |
} |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23900
diff
changeset
|
1847 |
@SuppressWarnings("unchecked") |
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1848 |
WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1849 |
if (map == null) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1850 |
map = new WeakHashMap<Window, Long>(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1851 |
ctx.put(DEACTIVATION_TIMES_MAP_KEY, map); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1852 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1853 |
map.put(w, time); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1854 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1855 |
|
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1856 |
public synchronized long getWindowDeactivationTime(Window w) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1857 |
AppContext ctx = getAppContext(w); |
27715
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1858 |
if (ctx == null) { |
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1859 |
return -1; |
58e23e39e064
8004148: NPE in sun.awt.SunToolkit.getWindowDeactivationTime
ant
parents:
26353
diff
changeset
|
1860 |
} |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
23900
diff
changeset
|
1861 |
@SuppressWarnings("unchecked") |
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1862 |
WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1863 |
if (map == null) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1864 |
return -1; |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1865 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1866 |
Long time = map.get(w); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1867 |
return time == null ? -1 : time; |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1868 |
} |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
1869 |
|
42739
36f46e978c31
8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents:
41803
diff
changeset
|
1870 |
public void updateScreenMenuBarUI() { |
36f46e978c31
8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents:
41803
diff
changeset
|
1871 |
} |
36f46e978c31
8166683: On macOS (Mac OS X) getting a ScreenMenuBar when not running "com.apple.laf.AquaLookAndFeel"
azvegint
parents:
41803
diff
changeset
|
1872 |
|
2451 | 1873 |
// Cosntant alpha |
1874 |
public boolean isWindowOpacitySupported() { |
|
1875 |
return false; |
|
1876 |
} |
|
1877 |
||
1878 |
// Shaping |
|
1879 |
public boolean isWindowShapingSupported() { |
|
1880 |
return false; |
|
1881 |
} |
|
1882 |
||
1883 |
// Per-pixel alpha |
|
1884 |
public boolean isWindowTranslucencySupported() { |
|
1885 |
return false; |
|
1886 |
} |
|
1887 |
||
1888 |
public boolean isTranslucencyCapable(GraphicsConfiguration gc) { |
|
1889 |
return false; |
|
1890 |
} |
|
1891 |
||
1892 |
/** |
|
13233 | 1893 |
* Returns true if swing backbuffer should be translucent. |
1894 |
*/ |
|
1895 |
public boolean isSwingBackbufferTranslucencySupported() { |
|
1896 |
return false; |
|
1897 |
} |
|
1898 |
||
1899 |
/** |
|
2451 | 1900 |
* Returns whether or not a containing top level window for the passed |
1901 |
* component is |
|
2648 | 1902 |
* {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}. |
2451 | 1903 |
* |
1904 |
* @param c a Component which toplevel's to check |
|
1905 |
* @return {@code true} if the passed component is not null and has a |
|
1906 |
* containing toplevel window which is opaque (so per-pixel translucency |
|
1907 |
* is not enabled), {@code false} otherwise |
|
2648 | 1908 |
* @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT |
2451 | 1909 |
*/ |
1910 |
public static boolean isContainingTopLevelOpaque(Component c) { |
|
1911 |
Window w = getContainingWindow(c); |
|
3237 | 1912 |
return w != null && w.isOpaque(); |
2451 | 1913 |
} |
1914 |
||
1915 |
/** |
|
1916 |
* Returns whether or not a containing top level window for the passed |
|
1917 |
* component is |
|
2648 | 1918 |
* {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}. |
2451 | 1919 |
* |
1920 |
* @param c a Component which toplevel's to check |
|
1921 |
* @return {@code true} if the passed component is not null and has a |
|
1922 |
* containing toplevel window which has opacity less than |
|
1923 |
* 1.0f (which means that it is translucent), {@code false} otherwise |
|
2648 | 1924 |
* @see GraphicsDevice.WindowTranslucency#TRANSLUCENT |
2451 | 1925 |
*/ |
1926 |
public static boolean isContainingTopLevelTranslucent(Component c) { |
|
1927 |
Window w = getContainingWindow(c); |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1928 |
return w != null && w.getOpacity() < 1.0f; |
2451 | 1929 |
} |
1930 |
||
1931 |
/** |
|
1932 |
* Returns whether the native system requires using the peer.updateWindow() |
|
1933 |
* method to update the contents of a non-opaque window, or if usual |
|
1934 |
* painting procedures are sufficient. The default return value covers |
|
1935 |
* the X11 systems. On MS Windows this method is overriden in WToolkit |
|
1936 |
* to return true. |
|
1937 |
*/ |
|
1938 |
public boolean needUpdateWindow() { |
|
1939 |
return false; |
|
1940 |
} |
|
1941 |
||
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1942 |
/** |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1943 |
* Descendants of the SunToolkit should override and put their own logic here. |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1944 |
*/ |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1945 |
public int getNumberOfButtons(){ |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1946 |
return 3; |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2648
diff
changeset
|
1947 |
} |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1948 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1949 |
/** |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1950 |
* Checks that the given object implements/extends the given |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1951 |
* interface/class. |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1952 |
* |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1953 |
* Note that using the instanceof operator causes a class to be loaded. |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1954 |
* Using this method doesn't load a class and it can be used instead of |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1955 |
* the instanceof operator for performance reasons. |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1956 |
* |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1957 |
* @param obj Object to be checked |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1958 |
* @param type The name of the interface/class. Must be |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1959 |
* fully-qualified interface/class name. |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1960 |
* @return true, if this object implements/extends the given |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1961 |
* interface/class, false, otherwise, or if obj or type is null |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1962 |
*/ |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1963 |
public static boolean isInstanceOf(Object obj, String type) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1964 |
if (obj == null) return false; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1965 |
if (type == null) return false; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1966 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1967 |
return isInstanceOf(obj.getClass(), type); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1968 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1969 |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1970 |
private static boolean isInstanceOf(Class<?> cls, String type) { |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1971 |
if (cls == null) return false; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1972 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1973 |
if (cls.getName().equals(type)) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1974 |
return true; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1975 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1976 |
|
11264
54f2f4c6bd30
7117008: Warnings cleanup day: reduce number of javac warnings in the sun.awt package
art
parents:
9035
diff
changeset
|
1977 |
for (Class<?> c : cls.getInterfaces()) { |
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1978 |
if (c.getName().equals(type)) { |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1979 |
return true; |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1980 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1981 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1982 |
return isInstanceOf(cls.getSuperclass(), type); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2810
diff
changeset
|
1983 |
} |
6826
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
1984 |
|
26342
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1985 |
protected static LightweightFrame getLightweightFrame(Component c) { |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1986 |
for (; c != null; c = c.getParent()) { |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1987 |
if (c instanceof LightweightFrame) { |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1988 |
return (LightweightFrame)c; |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1989 |
} |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1990 |
if (c instanceof Window) { |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1991 |
// Don't traverse owner windows |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1992 |
return null; |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1993 |
} |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1994 |
} |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1995 |
return null; |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1996 |
} |
3637212ae8f2
8049065: [JLightweightFrame] Support DnD for SwingNode
anthony
parents:
26031
diff
changeset
|
1997 |
|
6826
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
1998 |
/////////////////////////////////////////////////////////////////////////// |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
1999 |
// |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2000 |
// The following methods help set and identify whether a particular |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2001 |
// AWTEvent object was produced by the system or by user code. As of this |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2002 |
// writing the only consumer is the Java Plug-In, although this information |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2003 |
// could be useful to more clients and probably should be formalized in |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2004 |
// the public API. |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2005 |
// |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2006 |
/////////////////////////////////////////////////////////////////////////// |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2007 |
|
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2008 |
public static void setSystemGenerated(AWTEvent e) { |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2009 |
AWTAccessor.getAWTEventAccessor().setSystemGenerated(e); |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2010 |
} |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2011 |
|
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2012 |
public static boolean isSystemGenerated(AWTEvent e) { |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2013 |
return AWTAccessor.getAWTEventAccessor().isSystemGenerated(e); |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2014 |
} |
1fc6a05552f2
6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents:
6821
diff
changeset
|
2015 |
|
2 | 2016 |
} // class SunToolkit |
2017 |
||
2018 |
||
2019 |
/* |
|
2020 |
* PostEventQueue is a Thread that runs in the same AppContext as the |
|
2021 |
* Java EventQueue. It is a queue of AWTEvents to be posted to the |
|
2022 |
* Java EventQueue. The toolkit Thread (AWT-Windows/AWT-Motif) posts |
|
2023 |
* events to this queue, which then calls EventQueue.postEvent(). |
|
2024 |
* |
|
2025 |
* We do this because EventQueue.postEvent() may be overridden by client |
|
2026 |
* code, and we mustn't ever call client code from the toolkit thread. |
|
2027 |
*/ |
|
2028 |
class PostEventQueue { |
|
2029 |
private EventQueueItem queueHead = null; |
|
2030 |
private EventQueueItem queueTail = null; |
|
2031 |
private final EventQueue eventQueue; |
|
2032 |
||
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2033 |
private Thread flushThread = null; |
13240
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2034 |
|
2 | 2035 |
PostEventQueue(EventQueue eq) { |
2036 |
eventQueue = eq; |
|
2037 |
} |
|
2038 |
||
2039 |
/* |
|
5942
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
2040 |
* Continually post pending AWTEvents to the Java EventQueue. The method |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
2041 |
* is synchronized to ensure the flush is completed before a new event |
287c421fb9b2
6424157: java.awt.EventQueue push/pop might cause threading issues
art
parents:
5506
diff
changeset
|
2042 |
* can be posted to this queue. |
13240
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2043 |
* |
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2044 |
* 7177040: The method couldn't be wholly synchronized because of calls |
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2045 |
* of EventQueue.postEvent() that uses pushPopLock, otherwise it could |
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2046 |
* potentially lead to deadlock |
2 | 2047 |
*/ |
13240
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2048 |
public void flush() { |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2049 |
|
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2050 |
Thread newThread = Thread.currentThread(); |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2051 |
|
13240
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2052 |
try { |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2053 |
EventQueueItem tempQueue; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2054 |
synchronized (this) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2055 |
// Avoid method recursion |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2056 |
if (newThread == flushThread) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2057 |
return; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2058 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2059 |
// Wait for other threads' flushing |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2060 |
while (flushThread != null) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2061 |
wait(); |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2062 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2063 |
// Skip everything if queue is empty |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2064 |
if (queueHead == null) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2065 |
return; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2066 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2067 |
// Remember flushing thread |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2068 |
flushThread = newThread; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2069 |
|
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2070 |
tempQueue = queueHead; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2071 |
queueHead = queueTail = null; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2072 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2073 |
try { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2074 |
while (tempQueue != null) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2075 |
eventQueue.postEvent(tempQueue.event); |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2076 |
tempQueue = tempQueue.next; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2077 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2078 |
} |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2079 |
finally { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2080 |
// Only the flushing thread can get here |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2081 |
synchronized (this) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2082 |
// Forget flushing thread, inform other pending threads |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2083 |
flushThread = null; |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2084 |
notifyAll(); |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2085 |
} |
13240
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2086 |
} |
5f9e6f436f0b
7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater
bagiras
parents:
13233
diff
changeset
|
2087 |
} |
13775
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2088 |
catch (InterruptedException e) { |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2089 |
// Couldn't allow exception go up, so at least recover the flag |
3ab536cab1d1
7186109: Simplify lock machinery for PostEventQueue & EventQueue
bagiras
parents:
13656
diff
changeset
|
2090 |
newThread.interrupt(); |
2 | 2091 |
} |
2092 |
} |
|
2093 |
||
2094 |
/* |
|
2095 |
* Enqueue an AWTEvent to be posted to the Java EventQueue. |
|
2096 |
*/ |
|
2097 |
void postEvent(AWTEvent event) { |
|
2098 |
EventQueueItem item = new EventQueueItem(event); |
|
2099 |
||
2100 |
synchronized (this) { |
|
2101 |
if (queueHead == null) { |
|
2102 |
queueHead = queueTail = item; |
|
2103 |
} else { |
|
2104 |
queueTail.next = item; |
|
2105 |
queueTail = item; |
|
2106 |
} |
|
2107 |
} |
|
2108 |
SunToolkit.wakeupEventQueue(eventQueue, event.getSource() == AWTAutoShutdown.getInstance()); |
|
2109 |
} |
|
2110 |
} // class PostEventQueue |