A couple of fixes for the X peers. Basically, it disables the ClasspathToolkit method getLocalGraphicsEnvironment() and lets the GraphicsEnvironment class figure this out on its own via the system property java.awt.graphicsenv. This avoids two instances of that class.

2006-07-17  Roman Kennke  <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/x/XGraphicsEnvironment.java
        (XGraphicsEnvironment): Make constructor public so that it
        can be called via Class.forName().newInstance().
        * gnu/java/awt/peer/x/XImage.java
        (XImage): Fetch GraphicsEnvironment via
        GraphicsEnvironment.getLocalGraphicsEnvironment() rather
        than the XToolkit method, to avoid double instantiation
        of the XGraphicsEnvironment.
        * gnu/java/awt/peer/x/XToolkit.java
        (env): Removed field.
        (getLocalGraphicsEnvironment): Removed impl. This method
        should not be called since we set the graphicsenv property
        in the constructor.

/Roman
Index: gnu/java/awt/peer/x/XGraphicsEnvironment.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XGraphicsEnvironment.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 XGraphicsEnvironment.java
--- gnu/java/awt/peer/x/XGraphicsEnvironment.java	29 Jun 2006 15:15:56 -0000	1.1
+++ gnu/java/awt/peer/x/XGraphicsEnvironment.java	17 Jul 2006 08:24:09 -0000
@@ -71,25 +71,25 @@
 
   /**
    * All configured devices.
    */
   private XGraphicsDevice[] devices;
 
   /**
    * Creates a new XGraphicsEnvironment. This loads the configuration if
    * there is one present and initializes the XGraphicsDevices in the
    * environment. If there is no configuration, then there is one
    * default device initialized with the local main X device.
    */
-  XGraphicsEnvironment()
+  public XGraphicsEnvironment()
   {
     // Initiliaze the devices.
     Properties props = new Properties();
     File config = new File(System.getProperty("user.home"),
                            ".xawt.properties");
 
     try
       {
         FileInputStream configIn = new FileInputStream(config);
         props.load(configIn);
         int dev = 1;
         ArrayList deviceList = new ArrayList();
Index: gnu/java/awt/peer/x/XImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XImage.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 XImage.java
--- gnu/java/awt/peer/x/XImage.java	29 Jun 2006 15:15:56 -0000	1.1
+++ gnu/java/awt/peer/x/XImage.java	17 Jul 2006 08:24:09 -0000
@@ -34,38 +34,37 @@
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package gnu.java.awt.peer.x;
 
 import gnu.x11.Pixmap;
 
 import java.awt.Graphics;
 import java.awt.GraphicsEnvironment;
 import java.awt.Image;
-import java.awt.Toolkit;
 import java.awt.image.ImageObserver;
 import java.awt.image.ImageProducer;
 
 public class XImage
   extends Image
 {
 
   Pixmap pixmap;
 
   XImage(int w, int h)
   {
-    XToolkit tk = (XToolkit) Toolkit.getDefaultToolkit();
-    GraphicsEnvironment env = tk.getLocalGraphicsEnvironment();
+    GraphicsEnvironment env =
+      GraphicsEnvironment.getLocalGraphicsEnvironment();
     XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
     pixmap = new Pixmap(dev.getDisplay(), w, h);
   }
 
   public int getWidth(ImageObserver observer)
   {
     return pixmap.width;
   }
 
   public int getHeight(ImageObserver observer)
   {
     return pixmap.height;
Index: gnu/java/awt/peer/x/XToolkit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XToolkit.java,v
retrieving revision 1.3
diff -u -1 -2 -r1.3 XToolkit.java
--- gnu/java/awt/peer/x/XToolkit.java	14 Jul 2006 19:33:51 -0000	1.3
+++ gnu/java/awt/peer/x/XToolkit.java	17 Jul 2006 08:24:09 -0000
@@ -122,26 +122,24 @@
 import gnu.java.awt.peer.swing.SwingLabelPeer;
 import gnu.java.awt.peer.swing.SwingPanelPeer;
 
 public class XToolkit
   extends ClasspathToolkit
 {
 
   /**
    * Set to true to enable debug output.
    */
   static boolean DEBUG = false;
 
-  private XGraphicsEnvironment env;
-
   /**
    * The system event queue.
    */
   private EventQueue eventQueue;
 
   /**
    * The default color model of this toolkit.
    */
   private ColorModel colorModel;
 
   /**
    * Maps image URLs to Image instances.
@@ -153,27 +151,26 @@
    */
   private WeakHashMap fontCache = new WeakHashMap();
 
   public XToolkit()
   {
     SystemProperties.setProperty("gnu.javax.swing.noGraphics2D", "true");
     SystemProperties.setProperty("java.awt.graphicsenv",
                                  "gnu.java.awt.peer.x.XGraphicsEnvironment");
   }
 
   public GraphicsEnvironment getLocalGraphicsEnvironment()
   {
-    if (env == null)
-      env = new XGraphicsEnvironment();
-    return env;
+    assert false : "Don't call this";
+    return null;
   }
 
   /**
    * Returns the font peer for a font with the specified name and attributes.
    *
    * @param name the font name
    * @param attrs the font attributes
    *
    * @return the font peer for a font with the specified name and attributes
    */
   public ClasspathFontPeer getClasspathFontPeer(String name, Map attrs)
   {

Reply via email to