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