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