changeset 781:b8f91ea2fb33

6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal Reviewed-by: prr, tdv Contributed-by: rkennke@kennke.org
author tdv
date Fri, 12 Sep 2008 15:01:45 -0700
parents cd88b4ad7f25
children 41ff3f84cd96
files src/share/classes/sun/java2d/SunGraphicsEnvironment.java src/share/classes/sun/swing/SwingUtilities2.java src/solaris/classes/sun/awt/X11GraphicsEnvironment.java src/solaris/native/sun/awt/fontpath.c src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
diffstat 5 files changed, 24 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/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/src/share/classes/sun/swing/SwingUtilities2.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/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/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/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/src/solaris/native/sun/awt/fontpath.c	Thu Aug 28 11:27:14 2008 -0700
+++ b/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/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ b/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;
+    }
 }