[Patch] java.awt - GraphicsDevice and GraphicsEnvironment

Michael Koch konqueror@gmx.de
Mon Apr 25 21:00:00 GMT 2005


Hi list,


I just commited the attached patch to merge more java.awt stuff from GNU
classpath to gcc HEAD.


Michael


2005-04-25  Jeroen Frijters  <jeroen@frijters.net>

	* java/awt/GraphicsEnvironment.java
	(localGraphicsEnvironment): New field.
	(getLocalGraphicsEnvironment): Added support for java.awt.graphicsenv
	property.
	(isHeadless): Added support for java.awt.headless property.
	(isHeadlessInstance): Call headless().

2005-04-25  Roman Kennke  <roman@kennke.org>

	* gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java
	(getDisplayMode): Added. Returns the current display mode.
	(isFullScreenSupported): Added.
	* java/awt/GraphicsDevice.java
	(setFullScreenWindow): Implemented a primitive fullscreen mode.
	This resizes and relocates the fullscreen window so that it uses
	the whole screen. This is not a fully accelerated fullscreen
	exclusive mode.

-------------- next part --------------
Index: gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java,v
retrieving revision 1.3
diff -u -r1.3 GdkScreenGraphicsDevice.java
--- gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java	17 Feb 2005 07:48:22 -0000	1.3
+++ gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java	25 Apr 2005 20:57:48 -0000
@@ -38,6 +38,8 @@
 
 package gnu.java.awt.peer.gtk;
 
+import java.awt.Dimension;
+import java.awt.DisplayMode;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 
@@ -79,4 +81,35 @@
     // FIXME: query X for default configuration
     return new GdkGraphicsConfiguration(this);
   }
+
+
+  /**
+   * Returns the current display mode of this device, or null if unknown.
+   *
+   * @return the current display mode
+   * @see #setDisplayMode(DisplayMode)
+   * @see #getDisplayModes()
+   * @since 1.4
+   */
+  public DisplayMode getDisplayMode()
+  {
+    // determine display mode
+    Dimension dim = getToolkit().getScreenSize();
+    DisplayMode mode = new DisplayMode(dim.width, dim.height, 0,
+				       DisplayMode.REFRESH_RATE_UNKNOWN);
+    return mode;
+  }
+
+  /**
+   * This device does not yet support fullscreen exclusive mode, so this
+   * returns <code>false</code>.
+   *
+   * @return <code>false</code>
+   * @since 1.4
+   */
+  public boolean isFullScreenSupported()
+  {
+    return false;
+  }
+
 }
Index: java/awt/GraphicsDevice.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/GraphicsDevice.java,v
retrieving revision 1.2
diff -u -r1.2 GraphicsDevice.java
--- java/awt/GraphicsDevice.java	17 Feb 2005 07:48:24 -0000	1.2
+++ java/awt/GraphicsDevice.java	25 Apr 2005 20:57:48 -0000
@@ -64,6 +64,12 @@
   /** The current full-screen window, or null if there is none. */
   private Window full_screen;
 
+  /**
+   * The bounds of the fullscreen window before it has been switched to full
+   * screen.
+   */
+  private Rectangle fullScreenOldBounds;
+
   /** The current display mode, or null if unknown. */
   private DisplayMode mode;
 
@@ -151,9 +157,9 @@
    * </ul><br>
    * If <code>isFullScreenSupported()</code> returns false, full-screen
    * exclusive mode is simulated by resizing the window to the size of the
-   * screen and positioning it at (0,0).
-   *
-   * XXX Not yet implemented in Classpath.
+   * screen and positioning it at (0,0). This is also what this method does.
+   * If a device supports real fullscreen mode then it should override this
+   * method as well as #isFullScreenSupported and #getFullScreenWindow.
    *
    * @param w the window to toggle
    * @see #isFullScreenSupported()
