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