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