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