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