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