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 = new InvocationEvent(Toolkit.getDefaultToolkit(), event) { 534 @Override 535 public void dispatch() { 536 try { 537 super.dispatch(); 538 } finally { 539 if (mediator != 0) { 540 stopAWTRunLoop(mediator); 541 } 542 } 543 } 544 }; 545 546 if (component != null) { 547 AppContext appContext = SunToolkit.targetToAppContext(component); 548 SunToolkit.postEvent(appContext, invocationEvent); 549 550 // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock 551 SunToolkit.flushPendingEvents(appContext); 552 } else { 553 // This should be the equivalent to EventQueue.invokeAndWait 554 ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent); 555 } 556 557 doAWTRunLoop(mediator, false); 558 559 Throwable eventException = invocationEvent.getException(); 560 if (eventException != null) { 561 if (eventException instanceof UndeclaredThrowableException) { 562 eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable(); 563 } 564 throw new InvocationTargetException(eventException); 565 } 566 } 567 568 public static void invokeLater(Runnable event, Component component) throws InvocationTargetException { 569 final InvocationEvent invocationEvent = new InvocationEvent(Toolkit.getDefaultToolkit(), event); 570 571 if (component != null) { 572 final AppContext appContext = SunToolkit.targetToAppContext(component); 573 SunToolkit.postEvent(appContext, invocationEvent); 574 575 // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock 576 SunToolkit.flushPendingEvents(appContext); 577 } else { 578 // This should be the equivalent to EventQueue.invokeAndWait 579 ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent); 580 } 581 582 final Throwable eventException = invocationEvent.getException(); 583 if (eventException == null) return; 584 585 if (eventException instanceof UndeclaredThrowableException) { 586 throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable()); 587 } 588 throw new InvocationTargetException(eventException); 589 } 590 591 // This exists purely to get around permissions issues with getSystemEventQueueImpl 592 EventQueue getSystemEventQueueForInvokeAndWait() { 593 return getSystemEventQueueImpl(); 594 } 595 596 597 // DnD support 598 599 public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { 600 DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge); 601 602 return dscp; 603 } 604 605 public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { 606 DragGestureRecognizer dgr = null; 607 608 // Create a new mouse drag gesture recognizer if we have a class match: 609 if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass)) 610 dgr = new CMouseDragGestureRecognizer(ds, c, srcActions, dgl); 611 612 return (T)dgr; 613 } 614 615 // InputMethodSupport Method 616 /** 617 * Returns the default keyboard locale of the underlying operating system 618 */ 619 public Locale getDefaultKeyboardLocale() { 620 Locale locale = CInputMethod.getNativeLocale(); 621 622 if (locale == null) { 623 return super.getDefaultKeyboardLocale(); 624 } 625 626 return locale; 627 } 628 629 public java.awt.im.spi.InputMethodDescriptor getInputMethodAdapterDescriptor() { 630 if (sInputMethodDescriptor == null) 631 sInputMethodDescriptor = new CInputMethodDescriptor(); 632 633 return sInputMethodDescriptor; 634 } 635 636 /** 637 * Returns a map of visual attributes for thelevel description 638 * of the given input method highlight, or null if no mapping is found. 639 * The style field of the input method highlight is ignored. The map 640 * returned is unmodifiable. 641 * @param highlight input method highlight 642 * @return style attribute map, or null 643 * @since 1.3 644 */ 645 public Map mapInputMethodHighlight(InputMethodHighlight highlight) { 646 return CInputMethod.mapInputMethodHighlight(highlight); 647 } 648 649 /** 650 * Returns key modifiers used by Swing to set up a focus accelerator key stroke. 651 */ 652 @Override 653 public int getFocusAcceleratorKeyMask() { 654 return InputEvent.CTRL_MASK | InputEvent.ALT_MASK; 655 } 656 657 /** 658 * Tests whether specified key modifiers mask can be used to enter a printable 659 * character. 660 */ 661 @Override 662 public boolean isPrintableCharacterModifiersMask(int mods) { 663 return ((mods & (InputEvent.META_MASK | InputEvent.CTRL_MASK)) == 0); 664 } 665 666 /** 667 * Returns whether popup is allowed to be shown above the task bar. 668 */ 669 @Override 670 public boolean canPopupOverlapTaskBar() { 671 return false; 672 } 673 674 private static Boolean sunAwtDisableCALayers = null; 675 676 /** 677 * Returns the value of "sun.awt.disableCALayers" property. Default 678 * value is {@code false}. 679 */ 680 public synchronized static boolean getSunAwtDisableCALayers() { 681 if (sunAwtDisableCALayers == null) { 682 sunAwtDisableCALayers = AccessController.doPrivileged( 683 new GetBooleanAction("sun.awt.disableCALayers")); 684 } 685 return sunAwtDisableCALayers.booleanValue(); 686 } 687 688 689 /* 690 * Returns true if the application (one of its windows) owns keyboard focus. 691 */ 692 public native boolean isApplicationActive(); 693 694 /************************ 695 * Native methods section 696 ************************/ 697 698 static native long createAWTRunLoopMediator(); 699 /** 700 * Method to run a nested runloop. 701 * @param mediator a native pointer to the mediator object created by createAWTRunLoopMediator 702 * @param processEvents if true - dispatches event while in the nested loop. 703 * if false - all events come after exit form the nested loop 704 */ 705 static native void doAWTRunLoop(long mediator, boolean processEvents); 706 static native void stopAWTRunLoop(long mediator); 707 708 private native boolean nativeSyncQueue(long timeout); 709 710 @Override 711 public Clipboard createPlatformClipboard() { 712 return new CClipboard("System"); 713 } 714 715 @Override 716 public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) { 717 return (exclusionType == null) || 718 (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) || 719 (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) || 720 (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE); 721 } 722 723 @Override 724 public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { 725 //TODO: FileDialog blocks excluded windows... 726 //TODO: Test: 2 file dialogs, separate AppContexts: a) Dialog 1 blocked, shouldn't be. Frame 4 blocked (shouldn't be). 727 return (modalityType == null) || 728 (modalityType == Dialog.ModalityType.MODELESS) || 729 (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) || 730 (modalityType == Dialog.ModalityType.APPLICATION_MODAL) || 731 (modalityType == Dialog.ModalityType.TOOLKIT_MODAL); 732 } 733 734 @Override 735 public boolean isWindowShapingSupported() { 736 return true; 737 } 738 739 @Override 740 public boolean isWindowTranslucencySupported() { 741 return true; 742 } 743 744 @Override 745 public boolean isTranslucencyCapable(GraphicsConfiguration gc) { 746 return true; 747 } 748 749 public boolean isSwingBackbufferTranslucencySupported() { 750 return true; 751 } 752 753 @Override 754 public boolean enableInputMethodsForTextComponent() { 755 return true; 756 } 757 }