1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import java.awt.*; 29 import java.awt.datatransfer.Clipboard; 30 import java.awt.dnd.*; 31 import java.awt.dnd.peer.DragSourceContextPeer; 32 import java.awt.event.InputEvent; 33 import java.awt.event.InvocationEvent; 34 import java.awt.event.KeyEvent; 35 import java.awt.im.InputMethodHighlight; 36 import java.awt.peer.*; 37 import java.lang.reflect.*; 38 import java.security.*; 39 import java.util.*; 40 import java.util.concurrent.Callable; 41 42 import sun.awt.*; 43 import sun.lwawt.*; 44 import sun.lwawt.LWWindowPeer.PeerType; 45 import sun.security.action.GetBooleanAction; 46 47 class NamedCursor extends Cursor { 48 NamedCursor(String name) { 49 super(name); 50 } 51 } 52 53 /** 54 * Mac OS X Cocoa-based AWT Toolkit. 55 */ 56 public class LWCToolkit extends LWToolkit { 57 // While it is possible to enumerate all mouse devices 58 // and query them for the number of buttons, the code 59 // that does it is rather complex. Instead, we opt for 60 // the easy way and just support up to 5 mouse buttons, 61 // like Windows. 62 private static final int BUTTONS = 5; 63 64 private static native void initIDs(); 65 66 static native void executeNextAppKitEvent(); 67 68 private static CInputMethodDescriptor sInputMethodDescriptor; 69 70 static { 71 System.err.flush(); 72 java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() { 73 public Object run() { 74 System.loadLibrary("awt"); 75 System.loadLibrary("fontmanager"); 76 return null; 77 } 78 }); 79 if (!GraphicsEnvironment.isHeadless()) { 80 initIDs(); 81 } 82 } 83 84 public LWCToolkit() { 85 SunToolkit.setDataTransfererClassName("sun.lwawt.macosx.CDataTransferer"); 86 87 areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true")); 88 //set system property if not yet assigned 89 System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled); 90 } 91 92 /* 93 * System colors with default initial values, overwritten by toolkit if system values differ and are available. 94 */ 95 private final static int NUM_APPLE_COLORS = 3; 96 public final static int KEYBOARD_FOCUS_COLOR = 0; 97 public final static int INACTIVE_SELECTION_BACKGROUND_COLOR = 1; 98 public final static int INACTIVE_SELECTION_FOREGROUND_COLOR = 2; 99 private static int[] appleColors = { 100 0xFF808080, // keyboardFocusColor = Color.gray; 101 0xFFC0C0C0, // secondarySelectedControlColor 102 0xFF303030, // controlDarkShadowColor 103 }; 104 105 private native void loadNativeColors(final int[] systemColors, final int[] appleColors); 106 107 protected void loadSystemColors(final int[] systemColors) { 108 if (systemColors == null) return; 109 loadNativeColors(systemColors, appleColors); 110 } 111 112 private static class AppleSpecificColor extends Color { 113 int index; 114 public AppleSpecificColor(int index) { 115 super(appleColors[index]); 116 this.index = index; 117 } 118 119 public int getRGB() { 120 return appleColors[index]; 121 } 122 } 123 124 /** 125 * Returns Apple specific colors that we may expose going forward. 126 * 127 */ 128 public static Color getAppleColor(int color) { 129 return new AppleSpecificColor(color); 130 } 131 132 static void systemColorsChanged() { 133 // This is only called from native code. 134 EventQueue.invokeLater(new Runnable() { 135 public void run() { 136 AccessController.doPrivileged (new PrivilegedAction<Object>() { 137 public Object run() { 138 try { 139 final Method updateColorsMethod = SystemColor.class.getDeclaredMethod("updateSystemColors", new Class[0]); 140 updateColorsMethod.setAccessible(true); 141 updateColorsMethod.invoke(null, new Object[0]); 142 } catch (final Throwable e) { 143 e.printStackTrace(); 144 // swallow this if something goes horribly wrong 145 } 146 return null; 147 } 148 }); 149 } 150 }); 151 } 152 153 @Override 154 protected PlatformWindow createPlatformWindow(PeerType peerType) { 155 if (peerType == PeerType.EMBEDDEDFRAME) { 156 return new CPlatformEmbeddedFrame(); 157 } else { 158 return new CPlatformWindow(peerType); 159 } 160 } 161 162 @Override 163 protected PlatformComponent createPlatformComponent() { 164 return new CPlatformComponent(); 165 } 166 167 @Override 168 protected FileDialogPeer createFileDialogPeer(FileDialog target) { 169 return new CFileDialog(target); 170 } 171 172 @Override 173 public MenuPeer createMenu(Menu target) { 174 MenuPeer peer = new CMenu(target); 175 targetCreatedPeer(target, peer); 176 return peer; 177 } 178 179 @Override 180 public MenuBarPeer createMenuBar(MenuBar target) { 181 MenuBarPeer peer = new CMenuBar(target); 182 targetCreatedPeer(target, peer); 183 return peer; 184 } 185 186 @Override 187 public MenuItemPeer createMenuItem(MenuItem target) { 188 MenuItemPeer peer = new CMenuItem(target); 189 targetCreatedPeer(target, peer); 190 return peer; 191 } 192 193 @Override 194 public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) { 195 CheckboxMenuItemPeer peer = new CCheckboxMenuItem(target); 196 targetCreatedPeer(target, peer); 197 return peer; 198 } 199 200 @Override 201 public PopupMenuPeer createPopupMenu(PopupMenu target) { 202 PopupMenuPeer peer = new CPopupMenu(target); 203 targetCreatedPeer(target, peer); 204 return peer; 205 206 } 207 208 @Override 209 public SystemTrayPeer createSystemTray(SystemTray target) { 210 SystemTrayPeer peer = new CSystemTray(); 211 return peer; 212 } 213 214 @Override 215 public TrayIconPeer createTrayIcon(TrayIcon target) { 216 TrayIconPeer peer = new CTrayIcon(target); 217 targetCreatedPeer(target, peer); 218 return peer; 219 } 220 221 @Override 222 public LWCursorManager getCursorManager() { 223 return CCursorManager.getInstance(); 224 } 225 226 @Override 227 public Cursor createCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException { 228 return new CCustomCursor(cursor, hotSpot, name); 229 } 230 231 @Override 232 public Dimension getBestCursorSize(final int preferredWidth, final int preferredHeight) throws HeadlessException { 233 return CCustomCursor.getBestCursorSize(preferredWidth, preferredHeight); 234 } 235 236 @Override 237 protected void platformCleanup() { 238 // TODO Auto-generated method stub 239 240 } 241 242 @Override 243 protected void platformInit() { 244 // TODO Auto-generated method stub 245 246 } 247 248 @Override 249 protected void platformRunMessage() { 250 // TODO Auto-generated method stub 251 252 } 253 254 @Override 255 protected void platformShutdown() { 256 // TODO Auto-generated method stub 257 258 } 259 260 class OSXPlatformFont extends sun.awt.PlatformFont 261 { 262 public OSXPlatformFont(String name, int style) 263 { 264 super(name, style); 265 } 266 protected char getMissingGlyphCharacter() 267 { 268 // Follow up for real implementation 269 return (char)0xfff8; // see http://developer.apple.com/fonts/LastResortFont/ 270 } 271 } 272 public FontPeer getFontPeer(String name, int style) { 273 return new OSXPlatformFont(name, style); 274 } 275 276 @Override 277 protected MouseInfoPeer createMouseInfoPeerImpl() { 278 return new CMouseInfoPeer(); 279 } 280 281 282 @Override 283 protected int getScreenHeight() { 284 return GraphicsEnvironment.getLocalGraphicsEnvironment() 285 .getDefaultScreenDevice().getDefaultConfiguration().getBounds().height; 286 } 287 288 @Override 289 protected int getScreenWidth() { 290 return GraphicsEnvironment.getLocalGraphicsEnvironment() 291 .getDefaultScreenDevice().getDefaultConfiguration().getBounds().width; 292 } 293 294 @Override 295 protected void initializeDesktopProperties() { 296 super.initializeDesktopProperties(); 297 Map <Object, Object> fontHints = new HashMap<Object, Object>(); 298 fontHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 299 fontHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 300 desktopProperties.put(SunToolkit.DESKTOPFONTHINTS, fontHints); 301 desktopProperties.put("awt.mouse.numButtons", BUTTONS); 302 303 // These DnD properties must be set, otherwise Swing ends up spewing NPEs 304 // all over the place. The values came straight off of MToolkit. 305 desktopProperties.put("DnD.Autoscroll.initialDelay", new Integer(50)); 306 desktopProperties.put("DnD.Autoscroll.interval", new Integer(50)); 307 desktopProperties.put("DnD.Autoscroll.cursorHysteresis", new Integer(5)); 308 309 desktopProperties.put("DnD.isDragImageSupported", new Boolean(true)); 310 311 // Register DnD cursors 312 desktopProperties.put("DnD.Cursor.CopyDrop", new NamedCursor("DnD.Cursor.CopyDrop")); 313 desktopProperties.put("DnD.Cursor.MoveDrop", new NamedCursor("DnD.Cursor.MoveDrop")); 314 desktopProperties.put("DnD.Cursor.LinkDrop", new NamedCursor("DnD.Cursor.LinkDrop")); 315 desktopProperties.put("DnD.Cursor.CopyNoDrop", new NamedCursor("DnD.Cursor.CopyNoDrop")); 316 desktopProperties.put("DnD.Cursor.MoveNoDrop", new NamedCursor("DnD.Cursor.MoveNoDrop")); 317 desktopProperties.put("DnD.Cursor.LinkNoDrop", new NamedCursor("DnD.Cursor.LinkNoDrop")); 318 319 } 320 321 322 /* 323 * The method returns true if some events were processed during that timeout. 324 * @see sun.awt.SunToolkit#syncNativeQueue(long) 325 */ 326 @Override 327 protected boolean syncNativeQueue(long timeout) { 328 return nativeSyncQueue(timeout); 329 } 330 331 @Override 332 public native void beep(); 333 334 @Override 335 public int getScreenResolution() throws HeadlessException { 336 return ((CGraphicsDevice) GraphicsEnvironment 337 .getLocalGraphicsEnvironment().getDefaultScreenDevice()).getScreenResolution(); 338 } 339 340 @Override 341 public Insets getScreenInsets(final GraphicsConfiguration gc) { 342 final CGraphicsConfig cgc = (CGraphicsConfig) gc; 343 final int displayId = cgc.getDevice().getCoreGraphicsScreen(); 344 Rectangle fullScreen, workArea; 345 final long screen = CWrapper.NSScreen.screenByDisplayId(displayId); 346 try { 347 fullScreen = CWrapper.NSScreen.frame(screen).getBounds(); 348 workArea = CWrapper.NSScreen.visibleFrame(screen).getBounds(); 349 } finally { 350 CWrapper.NSObject.release(screen); 351 } 352 // Convert between Cocoa's coordinate system and Java. 353 int bottom = workArea.y - fullScreen.y; 354 int top = fullScreen.height - workArea.height - bottom; 355 int left = workArea.x - fullScreen.x; 356 int right = fullScreen.width - workArea.width - left; 357 return new Insets(top, left, bottom, right); 358 } 359 360 @Override 361 public void sync() { 362 // TODO Auto-generated method stub 363 364 } 365 366 @Override 367 public RobotPeer createRobot(Robot target, GraphicsDevice screen) { 368 return new CRobot(target, (CGraphicsDevice)screen); 369 } 370 371 private native boolean isCapsLockOn(); 372 373 /* 374 * NOTE: Among the keys this method is supposed to check, 375 * only Caps Lock works as a true locking key with OS X. 376 * There is no Scroll Lock key on modern Apple keyboards, 377 * and with a PC keyboard plugged in Scroll Lock is simply 378 * ignored: no LED lights up if you press it. 379 * The key located at the same position on Apple keyboards 380 * as Num Lock on PC keyboards is called Clear, doesn't lock 381 * anything and is used for entirely different purpose. 382 */ 383 public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { 384 switch (keyCode) { 385 case KeyEvent.VK_NUM_LOCK: 386 case KeyEvent.VK_SCROLL_LOCK: 387 case KeyEvent.VK_KANA_LOCK: 388 throw new UnsupportedOperationException("Toolkit.getLockingKeyState"); 389 390 case KeyEvent.VK_CAPS_LOCK: 391 return isCapsLockOn(); 392 393 default: 394 throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState"); 395 } 396 } 397 398 //Is it allowed to generate events assigned to extra mouse buttons. 399 //Set to true by default. 400 private static boolean areExtraMouseButtonsEnabled = true; 401 402 public boolean areExtraMouseButtonsEnabled() throws HeadlessException { 403 return areExtraMouseButtonsEnabled; 404 } 405 406 public int getNumberOfButtons(){ 407 return BUTTONS; 408 } 409 410 411 @Override 412 public boolean isTraySupported() { 413 return true; 414 } 415 416 @Override 417 public boolean isAlwaysOnTopSupported() { 418 return true; 419 } 420 421 // Intended to be called from the LWCToolkit.m only. 422 private static void installToolkitThreadNameInJava() { 423 Thread.currentThread().setName(CThreading.APPKIT_THREAD_NAME); 424 } 425 426 @Override 427 public boolean isWindowOpacitySupported() { 428 return true; 429 } 430 431 @Override 432 public boolean isFrameStateSupported(int state) throws HeadlessException { 433 switch (state) { 434 case Frame.NORMAL: 435 case Frame.ICONIFIED: 436 case Frame.MAXIMIZED_BOTH: 437 return true; 438 default: 439 return false; 440 } 441 } 442 443 /** 444 * Determines which modifier key is the appropriate accelerator 445 * key for menu shortcuts. 446 * <p> 447 * Menu shortcuts, which are embodied in the 448 * <code>MenuShortcut</code> class, are handled by the 449 * <code>MenuBar</code> class. 450 * <p> 451 * By default, this method returns <code>Event.CTRL_MASK</code>. 452 * Toolkit implementations should override this method if the 453 * <b>Control</b> key isn't the correct key for accelerators. 454 * @return the modifier mask on the <code>Event</code> class 455 * that is used for menu shortcuts on this toolkit. 456 * @see java.awt.MenuBar 457 * @see java.awt.MenuShortcut 458 * @since JDK1.1 459 */ 460 public int getMenuShortcutKeyMask() { 461 return Event.META_MASK; 462 } 463 464 @Override 465 public Image getImage(final String filename) { 466 final Image nsImage = checkForNSImage(filename); 467 if (nsImage != null) return nsImage; 468 469 return super.getImage(filename); 470 } 471 472 static final String nsImagePrefix = "NSImage://"; 473 protected Image checkForNSImage(final String imageName) { 474 if (imageName == null) return null; 475 if (!imageName.startsWith(nsImagePrefix)) return null; 476 return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length())); 477 } 478 479 // Thread-safe Object.equals() called from native 480 public static boolean doEquals(final Object a, final Object b, Component c) { 481 if (a == b) return true; 482 483 final boolean[] ret = new boolean[1]; 484 485 try { invokeAndWait(new Runnable() { public void run() { synchronized(ret) { 486 ret[0] = a.equals(b); 487 }}}, c); } catch (Exception e) { e.printStackTrace(); } 488 489 synchronized(ret) { return ret[0]; } 490 } 491 492 // Kicks an event over to the appropriate eventqueue and waits for it to finish 493 // To avoid deadlocking, we manually run the NSRunLoop while waiting 494 // Any selector invoked using ThreadUtilities performOnMainThread will be processed in doAWTRunLoop 495 // The CInvocationEvent will call LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual runloop 496 public static void invokeAndWait(Runnable event, Component component) throws InterruptedException, InvocationTargetException { 497 invokeAndWait(event, component, true); 498 } 499 500 public static <T> T invokeAndWait(final Callable<T> callable, Component component) throws Exception { 501 final CallableWrapper<T> wrapper = new CallableWrapper<T>(callable); 502 invokeAndWait(wrapper, component); 503 return wrapper.getResult(); 504 } 505 506 static final class CallableWrapper<T> implements Runnable { 507 final Callable<T> callable; 508 T object; 509 Exception e; 510 511 public CallableWrapper(final Callable<T> callable) { 512 this.callable = callable; 513 } 514 515 public void run() { 516 try { 517 object = callable.call(); 518 } catch (final Exception e) { 519 this.e = e; 520 } 521 } 522 523 public T getResult() throws Exception { 524 if (e != null) throw e; 525 return object; 526 } 527 } 528 529 public static void invokeAndWait(Runnable event, Component component, boolean detectDeadlocks) throws InterruptedException, InvocationTargetException { 530 long mediator = createAWTRunLoopMediator(); 531 532 InvocationEvent invocationEvent = new CPeerEvent(event, mediator); 533 534 if (component != null) { 535 AppContext appContext = SunToolkit.targetToAppContext(component); 536 SunToolkit.postEvent(appContext, invocationEvent); 537 538 // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock 539 sun.awt.SunToolkitSubclass.flushPendingEvents(appContext); 540 } else { 541 // This should be the equivalent to EventQueue.invokeAndWait 542 ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent); 543 } 544 545 doAWTRunLoop(mediator, true, detectDeadlocks); 546 547 Throwable eventException = invocationEvent.getException(); 548 if (eventException != null) { 549 if (eventException instanceof UndeclaredThrowableException) { 550 eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable(); 551 } 552 throw new InvocationTargetException(eventException); 553 } 554 } 555 556 public static void invokeLater(Runnable event, Component component) throws InvocationTargetException { 557 final InvocationEvent invocationEvent = new CPeerEvent(event, 0); 558 559 if (component != null) { 560 final AppContext appContext = SunToolkit.targetToAppContext(component); 561 SunToolkit.postEvent(appContext, invocationEvent); 562 563 // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock 564 sun.awt.SunToolkitSubclass.flushPendingEvents(appContext); 565 } else { 566 // This should be the equivalent to EventQueue.invokeAndWait 567 ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent); 568 } 569 570 final Throwable eventException = invocationEvent.getException(); 571 if (eventException == null) return; 572 573 if (eventException instanceof UndeclaredThrowableException) { 574 throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable()); 575 } 576 throw new InvocationTargetException(eventException); 577 } 578 579 // This exists purely to get around permissions issues with getSystemEventQueueImpl 580 EventQueue getSystemEventQueueForInvokeAndWait() { 581 return getSystemEventQueueImpl(); 582 } 583 584 585 // DnD support 586 587 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { 588 DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge); 589 590 return dscp; 591 } 592 593 public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { 594 DragGestureRecognizer dgr = null; 595 596 // Create a new mouse drag gesture recognizer if we have a class match: 597 if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass)) 598 dgr = new CMouseDragGestureRecognizer(ds, c, srcActions, dgl); 599 600 return (T)dgr; 601 } 602 603 // InputMethodSupport Method 604 /** 605 * Returns the default keyboard locale of the underlying operating system 606 */ 607 public Locale getDefaultKeyboardLocale() { 608 Locale locale = CInputMethod.getNativeLocale(); 609 610 if (locale == null) { 611 return super.getDefaultKeyboardLocale(); 612 } 613 614 return locale; 615 } 616 617 public java.awt.im.spi.InputMethodDescriptor getInputMethodAdapterDescriptor() { 618 if (sInputMethodDescriptor == null) 619 sInputMethodDescriptor = new CInputMethodDescriptor(); 620 621 return sInputMethodDescriptor; 622 } 623 624 /** 625 * Returns a map of visual attributes for thelevel description 626 * of the given input method highlight, or null if no mapping is found. 627 * The style field of the input method highlight is ignored. The map 628 * returned is unmodifiable. 629 * @param highlight input method highlight 630 * @return style attribute map, or null 631 * @since 1.3 632 */ 633 public Map mapInputMethodHighlight(InputMethodHighlight highlight) { 634 return CInputMethod.mapInputMethodHighlight(highlight); 635 } 636 637 /** 638 * Returns key modifiers used by Swing to set up a focus accelerator key stroke. 639 */ 640 @Override 641 public int getFocusAcceleratorKeyMask() { 642 return InputEvent.CTRL_MASK | InputEvent.ALT_MASK; 643 } 644 645 /** 646 * Tests whether specified key modifiers mask can be used to enter a printable 647 * character. 648 */ 649 @Override 650 public boolean isPrintableCharacterModifiersMask(int mods) { 651 return ((mods & (InputEvent.META_MASK | InputEvent.CTRL_MASK)) == 0); 652 } 653 654 /** 655 * Returns whether popup is allowed to be shown above the task bar. 656 */ 657 @Override 658 public boolean canPopupOverlapTaskBar() { 659 return false; 660 } 661 662 // Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early 663 // Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop 664 public static class CPeerEvent extends PeerEvent { 665 private long _mediator = 0; 666 667 public CPeerEvent(Runnable runnable, long mediator) { 668 super(Toolkit.getDefaultToolkit(), runnable, null, true, 0); 669 _mediator = mediator; 670 } 671 672 public void dispatch() { 673 try { 674 super.dispatch(); 675 } finally { 676 if (_mediator != 0) { 677 LWCToolkit.stopAWTRunLoop(_mediator); 678 } 679 } 680 } 681 } 682 683 // Call through to native methods 684 public static void doAWTRunLoop(long mediator, boolean awtMode) { doAWTRunLoop(mediator, awtMode, true); } 685 public static void doAWTRunLoop(long mediator) { doAWTRunLoop(mediator, true); } 686 687 private static Boolean sunAwtDisableCALayers = null; 688 689 /** 690 * Returns the value of "sun.awt.disableCALayers" property. Default 691 * value is {@code false}. 692 */ 693 public synchronized static boolean getSunAwtDisableCALayers() { 694 if (sunAwtDisableCALayers == null) { 695 sunAwtDisableCALayers = AccessController.doPrivileged( 696 new GetBooleanAction("sun.awt.disableCALayers")); 697 } 698 return sunAwtDisableCALayers.booleanValue(); 699 } 700 701 702 /* 703 * Returns true if the application (one of its windows) owns keyboard focus. 704 */ 705 public native boolean isApplicationActive(); 706 707 /************************ 708 * Native methods section 709 ************************/ 710 711 // These are public because they are accessed from WebKitPluginObject in JavaDeploy 712 // Basic usage: 713 // createAWTRunLoopMediator. Start client code on another thread. doAWTRunLoop. When client code is finished, stopAWTRunLoop. 714 public static native long createAWTRunLoopMediator(); 715 public static native void doAWTRunLoop(long mediator, boolean awtMode, boolean detectDeadlocks); 716 public static native void stopAWTRunLoop(long mediator); 717 718 private native boolean nativeSyncQueue(long timeout); 719 720 @Override 721 public Clipboard createPlatformClipboard() { 722 return new CClipboard("System"); 723 } 724 725 @Override 726 public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) { 727 return (exclusionType == null) || 728 (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) || 729 (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) || 730 (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE); 731 } 732 733 @Override 734 public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { 735 //TODO: FileDialog blocks excluded windows... 736 //TODO: Test: 2 file dialogs, separate AppContexts: a) Dialog 1 blocked, shouldn't be. Frame 4 blocked (shouldn't be). 737 return (modalityType == null) || 738 (modalityType == Dialog.ModalityType.MODELESS) || 739 (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) || 740 (modalityType == Dialog.ModalityType.APPLICATION_MODAL) || 741 (modalityType == Dialog.ModalityType.TOOLKIT_MODAL); 742 } 743 744 @Override 745 public boolean isWindowShapingSupported() { 746 return true; 747 } 748 749 @Override 750 public boolean isWindowTranslucencySupported() { 751 return true; 752 } 753 754 @Override 755 public boolean isTranslucencyCapable(GraphicsConfiguration gc) { 756 return true; 757 } 758 759 public boolean isSwingBackbufferTranslucencySupported() { 760 return true; 761 } 762 763 @Override 764 public boolean enableInputMethodsForTextComponent() { 765 return true; 766 } 767 }