Bah, forgot the actual patch. Here it comes now!
/Roman
Am Montag, den 08.09.2008, 21:04 +0200 schrieb Roman Kennke:
> Hi Oleg and lists,
>
> > >> I'm not the person who is supposed to review this changes from
> > >> technical point of view,
> > >> but I have one concern about idea of the fix. It adds one more place
> > >> where Swing uses sun-specific API.
> > >
> > > No. It takes advantage of Sun internal API, but it does not depend on
> > > it. (if (ge instanceof SunGraphicsEnvironment) { doSomethingCool(); }
> > > else { useReasonableDefault(); } ).
> >
> > it uses Sun-specific class, so this code can not be compiled by JDK
> > from another vendor :(
>
> Ehe :-) Try compiling Swing on any JDK from another vendor! Good luck!
> (Ok, the Caciocavallo project will certainly help alot, but we are still
> very far away from such a portable Swing).
>
> > >> Of course you can say that SwingUtilities2.isLocalDisplay() even
> > >> before your fix uses code which is specific
> > >> for Sun's implementation, and you will be right. But this doesn't
> > >> mean that we should leave with this.
> > >> IMHO, if we change such code we should remove dependency between Swing
> > >> and Sun-specific code,
> > >> i.e. we should add public API.
> > >
> > > I completely agree. That, of course, would be the best solution. But in
> > > the past it has been communicated several times to me that I can't just
> > > send in patches to public API and hope that it will be accepted easily.
> > > I propose to get in this patch if possible first, then start a
> > > discussion about adding public API.
> >
> > I understand your point, but I have a feeling that we you will not
> > start the discussion right now,
> > the idea of new API may be lost :( So, I'd suggest to try one more time ;)
>
> Ok, so here we go. This patch is slightly modified, the isDisplayLocal()
> method is now declared in GraphicsEnvironment, with the addition of
> throwing a HeadlessException in the headless case. Also, in fontpath.c,
> we don't call isDisplayLocal(), but instead call _isDisplayLocal(). We
> call it on X11GraphicsEnvironment only. In my original patch I tried to
> be more portable by calling
> GraphicsEnvironment.getLocalGraphicsEnvironment().isDisplayLocal(), but
> this resulted in an initialization loop (this code is very sensible to
> this kind of problem). I left that out for now, because fontpath.c is
> X11 specific anyway, and a real solution will come soon in the form of a
> huge FontManager patch :-)
>
> What do you think? Can we add this API to GE?
>
> /Roman
>
--
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-48
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
diff -r 7e10774d2a29 src/share/classes/java/awt/GraphicsEnvironment.java
--- a/src/share/classes/java/awt/GraphicsEnvironment.java Thu Aug 07 09:42:31 2008 -0700
+++ b/src/share/classes/java/awt/GraphicsEnvironment.java Mon Sep 08 20:58:03 2008 +0200
@@ -422,4 +422,18 @@
// device. This is correct for Microsoft Windows and non-Xinerama X11.
return SunGraphicsEnvironment.getUsableBounds(getDefaultScreenDevice());
}
+
+ /**
+ * Returns <code>true</code> when the display is local, <code>false</code>
+ * for remote displays.
+ *
+ * @return <code>true</code> when the display is local, <code>false</code>
+ * for remote displays
+ *
+ * @throws HeadlessException for headless graphics environments
+ *
+ * @since 1.7
+ */
+ public abstract boolean isDisplayLocal() throws HeadlessException;
+
}
diff -r 7e10774d2a29 src/share/classes/sun/java2d/HeadlessGraphicsEnvironment.java
--- a/src/share/classes/sun/java2d/HeadlessGraphicsEnvironment.java Thu Aug 07 09:42:31 2008 -0700
+++ b/src/share/classes/sun/java2d/HeadlessGraphicsEnvironment.java Mon Sep 08 20:58:03 2008 +0200
@@ -112,4 +112,8 @@
public GraphicsEnvironment getSunGraphicsEnvironment() {
return ge;
}
+
+ public boolean isDisplayLocal() {
+ throw new HeadlessException();
+ }
}
diff -r 7e10774d2a29 src/share/classes/sun/swing/SwingUtilities2.java
--- a/src/share/classes/sun/swing/SwingUtilities2.java Thu Aug 07 09:42:31 2008 -0700
+++ b/src/share/classes/sun/swing/SwingUtilities2.java Mon Sep 08 20:58:03 2008 +0200
@@ -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,9 @@
* 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) {
- }
- // If we get here we're most likely being run on some other O/S
- // or we didn't properly detect Windows.
- return true;
+
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ return ge.isDisplayLocal();
}
/**
diff -r 7e10774d2a29 src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
--- a/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java Thu Aug 07 09:42:31 2008 -0700
+++ b/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java Mon Sep 08 20:58:03 2008 +0200
@@ -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,7 @@
return getScreenDevices()[getDefaultScreenNum()];
}
- public static boolean isDisplayLocal() {
+ public boolean isDisplayLocal() {
if (isDisplayLocal == null) {
SunToolkit.awtLock();
try {
diff -r 7e10774d2a29 src/solaris/native/sun/awt/fontpath.c
--- a/src/solaris/native/sun/awt/fontpath.c Thu Aug 07 09:42:31 2008 -0700
+++ b/src/solaris/native/sun/awt/fontpath.c Mon Sep 08 20:58:03 2008 +0200
@@ -156,7 +156,7 @@
isLocal = JNU_CallStaticMethodByName(env, NULL,
"sun/awt/X11GraphicsEnvironment",
- "isDisplayLocal",
+ "_isDisplayLocal",
"()Z").z;
isLocalSet = True;
return isLocal;
diff -r 7e10774d2a29 src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
--- a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Thu Aug 07 09:42:31 2008 -0700
+++ b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Mon Sep 08 20:58:03 2008 +0200
@@ -393,4 +393,8 @@
private static void dwmCompositionChanged(boolean enabled) {
isDWMCompositionEnabled = enabled;
}
+
+ public boolean isDisplayLocal() {
+ return true;
+ }
}