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 import sun.util.CoreResourceBundleControl;
48
49 class NamedCursor extends Cursor {
50 NamedCursor(String name) {
51 super(name);
52 }
53 }
54
55 /**
56 * Mac OS X Cocoa-based AWT Toolkit.
57 */
58 public final class LWCToolkit extends LWToolkit {
59 // While it is possible to enumerate all mouse devices
60 // and query them for the number of buttons, the code
61 // that does it is rather complex. Instead, we opt for
62 // the easy way and just support up to 5 mouse buttons,
63 // like Windows.
64 private static final int BUTTONS = 5;
65
472 * Menu shortcuts, which are embodied in the
473 * <code>MenuShortcut</code> class, are handled by the
474 * <code>MenuBar</code> class.
475 * <p>
476 * By default, this method returns <code>Event.CTRL_MASK</code>.
477 * Toolkit implementations should override this method if the
478 * <b>Control</b> key isn't the correct key for accelerators.
479 * @return the modifier mask on the <code>Event</code> class
480 * that is used for menu shortcuts on this toolkit.
481 * @see java.awt.MenuBar
482 * @see java.awt.MenuShortcut
483 * @since JDK1.1
484 */
485 public int getMenuShortcutKeyMask() {
486 return Event.META_MASK;
487 }
488
489 @Override
490 public Image getImage(final String filename) {
491 final Image nsImage = checkForNSImage(filename);
492 if (nsImage != null) return nsImage;
493
494 return super.getImage(filename);
495 }
496
497 static final String nsImagePrefix = "NSImage://";
498 protected Image checkForNSImage(final String imageName) {
499 if (imageName == null) return null;
500 if (!imageName.startsWith(nsImagePrefix)) return null;
501 return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
502 }
503
504 // Thread-safe Object.equals() called from native
505 public static boolean doEquals(final Object a, final Object b, Component c) {
506 if (a == b) return true;
507
508 final boolean[] ret = new boolean[1];
509
510 try { invokeAndWait(new Runnable() { public void run() { synchronized(ret) {
511 ret[0] = a.equals(b);
512 }}}, c); } catch (Exception e) { e.printStackTrace(); }
513
514 synchronized(ret) { return ret[0]; }
515 }
516
764 }
765
766 @Override
767 public boolean isWindowTranslucencySupported() {
768 return true;
769 }
770
771 @Override
772 public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
773 return true;
774 }
775
776 public boolean isSwingBackbufferTranslucencySupported() {
777 return true;
778 }
779
780 @Override
781 public boolean enableInputMethodsForTextComponent() {
782 return true;
783 }
784 }
|
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.net.URL;
39 import java.security.*;
40 import java.util.*;
41 import java.util.concurrent.Callable;
42 import java.net.MalformedURLException;
43
44 import sun.awt.*;
45 import sun.lwawt.*;
46 import sun.lwawt.LWWindowPeer.PeerType;
47 import sun.security.action.GetBooleanAction;
48 import sun.awt.image.MultiResolutionImage;
49
50 import sun.util.CoreResourceBundleControl;
51
52 class NamedCursor extends Cursor {
53 NamedCursor(String name) {
54 super(name);
55 }
56 }
57
58 /**
59 * Mac OS X Cocoa-based AWT Toolkit.
60 */
61 public final class LWCToolkit extends LWToolkit {
62 // While it is possible to enumerate all mouse devices
63 // and query them for the number of buttons, the code
64 // that does it is rather complex. Instead, we opt for
65 // the easy way and just support up to 5 mouse buttons,
66 // like Windows.
67 private static final int BUTTONS = 5;
68
475 * Menu shortcuts, which are embodied in the
476 * <code>MenuShortcut</code> class, are handled by the
477 * <code>MenuBar</code> class.
478 * <p>
479 * By default, this method returns <code>Event.CTRL_MASK</code>.
480 * Toolkit implementations should override this method if the
481 * <b>Control</b> key isn't the correct key for accelerators.
482 * @return the modifier mask on the <code>Event</code> class
483 * that is used for menu shortcuts on this toolkit.
484 * @see java.awt.MenuBar
485 * @see java.awt.MenuShortcut
486 * @since JDK1.1
487 */
488 public int getMenuShortcutKeyMask() {
489 return Event.META_MASK;
490 }
491
492 @Override
493 public Image getImage(final String filename) {
494 final Image nsImage = checkForNSImage(filename);
495 if (nsImage != null) {
496 return nsImage;
497 }
498
499 if (imageCached(filename)) {
500 return super.getImage(filename);
501 }
502
503 String fileneame2x = getScaledImageName(filename);
504 return (imageExists(fileneame2x))
505 ? getImageWithResolutionVariant(filename, fileneame2x)
506 : super.getImage(filename);
507 }
508
509 @Override
510 public Image getImage(URL url) {
511
512 if (imageCached(url)) {
513 return super.getImage(url);
514 }
515
516 URL url2x = getScaledImageURL(url);
517 return (imageExists(url2x))
518 ? getImageWithResolutionVariant(url, url2x) : super.getImage(url);
519 }
520
521 static final String nsImagePrefix = "NSImage://";
522 protected Image checkForNSImage(final String imageName) {
523 if (imageName == null) return null;
524 if (!imageName.startsWith(nsImagePrefix)) return null;
525 return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
526 }
527
528 // Thread-safe Object.equals() called from native
529 public static boolean doEquals(final Object a, final Object b, Component c) {
530 if (a == b) return true;
531
532 final boolean[] ret = new boolean[1];
533
534 try { invokeAndWait(new Runnable() { public void run() { synchronized(ret) {
535 ret[0] = a.equals(b);
536 }}}, c); } catch (Exception e) { e.printStackTrace(); }
537
538 synchronized(ret) { return ret[0]; }
539 }
540
788 }
789
790 @Override
791 public boolean isWindowTranslucencySupported() {
792 return true;
793 }
794
795 @Override
796 public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
797 return true;
798 }
799
800 public boolean isSwingBackbufferTranslucencySupported() {
801 return true;
802 }
803
804 @Override
805 public boolean enableInputMethodsForTextComponent() {
806 return true;
807 }
808
809 private static URL getScaledImageURL(URL url) {
810 try {
811 String scaledImagePath = getScaledImageName(url.getPath());
812 return scaledImagePath == null ? null : new URL(url.getProtocol(),
813 url.getHost(), url.getPort(), scaledImagePath);
814 } catch (MalformedURLException e) {
815 return null;
816 }
817 }
818
819 private static String getScaledImageName(String path) {
820 if (!isValidPath(path)) {
821 return null;
822 }
823
824 int slash = path.lastIndexOf('/');
825 String name = (slash < 0) ? path : path.substring(slash + 1);
826
827 if (name.contains("@2x")) {
828 return null;
829 }
830
831 int dot = name.lastIndexOf('.');
832 String name2x = (dot < 0) ? name + "@2x"
833 : name.substring(0, dot) + "@2x" + name.substring(dot);
834 return (slash < 0) ? name2x : path.substring(0, slash + 1) + name2x;
835 }
836
837 private static boolean isValidPath(String path) {
838 return !path.isEmpty() && !path.endsWith("/") && !path.endsWith(".");
839 }
840 }
|