6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
authortdv
Fri, 12 Sep 2008 15:01:45 -0700
changeset 1724 a22a286aa16f
parent 1723 4a616c1eac0b
child 1725 3be564c67d63
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal Reviewed-by: prr, tdv Contributed-by: rkennke@kennke.org
jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
jdk/src/share/classes/sun/swing/SwingUtilities2.java
jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
jdk/src/solaris/native/sun/awt/fontpath.c
jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
--- a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Fri Sep 12 15:01:45 2008 -0700
@@ -1272,6 +1272,13 @@
         displayChanger.notifyPaletteChanged();
     }
 
+    /**
+     * Returns true when the display is local, false for remote displays.
+     *
+     * @return true when the display is local, false for remote displays
+     */
+    public abstract boolean isDisplayLocal();
+
     /*
      * ----DISPLAY CHANGE SUPPORT----
      */
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java	Fri Sep 12 15:01:45 2008 -0700
@@ -55,6 +55,7 @@
 import java.util.*;
 import sun.font.FontDesignMetrics;
 import sun.font.FontManager;
+import sun.java2d.SunGraphicsEnvironment;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
@@ -1482,22 +1483,14 @@
      * appear capable of performing gamma correction needed for LCD text.
      */
     public static boolean isLocalDisplay() {
-        try {
-            // On Windows just return true. Permission to read os.name
-            // is granted to all code but wrapped in try to be safe.
-            if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
-                return true;
-            }
-            // Else probably Solaris or Linux in which case may be remote X11
-            Class x11Class = Class.forName("sun.awt.X11GraphicsEnvironment");
-            Method isDisplayLocalMethod = x11Class.getMethod(
-                      "isDisplayLocal", new Class[0]);
-            return (Boolean)isDisplayLocalMethod.invoke(null, (Object[])null);
-        } catch (Throwable t) {
+        boolean isLocal;
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        if (ge instanceof SunGraphicsEnvironment) {
+            isLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
+        } else {
+            isLocal = true;
         }
-        // If we get here we're most likely being run on some other O/S
-        // or we didn't properly detect Windows.
-        return true;
+        return isLocal;
     }
 
     /**
--- a/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Fri Sep 12 15:01:45 2008 -0700
@@ -209,7 +209,7 @@
     private static native int checkShmExt();
 
     private static  native String getDisplayString();
-    private static Boolean isDisplayLocal;
+    private Boolean isDisplayLocal;
 
     /**
      * This should only be called from the static initializer, so no need for
@@ -234,7 +234,8 @@
         return getScreenDevices()[getDefaultScreenNum()];
     }
 
-    public static boolean isDisplayLocal() {
+    @Override
+    public boolean isDisplayLocal() {
         if (isDisplayLocal == null) {
             SunToolkit.awtLock();
             try {
--- a/jdk/src/solaris/native/sun/awt/fontpath.c	Thu Aug 28 11:27:14 2008 -0700
+++ b/jdk/src/solaris/native/sun/awt/fontpath.c	Fri Sep 12 15:01:45 2008 -0700
@@ -156,7 +156,7 @@
 
     isLocal = JNU_CallStaticMethodByName(env, NULL,
                                          "sun/awt/X11GraphicsEnvironment",
-                                         "isDisplayLocal",
+                                         "_isDisplayLocal",
                                          "()Z").z;
     isLocalSet = True;
     return isLocal;
--- a/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Fri Sep 12 15:01:45 2008 -0700
@@ -393,4 +393,9 @@
     private static void dwmCompositionChanged(boolean enabled) {
         isDWMCompositionEnabled = enabled;
     }
+
+    @Override
+    public boolean isDisplayLocal() {
+        return true;
+    }
 }