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