src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java

Print this page




  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.im.spi.InputMethodDescriptor;
  37 import java.awt.peer.*;
  38 import java.lang.reflect.*;
  39 import java.net.URL;
  40 import java.security.*;
  41 import java.util.*;
  42 import java.util.concurrent.Callable;
  43 import java.net.MalformedURLException;
  44 
  45 import sun.awt.*;
  46 import sun.awt.datatransfer.DataTransferer;

  47 import sun.java2d.opengl.OGLRenderQueue;
  48 import sun.lwawt.*;
  49 import sun.lwawt.LWWindowPeer.PeerType;
  50 import sun.security.action.GetBooleanAction;
  51 
  52 import sun.util.CoreResourceBundleControl;
  53 
  54 @SuppressWarnings("serial") // JDK implementation class
  55 final class NamedCursor extends Cursor {
  56     NamedCursor(String name) {
  57         super(name);
  58     }
  59 }
  60 
  61 /**
  62  * Mac OS X Cocoa-based AWT Toolkit.
  63  */
  64 public final class LWCToolkit extends LWToolkit {
  65     // While it is possible to enumerate all mouse devices
  66     // and query them for the number of buttons, the code
  67     // that does it is rather complex. Instead, we opt for
  68     // the easy way and just support up to 5 mouse buttons,
  69     // like Windows.
  70     private static final int BUTTONS = 5;
  71 
  72     private static native void initIDs();
  73 
  74     private static CInputMethodDescriptor sInputMethodDescriptor;
  75 
  76     static {
  77         System.err.flush();
  78 
  79         ResourceBundle platformResources = java.security.AccessController.doPrivileged(
  80                 new java.security.PrivilegedAction<ResourceBundle>() {
  81             @Override
  82             public ResourceBundle run() {
  83                 ResourceBundle platformResources = null;
  84                 try {
  85                     platformResources =
  86                             ResourceBundle.getBundle("sun.awt.resources.awtosx",
  87                                     CoreResourceBundleControl.getRBControlInstance());
  88                 } catch (MissingResourceException e) {
  89                     // No resource file; defaults will be used.
  90                 }
  91 
  92                 System.loadLibrary("awt");
  93                 System.loadLibrary("fontmanager");


 102             initIDs();
 103         }
 104         inAWT = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
 105             @Override
 106             public Boolean run() {
 107                 return !Boolean.parseBoolean(System.getProperty("javafx.embed.singleThread", "false"));
 108             }
 109         });
 110     }
 111 
 112     /*
 113      * If true  we operate in normal mode and nested runloop is executed in JavaRunLoopMode
 114      * If false we operate in singleThreaded FX/AWT interop mode and nested loop uses NSDefaultRunLoopMode
 115      */
 116     private static final boolean inAWT;
 117 
 118     public LWCToolkit() {
 119         areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 120         //set system property if not yet assigned
 121         System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);

 122     }
 123 
 124     /*
 125      * System colors with default initial values, overwritten by toolkit if system values differ and are available.
 126      */
 127     private final static int NUM_APPLE_COLORS = 3;
 128     public final static int KEYBOARD_FOCUS_COLOR = 0;
 129     public final static int INACTIVE_SELECTION_BACKGROUND_COLOR = 1;
 130     public final static int INACTIVE_SELECTION_FOREGROUND_COLOR = 2;
 131     private static int[] appleColors = {
 132         0xFF808080, // keyboardFocusColor = Color.gray;
 133         0xFFC0C0C0, // secondarySelectedControlColor
 134         0xFF303030, // controlDarkShadowColor
 135     };
 136 
 137     private native void loadNativeColors(final int[] systemColors, final int[] appleColors);
 138 
 139     @Override
 140     protected void loadSystemColors(final int[] systemColors) {
 141         if (systemColors == null) return;


 149             super(appleColors[index]);
 150             this.index = index;
 151         }
 152 
 153         @Override
 154         public int getRGB() {
 155             return appleColors[index];
 156         }
 157     }
 158 
 159     /**
 160      * Returns Apple specific colors that we may expose going forward.
 161      */
 162     public static Color getAppleColor(int color) {
 163         return new AppleSpecificColor(color);
 164     }
 165 
 166     // This is only called from native code.
 167     static void systemColorsChanged() {
 168         EventQueue.invokeLater(() -> {
 169             AccessController.doPrivileged ((PrivilegedAction<Object>) () -> {
 170                 AWTAccessor.getSystemColorAccessor().updateSystemColors();
 171                 return null;
 172             });
 173         });
 174     }
 175 
 176     public static LWCToolkit getLWCToolkit() {
 177         return (LWCToolkit)Toolkit.getDefaultToolkit();
 178     }
 179 
 180     @Override
 181     protected PlatformWindow createPlatformWindow(PeerType peerType) {
 182         if (peerType == PeerType.EMBEDDED_FRAME) {
 183             return new CPlatformEmbeddedFrame();
 184         } else if (peerType == PeerType.VIEW_EMBEDDED_FRAME) {
 185             return new CViewPlatformEmbeddedFrame();
 186         } else if (peerType == PeerType.LW_FRAME) {
 187             return new CPlatformLWWindow();
 188         } else {
 189             assert (peerType == PeerType.SIMPLEWINDOW




  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.im.spi.InputMethodDescriptor;
  37 import java.awt.peer.*;
  38 import java.lang.reflect.*;
  39 import java.net.URL;
  40 import java.security.*;
  41 import java.util.*;
  42 import java.util.concurrent.Callable;
  43 import java.net.MalformedURLException;
  44 
  45 import sun.awt.*;
  46 import sun.awt.datatransfer.DataTransferer;
  47 import sun.awt.util.ThreadGroupUtils;
  48 import sun.java2d.opengl.OGLRenderQueue;
  49 import sun.lwawt.*;
  50 import sun.lwawt.LWWindowPeer.PeerType;
  51 import sun.security.action.GetBooleanAction;
  52 
  53 import sun.util.CoreResourceBundleControl;
  54 
  55 @SuppressWarnings("serial") // JDK implementation class
  56 final class NamedCursor extends Cursor {
  57     NamedCursor(String name) {
  58         super(name);
  59     }
  60 }
  61 
  62 /**
  63  * Mac OS X Cocoa-based AWT Toolkit.
  64  */
  65 public final class LWCToolkit extends LWToolkit {
  66     // While it is possible to enumerate all mouse devices
  67     // and query them for the number of buttons, the code
  68     // that does it is rather complex. Instead, we opt for
  69     // the easy way and just support up to 5 mouse buttons,
  70     // like Windows.
  71     private static final int BUTTONS = 5;
  72 
  73     private static native void initIDs();
  74     private static native void initAppkit(ThreadGroup appKitThreadGroup, boolean headless);
  75     private static CInputMethodDescriptor sInputMethodDescriptor;
  76 
  77     static {
  78         System.err.flush();
  79 
  80         ResourceBundle platformResources = java.security.AccessController.doPrivileged(
  81                 new java.security.PrivilegedAction<ResourceBundle>() {
  82             @Override
  83             public ResourceBundle run() {
  84                 ResourceBundle platformResources = null;
  85                 try {
  86                     platformResources =
  87                             ResourceBundle.getBundle("sun.awt.resources.awtosx",
  88                                     CoreResourceBundleControl.getRBControlInstance());
  89                 } catch (MissingResourceException e) {
  90                     // No resource file; defaults will be used.
  91                 }
  92 
  93                 System.loadLibrary("awt");
  94                 System.loadLibrary("fontmanager");


 103             initIDs();
 104         }
 105         inAWT = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
 106             @Override
 107             public Boolean run() {
 108                 return !Boolean.parseBoolean(System.getProperty("javafx.embed.singleThread", "false"));
 109             }
 110         });
 111     }
 112 
 113     /*
 114      * If true  we operate in normal mode and nested runloop is executed in JavaRunLoopMode
 115      * If false we operate in singleThreaded FX/AWT interop mode and nested loop uses NSDefaultRunLoopMode
 116      */
 117     private static final boolean inAWT;
 118 
 119     public LWCToolkit() {
 120         areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
 121         //set system property if not yet assigned
 122         System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
 123         initAppkit(ThreadGroupUtils.getRootThreadGroup(), GraphicsEnvironment.isHeadless());
 124     }
 125 
 126     /*
 127      * System colors with default initial values, overwritten by toolkit if system values differ and are available.
 128      */
 129     private final static int NUM_APPLE_COLORS = 3;
 130     public final static int KEYBOARD_FOCUS_COLOR = 0;
 131     public final static int INACTIVE_SELECTION_BACKGROUND_COLOR = 1;
 132     public final static int INACTIVE_SELECTION_FOREGROUND_COLOR = 2;
 133     private static int[] appleColors = {
 134         0xFF808080, // keyboardFocusColor = Color.gray;
 135         0xFFC0C0C0, // secondarySelectedControlColor
 136         0xFF303030, // controlDarkShadowColor
 137     };
 138 
 139     private native void loadNativeColors(final int[] systemColors, final int[] appleColors);
 140 
 141     @Override
 142     protected void loadSystemColors(final int[] systemColors) {
 143         if (systemColors == null) return;


 151             super(appleColors[index]);
 152             this.index = index;
 153         }
 154 
 155         @Override
 156         public int getRGB() {
 157             return appleColors[index];
 158         }
 159     }
 160 
 161     /**
 162      * Returns Apple specific colors that we may expose going forward.
 163      */
 164     public static Color getAppleColor(int color) {
 165         return new AppleSpecificColor(color);
 166     }
 167 
 168     // This is only called from native code.
 169     static void systemColorsChanged() {
 170         EventQueue.invokeLater(() -> {
 171             AccessController.doPrivileged( (PrivilegedAction<Object>) () -> {
 172                 AWTAccessor.getSystemColorAccessor().updateSystemColors();
 173                 return null;
 174             });
 175         });
 176     }
 177 
 178     public static LWCToolkit getLWCToolkit() {
 179         return (LWCToolkit)Toolkit.getDefaultToolkit();
 180     }
 181 
 182     @Override
 183     protected PlatformWindow createPlatformWindow(PeerType peerType) {
 184         if (peerType == PeerType.EMBEDDED_FRAME) {
 185             return new CPlatformEmbeddedFrame();
 186         } else if (peerType == PeerType.VIEW_EMBEDDED_FRAME) {
 187             return new CViewPlatformEmbeddedFrame();
 188         } else if (peerType == PeerType.LW_FRAME) {
 189             return new CPlatformLWWindow();
 190         } else {
 191             assert (peerType == PeerType.SIMPLEWINDOW