# HG changeset patch
# User tdv
# Date 1221256905 25200
# Node ID b8f91ea2fb33cdbbc177ab1f68170ce7966b5d7b
# Parent  cd88b4ad7f258f023f12ebcc3b5a01a826e9392d
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
Reviewed-by: prr, tdv
Contributed-by: rkennke@kennke.org

diff -r cd88b4ad7f25 -r b8f91ea2fb33 src/share/classes/sun/java2d/SunGraphicsEnvironment.java
--- openjdk.orig/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ openjdk/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----
      */
diff -r cd88b4ad7f25 -r b8f91ea2fb33 src/share/classes/sun/swing/SwingUtilities2.java
--- openjdk.orig/jdk/src/share/classes/sun/swing/SwingUtilities2.java	Thu Aug 28 11:27:14 2008 -0700
+++ openjdk/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;
     }
 
     /**
diff -r cd88b4ad7f25 -r b8f91ea2fb33 src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
--- openjdk.orig/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ openjdk/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 {
diff -r cd88b4ad7f25 -r b8f91ea2fb33 src/solaris/native/sun/awt/fontpath.c
--- openjdk.orig/jdk/src/solaris/native/sun/awt/fontpath.c	Thu Aug 28 11:27:14 2008 -0700
+++ openjdk/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;
diff -r cd88b4ad7f25 -r b8f91ea2fb33 src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
--- openjdk.orig/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Thu Aug 28 11:27:14 2008 -0700
+++ openjdk/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;
+    }
 }
exporting patch:
<fdopen>