@@ -164,11 +170,24 @@
    */
   public synchronized void setFullScreenWindow(Window w)
   {
+    // Restore the previous window to normal mode and release the reference.
     if (full_screen != null)
-      ; // XXX Restore the previous window to normal mode.
-    full_screen = w;
-    // XXX If w != null, make it full-screen.
-    throw new Error("not implemented");
+      {
+	full_screen.setBounds(fullScreenOldBounds);
+      }
+
+    full_screen = null;
+
+    // If w != null, make it full-screen.
+    if (w != null)
+      {
+	fullScreenOldBounds = w.getBounds();
+	full_screen = w;
+	DisplayMode dMode = getDisplayMode();
+	full_screen.setBounds(0, 0, dMode.getWidth(), dMode.getHeight());
+	full_screen.requestFocus();
+	full_screen.setLocationRelativeTo(null);
+      }
   }
 
   /**
Index: java/awt/GraphicsEnvironment.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/GraphicsEnvironment.java,v
retrieving revision 1.3
diff -u -r1.3 GraphicsEnvironment.java
--- java/awt/GraphicsEnvironment.java	30 Nov 2004 23:58:38 -0000	1.3
+++ java/awt/GraphicsEnvironment.java	25 Apr 2005 20:57:48 -0000
@@ -1,5 +1,5 @@
 /* GraphicsEnvironment.java -- information about the graphics environment
-   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -39,7 +39,7 @@
 package java.awt;
 
 import gnu.java.awt.ClasspathToolkit;
-
+import gnu.classpath.SystemProperties;
 import java.awt.image.BufferedImage;
 import java.util.Locale;
 
@@ -56,6 +56,8 @@
  */
 public abstract class GraphicsEnvironment
 {
+  private static GraphicsEnvironment localGraphicsEnvironment;
+
   /**
    * The environment must be obtained from a factory or query method, hence
    * this constructor is protected.
@@ -65,16 +67,43 @@
   }
 
   /**
-   * Returns the local graphics environment.
+   * Returns the local graphics environment. If the java.awt.graphicsenv
+   * system property is set, it instantiates the specified class,
+   * otherwise it assume that the awt toolkit is a ClasspathToolkit
+   * and delegates to it to create the instance.
    *
-   * XXX Not implemented in Classpath yet.
    * @return the local environment
    */
   public static GraphicsEnvironment getLocalGraphicsEnvironment()
   {
-    ClasspathToolkit tk;
-    tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit ());
-    return tk.getLocalGraphicsEnvironment ();
+    if (localGraphicsEnvironment != null)
+      return localGraphicsEnvironment;
+
+    String graphicsenv = SystemProperties.getProperty("java.awt.graphicsenv",
+                                                      null);
+    if (graphicsenv != null)
+      {
+        try
+          {
+            // We intentionally use the bootstrap class loader.
+            localGraphicsEnvironment = (GraphicsEnvironment)
+                Class.forName(graphicsenv).newInstance();
+            return localGraphicsEnvironment;
+          }
+        catch (Exception x)
+          {
+            throw (InternalError)
+                new InternalError("Unable to instantiate java.awt.graphicsenv")
+                    .initCause(x);
+          }
+      }
+    else
+      {
+        ClasspathToolkit tk;
+        tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit());
+        localGraphicsEnvironment = tk.getLocalGraphicsEnvironment();
+        return localGraphicsEnvironment;
+      }
   }
 
   /**
@@ -83,7 +112,8 @@
    * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
    * returns true.
    *
-   * XXX For now, Classpath assumes that it is never headless.
+   * This method returns true if the java.awt.headless property is set
+   * to "true".
    *
    * @return true if the environment is headless, meaning that graphics are
    *         unsupported
@@ -91,16 +121,16 @@
    */
   public static boolean isHeadless()
   {
-    // XXX Should be: getLocalGraphicsEnvironment().isHeadlessInstance();
-    return false;
+    String headless = SystemProperties.getProperty("java.awt.headless", null);
+    return "true".equalsIgnoreCase(headless);
   }
 
   /**
    * Check if the given environment is headless, meaning that it does not
    * support a display, keyboard, or mouse. Many methods in the Abstract
    * Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
-   * returns true. This default implementation returns false, so subclasses
-   * need only override it if they are headless.
+   * returns true. This default implementation returns isHeadless(), so
+   * subclasses need only override it if they differ.
    *
    * @return true if the environment is headless, meaning that graphics are
    *         unsupported
@@ -108,7 +138,7 @@
    */
   public boolean isHeadlessInstance()
   {
-    return false;
+    return isHeadless();
   }
 
   /**


More information about the Java-patches mailing list