518 * <p>
519 * Menu shortcuts, which are embodied in the
520 * {@code MenuShortcut} class, are handled by the
521 * {@code MenuBar} class.
522 * <p>
523 * By default, this method returns {@code Event.CTRL_MASK}.
524 * Toolkit implementations should override this method if the
525 * <b>Control</b> key isn't the correct key for accelerators.
526 * @return the modifier mask on the {@code Event} class
527 * that is used for menu shortcuts on this toolkit.
528 * @see java.awt.MenuBar
529 * @see java.awt.MenuShortcut
530 * @since 1.1
531 */
532 @Override
533 public int getMenuShortcutKeyMask() {
534 return Event.META_MASK;
535 }
536
537 @Override
538 public Image getImage(final String filename) {
539 final Image nsImage = checkForNSImage(filename);
540 if (nsImage != null) {
541 return nsImage;
542 }
543
544 if (imageCached(filename)) {
545 return super.getImage(filename);
546 }
547
548 String filename2x = getScaledImageName(filename);
549 return (imageExists(filename2x))
550 ? getImageWithResolutionVariant(filename, filename2x)
551 : super.getImage(filename);
552 }
553
554 @Override
555 public Image getImage(URL url) {
556
557 if (imageCached(url)) {
558 return super.getImage(url);
559 }
560
561 URL url2x = getScaledImageURL(url);
562 return (imageExists(url2x))
563 ? getImageWithResolutionVariant(url, url2x) : super.getImage(url);
564 }
565
566 private static final String nsImagePrefix = "NSImage://";
567 private Image checkForNSImage(final String imageName) {
568 if (imageName == null) return null;
569 if (!imageName.startsWith(nsImagePrefix)) return null;
570 return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
571 }
572
573 // Thread-safe Object.equals() called from native
574 public static boolean doEquals(final Object a, final Object b, Component c) {
575 if (a == b) return true;
576
577 final boolean[] ret = new boolean[1];
578
579 try { invokeAndWait(new Runnable() { @Override
580 public void run() { synchronized(ret) {
581 ret[0] = a.equals(b);
582 }}}, c); } catch (Exception e) { e.printStackTrace(); }
583
584 synchronized(ret) { return ret[0]; }
585 }
879 @Override
880 public boolean isWindowTranslucencySupported() {
881 return true;
882 }
883
884 @Override
885 public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
886 return true;
887 }
888
889 @Override
890 public boolean isSwingBackbufferTranslucencySupported() {
891 return true;
892 }
893
894 @Override
895 public boolean enableInputMethodsForTextComponent() {
896 return true;
897 }
898
899 private static URL getScaledImageURL(URL url) {
900 try {
901 String scaledImagePath = getScaledImageName(url.getPath());
902 return scaledImagePath == null ? null : new URL(url.getProtocol(),
903 url.getHost(), url.getPort(), scaledImagePath);
904 } catch (MalformedURLException e) {
905 return null;
906 }
907 }
908
909 private static String getScaledImageName(String path) {
910 if (!isValidPath(path)) {
911 return null;
912 }
913
914 int slash = path.lastIndexOf('/');
915 String name = (slash < 0) ? path : path.substring(slash + 1);
916
917 if (name.contains("@2x")) {
918 return null;
919 }
920
921 int dot = name.lastIndexOf('.');
922 String name2x = (dot < 0) ? name + "@2x"
923 : name.substring(0, dot) + "@2x" + name.substring(dot);
924 return (slash < 0) ? name2x : path.substring(0, slash + 1) + name2x;
925 }
926
927 private static boolean isValidPath(String path) {
928 return path != null &&
929 !path.isEmpty() &&
930 !path.endsWith("/") &&
931 !path.endsWith(".");
932 }
933
934 @Override
935 protected PlatformWindow getPlatformWindowUnderMouse() {
936 return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
937 }
938 }
|
518 * <p>
519 * Menu shortcuts, which are embodied in the
520 * {@code MenuShortcut} class, are handled by the
521 * {@code MenuBar} class.
522 * <p>
523 * By default, this method returns {@code Event.CTRL_MASK}.
524 * Toolkit implementations should override this method if the
525 * <b>Control</b> key isn't the correct key for accelerators.
526 * @return the modifier mask on the {@code Event} class
527 * that is used for menu shortcuts on this toolkit.
528 * @see java.awt.MenuBar
529 * @see java.awt.MenuShortcut
530 * @since 1.1
531 */
532 @Override
533 public int getMenuShortcutKeyMask() {
534 return Event.META_MASK;
535 }
536
537 @Override
538 public Image getImage(String filename) {
539 final Image nsImage = checkForNSImage(filename);
540 if (nsImage != null) {
541 return nsImage;
542 }
543
544 return super.getImage(filename);
545 }
546
547 private static final String nsImagePrefix = "NSImage://";
548 private Image checkForNSImage(final String imageName) {
549 if (imageName == null) return null;
550 if (!imageName.startsWith(nsImagePrefix)) return null;
551 return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
552 }
553
554 // Thread-safe Object.equals() called from native
555 public static boolean doEquals(final Object a, final Object b, Component c) {
556 if (a == b) return true;
557
558 final boolean[] ret = new boolean[1];
559
560 try { invokeAndWait(new Runnable() { @Override
561 public void run() { synchronized(ret) {
562 ret[0] = a.equals(b);
563 }}}, c); } catch (Exception e) { e.printStackTrace(); }
564
565 synchronized(ret) { return ret[0]; }
566 }
860 @Override
861 public boolean isWindowTranslucencySupported() {
862 return true;
863 }
864
865 @Override
866 public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
867 return true;
868 }
869
870 @Override
871 public boolean isSwingBackbufferTranslucencySupported() {
872 return true;
873 }
874
875 @Override
876 public boolean enableInputMethodsForTextComponent() {
877 return true;
878 }
879
880 @Override
881 protected PlatformWindow getPlatformWindowUnderMouse() {
882 return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
883 }
884 }
|