diff options
author | Eric Blake <ebb9@byu.net> | 2002-03-18 22:40:25 +0000 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2002-03-18 22:40:25 +0000 |
commit | 21ef77c06987bfb89e24c7f01eb79945224f9457 (patch) | |
tree | 3c4124727d634cb3e52fbd6de4893eeb033d1a94 /java | |
parent | 520b3e7425b5596d6c5dac561fad1b3bdc42f879 (diff) | |
download | classpath-21ef77c06987bfb89e24c7f01eb79945224f9457.tar.gz |
2002-03-18 Eric Blake <ebb9@email.byu.edu>
* java/applet/AppletContext.java (setStream, getStream),
(getStreamKeys): Add new methods.
* java/applet/AppletStub.java: Improve javadoc.
* java/applet/AudioClip.java: Ditto.
* java/applet/Applet.java: Updated to 1.4.
* java/awt/Makefile.am (EXTRA_DIST): Add DisplayMode.java,
GraphicsConfigTemplate.java, GraphicsDevice.java and
GraphicsEnvironment.java.
* java/awt/DisplayMode.java: New file.
* java/awt/GraphicsConfigTemplate.java: New file.
* java/awt/GraphicsDevice.java: New file.
* java/awt/GraphicsEnvironment.java: New file.
* java/awt/GraphicsConfiguration.java (getDevice): Add method.
* java/awt/Panel.java: Updated to 1.4.
* java/awt/AWTPermission.java: Updated to 1.4.
* java/awt/Container.java: Partial update to 1.4.
* java/awt/Component.java: Partial update to 1.4.
Diffstat (limited to 'java')
-rw-r--r-- | java/applet/Applet.java | 542 | ||||
-rw-r--r-- | java/applet/AppletContext.java | 149 | ||||
-rw-r--r-- | java/applet/AppletStub.java | 97 | ||||
-rw-r--r-- | java/applet/AudioClip.java | 41 | ||||
-rw-r--r-- | java/awt/AWTPermission.java | 82 | ||||
-rw-r--r-- | java/awt/Component.java | 404 | ||||
-rw-r--r-- | java/awt/Container.java | 445 | ||||
-rw-r--r-- | java/awt/DisplayMode.java | 164 | ||||
-rw-r--r-- | java/awt/GraphicsConfigTemplate.java | 106 | ||||
-rw-r--r-- | java/awt/GraphicsConfiguration.java | 2 | ||||
-rw-r--r-- | java/awt/GraphicsDevice.java | 271 | ||||
-rw-r--r-- | java/awt/GraphicsEnvironment.java | 210 | ||||
-rw-r--r-- | java/awt/Makefile.am | 4 | ||||
-rw-r--r-- | java/awt/Panel.java | 154 |
14 files changed, 2000 insertions, 671 deletions
diff --git a/java/applet/Applet.java b/java/applet/Applet.java index 8f9338ffd..d97009778 100644 --- a/java/applet/Applet.java +++ b/java/applet/Applet.java @@ -1,23 +1,23 @@ /* Applet.java -- Java base applet class - Copyright (C) 1999 Free Software Foundation, Inc. - + Copyright (C) 1999, 2002 Free Software Foundation, Inc. + This file is part of GNU Classpath. - + GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - + Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole @@ -39,269 +39,469 @@ exception statement from your version. */ package java.applet; import java.awt.Dimension; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; import java.awt.Image; +import java.awt.Panel; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; /** - * This is the base applet class. An applet is a Java program that - * runs inside a web browser or other applet viewer in a restricted - * environment. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Applet extends java.awt.Panel implements java.io.Serializable + * This is the base applet class. An applet is a Java program that + * runs inside a web browser or other applet viewer in a restricted + * environment. + * + * <p>To be useful, a subclass should override at least start(). Also useful + * are init, stop, and destroy for control purposes, and getAppletInfo and + * getParameterInfo for descriptive purposes. + * + * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.0 + * @status updated to 1.4 + */ +public class Applet extends Panel { - // The applet stub for this applet - private AppletStub stub; + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = -5836846270535785031L; + + /** The applet stub for this applet. */ + private transient AppletStub stub; + + /** + * The accessibility context for this applet. + * + * @serial the accessibleContext for this + * @since 1.2 + */ + private AccessibleContext accessibleContext; + + /** + * Default constructor for subclasses. + * + * @throws HeadlessException if in a headless environment + */ + public Applet() + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + } + + /** + * The browser calls this method to set the applet's stub, which is the + * low level interface to the browser. Manually setting this to null is + * asking for problems down the road. + * + * @param stub the applet stub for this applet + */ + public final void setStub(AppletStub stub) + { + this.stub = stub; + } /** - * Default constructor for subclasses. - */ - public Applet() {} + * Tests whether or not this applet is currently active. An applet is active + * just before the browser invokes start(), and becomes inactive just + * before the browser invokes stop(). + * + * @return <code>true</code> if this applet is active + */ + public boolean isActive() + { + return stub.isActive(); + } /** - * Returns the URL of the document this applet is embedded in. - * - * @return The URL of the document this applet is embedded in. - */ + * Returns the basename URL of the document this applet is embedded in. This + * is everything up to the final '/'. + * + * @return the URL of the document this applet is embedded in + * @see #getCodeBase() + */ public URL getDocumentBase() { - return (stub.getDocumentBase ()); + return stub.getDocumentBase(); } /** - * Returns the URL of the code base for this applet. - * - * @return The URL of the code base for this applet. - */ + * Returns the URL of the code base for this applet. + * + * @return the URL of the code base for this applet + */ public URL getCodeBase() { - return (stub.getCodeBase ()); + return stub.getCodeBase(); } /** - * Returns the value of the specified parameter that was specified in - * the <APPLET> tag for this applet. - * - * @param name The parameter name. - * - * @param value The parameter value, or <code>null</code> if the parameter - * does not exist. - */ + * Returns the value of the specified parameter that was specified in + * the <code><APPLET></code> tag for this applet. + * + * @param name the parameter name + * @return the parameter value, or null if the parameter does not exist + * @throws NullPointerException if name is null + */ public String getParameter(String name) { - return (stub.getParameter (name)); + return stub.getParameter(name); } /** - * Returns the applet context for this applet. - * - * @return The applet context for this applet. - */ + * Returns the applet context for this applet. + * + * @return the applet context for this applet + */ public AppletContext getAppletContext() { - return (stub.getAppletContext ()); + return stub.getAppletContext(); } /** - * Tests whether or not this applet is currently active. - * - * @return <code>true</code> if this applet is active, <code>false</code> - * otherwise. - */ - public boolean isActive() + * Requests that the applet window for this applet be resized. + * + * @param width the new width in pixels + * @param height the new height in pixels + */ + public void resize(int width, int height) { - return (stub.isActive ()); + stub.appletResize(width, height); } /** - * Requests that the applet window for this applet be resized. - * - * @param width The new width in pixels. - * @param height The new height in pixels. - */ - public void resize(int width, int height) + * Requests that the applet window for this applet be resized. + * + * @param dim the requested dimensions + * @throws NullPointerException if dim is null + */ + public void resize(Dimension dim) { - stub.appletResize (width, height); + resize(dim.width, dim.height); } /** - * Requests that the applet window for this applet be resized. - * - * @param dim The <code>Dimension</code> object with the requested - * width and height. - */ - public void resize(Dimension dim) + * Displays the specified message in the status window if that window + * exists. + * + * @param message the status message, may be null + */ + public void showStatus(String message) + { + getAppletContext().showStatus(message); + } + + /** + * Returns an image from the specified URL. Note that the image is not + * actually retrieved until the applet attempts to display it, so this + * method returns immediately. + * + * @param url the URL of the image + * @return the retrieved image + * @throws NullPointerException if url is null + */ + public Image getImage(URL url) { - resize (dim.width, dim.height); + return getAppletContext().getImage(url); } /** - * Returns an audio clip from the specified URL. - * - * @param url The URL of the audio clip. - * - * @return The retrieved audio clip. - */ + * Returns an image from the specified absolute URL, and relative path + * from that URL. Note that the image is not actually retrieved until the + * applet attempts to display it, so this method returns immediately. + * This calls <code>getImage(new URL(url, name))</code>, but if building + * the new URL fails, this returns null. + * + * @param url the base URL of the image + * @param name the name of the image relative to the URL + * @return the retrieved image, or null on failure + * @see #getImage(URL) + */ + public Image getImage(URL url, String name) + { + try + { + return getImage(new URL(url, name)); + } + catch (MalformedURLException e) + { + return null; + } + } + + /** + * Returns an audio clip from the specified URL. This clip is not tied to + * any particular applet. + * + * XXX Classpath does not yet implement this. + * + * @param url the URL of the audio clip + * @return the retrieved audio clip + * @throws NullPointerException if url is null + * @see #getAudioClip(URL) + * @since 1.2 + */ + public static final AudioClip newAudioClip(URL url) + { + // This requires an implementation of AudioClip in gnu.java.applet. + throw new Error("Not implemented"); + } + + /** + * Returns an audio clip from the specified URL. Note that the clip is not + * actually retrieved until the applet attempts to play it, so this method + * returns immediately. + * + * @param url the URL of the audio clip + * @return the retrieved audio clip + * @throws NullPointerException if url is null + */ public AudioClip getAudioClip(URL url) { - return (getAppletContext ().getAudioClip (url)); + return getAppletContext().getAudioClip(url); } /** - * Returns an audio clip from the specified URL and name - * - * @param url The base URL of the audio clip. - * @param name The name of the clip relative to the URL. - * - * @return The retrieved audio clip. - */ + * Returns an audio clip from the specified absolute URL, and relative path + * from that URL. Note that the clip is not actually retrieved until the + * applet attempts to play it, so this method returns immediately. This + * calls <code>getAudioClip(new URL(url, name))</code>, but if building + * the new URL fails, this returns null. + * + * @param url the base URL of the audio clip + * @param name the name of the clip relative to the URL + * @return the retrieved audio clip, or null on failure + * @see #getAudioClip(URL) + */ public AudioClip getAudioClip(URL url, String name) { try { - return (getAppletContext ().getAudioClip (new URL (url.toExternalForm() - + name))); + return getAudioClip(new URL(url, name)); } - catch(Exception e) + catch (MalformedURLException e) { - return (getAudioClip (url)); + return null; } } /** - * Loads and plays the audio clip pointed to by the specified URL. - * - * @param The URL of the audio clip. - */ - public void play (URL url) + * Returns a descriptive string with applet defined information. The + * implementation in this class returns <code>null</code>, so subclasses + * must override to return information. + * + * @return a string describing the author, version, and applet copyright + */ + public String getAppletInfo() { - getAudioClip (url).play (); + return null; } /** - * Loads and plays the audio clip pointed to by the specified URL. - * - * @param The base URL of the audio clip. - * @param name The name of the audio clip relative to the URL. - */ - public void play (URL url, String name) + * Returns the locale for this applet, if it has been set. If no applet + * specific locale has been set, the default locale is returned. + * + * @return the locale for this applet + * @see Component#setLocale(Locale) + * @since 1.1 + */ + public Locale getLocale() { - getAudioClip (url, name).play (); + return super.getLocale(); } /** - * Returns an image from the specified URL. Note that the image is not - * actually retrieved until the applet attempts to display it, so this - * method returns immediately. - * - * @param url The URL of the image. - * - * @return The retrieved image. - */ - public Image getImage(URL url) + * Returns a list of parameters this applet supports. Each element of + * the outer array is an array of three strings with the name of the + * parameter, the data type or valid values, and a description. This + * method is optional and the default implementation returns null. + * + * @return the list of parameters supported by this applet + */ + public String[][] getParameterInfo() { - return (getAppletContext ().getImage (url)); + return null; } /** - * Returns an image from the specified URL. Note that the image is not - * actually retrieved until the applet attempts to display it, so this - * method returns immediately. - * - * @param url The base URL of the image. - * @param name The name of the image relative to the URL. - * - * @return The retrieved image. - */ - public Image getImage(URL url, String name) + * Loads and plays the audio clip pointed to by the specified URL. This does + * nothing if the URL does not point to a valid audio clip. + * + * @param url the URL of the audio clip + * @throws NullPointerException if url is null + * @see #getAudioClip(URL) + */ + public void play(URL url) { + AudioClip ac = getAudioClip(url); try { - return (getAppletContext ().getImage (new URL (url.toExternalForm() - + name))); + ac.play(); } - catch(Exception e) + catch (Exception ignored) { - return (getImage (url)); } } /** - * Returns the locale for this applet, if it has been set. If no applet - * specific locale has been set, the default locale is returned. - * - * @return The locale for this applet. - */ - public Locale getLocale() + * Loads and plays the audio clip pointed to by the specified absolute URL, + * and relative path from that URL. This does nothing if the URL cannot be + * constructed, or if it does not point to a valid audio clip. + * + * @param url the base URL of the audio clip + * @param name the name of the audio clip relative to the URL + * @see #getAudioClip(URL, String) + * @see #play(URL) + */ + public void play(URL url, String name) { - return (super.getLocale ()); + try + { + getAudioClip(url, name).play(); + } + catch (Exception ignored) + { + } } /** - * Returns a descriptive string with applet defined information. The - * implementation in this class returns <code>null</code>. Applets who - * wish to return this information should override. - * - * @return A string describing the applet. - */ - public String getAppletInfo() + * This method is called when the applet is first loaded, before start(). + * The default implementation does nothing; override to do any one-time + * initialization. + * + * @see #start() + * @see #stop() + * @see #destroy() + */ + public void init() { - return (null); } /** - * Returns a list of parameters this applet supports. Each element of - * the array is a list of three strings with the name of the parameter, - * the data type or valid values, and a description. This method is - * optional and the default implementation returns <code>null</code>. - * - * @return The list of parameters supported by this applet. - */ - public String[][] getParameterInfo() + * This method is called when the applet should start running. This is + * normally each time a web page containing it is loaded. The default + * implemention does nothing; override for your applet to be useful. + * + * @see #init() + * @see #stop() + * @see #destroy() + */ + public void start() { - return (null); } /** - * This method is called when the applet is first loaded. The default - * implementation does nothing. Applets that wish to do one time - * initialization should override. - */ - public void init() {} + * This method is called when the applet should stop running. This is + * normally when the next web page is loaded. The default implementation + * does nothing; override for your applet to stop using resources when + * it is no longer visible, but may be restarted soon. + * + * @see #init() + * @see #start() + * @see #destroy() + */ + public void stop() + { + } /** - * This method is called when the applet is being unloaded. The default - * implementation does nothing. Applets that need to clean up resources - * on exit should override. - */ - public void destroy() {} + * This method is called when the applet is being unloaded. The default + * implementation does nothing; override for your applet to clean up + * resources on exit. + * + * @see #init() + * @see #start() + * @see #stop() + */ + public void destroy() + { + } /** - * This method is called when the applet should start running. This is - * normally each time a web page containing it is loaded. The default - * implemention does nothing. Subclasses should override. - */ - public void start() {} + * Gets the AccessibleContext associated with this applet, creating one if + * necessary. This always returns an instance of {@link AccessibleApplet}. + * + * @return the accessibility context of this applet + * @since 1.3 + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleApplet(); + return accessibleContext; + } /** - * This method is called when the applet should stop running. This is - * normally when the next web page is loaded. The default implementation - * does nothing. - */ - public void stop() {} + * Read an applet from an object stream. This checks for a headless + * environment, then does the normal read. + * + * @param s the stream to read from + * @throws ClassNotFoundException if a class is not found + * @throws IOException if deserialization fails + * @throws HeadlessException if this is a headless environment + * @see GraphicsEnvironment#isHeadless() + * @since 1.4 + */ + private void readObject(ObjectInputStream s) + throws ClassNotFoundException, IOException + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + s.defaultReadObject(); + } /** - * The browser calls this method to set the applet's stub, which is the - * low level interface to the browser. - * - * @param stub The applet stub for this applet. - */ - public final void setStub (AppletStub stub) + * This class provides accessibility support for Applets, and is the + * runtime type returned by {@link #getAccessibleContext()}. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.3 + */ + protected class AccessibleApplet extends AccessibleAWTPanel { - this.stub = stub; - } + /** + * Compatible with JDK 1.4+. + */ + private static final long serialVersionUID = 8127374778187708896L; -} // class Applet + /** + * The default constructor. + */ + protected AccessibleApplet() + { + } + /** + * Get the role of this accessible object, a frame. + * + * @return the role of the object + * @see AccessibleRole#FRAME + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.FRAME; + } + + /** + * Get the state set of this accessible object. In addition to the default + * states of a Component, the applet is also active. + * + * @return the role of the object + * @see AccessibleState + */ + public AccessibleStateSet getAccessibleStateSet() + { + // XXX Make sure that this is correct. + AccessibleStateSet s = super.getAccessibleStateSet(); + s.add(AccessibleState.ACTIVE); + return s; + } + } // class AccessibleApplet +} // class Applet diff --git a/java/applet/AppletContext.java b/java/applet/AppletContext.java index 86552abc2..f3b612377 100644 --- a/java/applet/AppletContext.java +++ b/java/applet/AppletContext.java @@ -1,23 +1,23 @@ -/* AppletContext.java -- Access the applet's runtime environment. - Copyright (C) 1999 Free Software Foundation, Inc. - +/* AppletContext.java -- access the applet's runtime environment + Copyright (C) 1999, 2002 Free Software Foundation, Inc. + This file is part of GNU Classpath. - + GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - + Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole @@ -39,81 +39,116 @@ exception statement from your version. */ package java.applet; import java.awt.Image; +import java.io.InputStream; +import java.io.IOException; import java.net.URL; import java.util.Enumeration; +import java.util.Iterator; /** - * This interface allows an applet access to the browser to retrieve - * additional data files and display documents. It also allows the - * applet to find out other applets in the same document. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface allows an applet access to the browser to retrieve + * additional data files and display documents. It also allows the + * applet to find out other applets in the same document. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @since 1.0 + * @status updated to 1.4 + */ public interface AppletContext { /** - * Returns an audio clip from the specified URL. - * - * @param url The URL of the audio clip. - * - * @return The retrieved audio clip // FIXME: What happens on error? - */ + * Returns an audio clip from the specified URL. + * + * @param url the URL of the audio clip + * @return the retrieved audio clip + * @throws NullPointerException if url is null + */ AudioClip getAudioClip(URL url); /** - * Returns an image from the specified URL. Note that the image is not - * actually retrieved until the applet attempts to display it, so this - * method returns immediately. - * - * @param url The URL of the image. - * - * @return The retrieved image. // FIXME: What happens on eror? - */ + * Returns an image from the specified URL. Note that the image is not + * actually retrieved until the applet attempts to display it, so this + * method returns immediately. + * + * @param url the absolute URL of the image + * @return the retrieved image + * @throws NullPointerException if url is null + */ Image getImage(URL url); /** - * Returns the applet in the document for this object that has the - * specified name. - * - * @param name The applet name. - * - * @return The requested applet, or <code>null</code> if an applet with - * the requested name cannot be found. - */ + * Returns the applet in the document for this object that has the + * specified name. + * + * @param name the applet name + * @return the requested applet, or <code>null</code> if not found + */ Applet getApplet(String name); /** - * Returns a list of all the applets in the document for this object. - * - * @return A list of all the applets in the document for this object. - */ + * Returns a list of all the applets in the document for this object. + * + * @return a list of all the applets + */ Enumeration getApplets(); /** - * Displays the web page pointed to by the specified URL in the window - * for this object. This page replaces the document that is currently - * there. - * - * @param url The URL of the web page to load. - */ + * Displays the web page pointed to by the specified URL in the window + * for this object. This page replaces the document that is currently + * there. + * + * @param url the URL of the web page to load; unspecified on an error + */ void showDocument(URL url); /** - * Displays the web page pointed to be the sepcified URL in the window - * with the specified name. The standard names "_top", "_blank", - * "_parent", and "_self" are allowed. - * - * @param url The URL of the web page to load. - * @param target The target window. - */ + * Displays the web page pointed to be the sepcified URL in the window + * with the specified name. The standard names "_top", "_blank", + * "_parent", and "_self" are allowed. An applet viewer may disregard + * this request. + * + * @param url the URL of the web page to load + * @param target the target window + */ void showDocument(URL url, String target); /** - * Displays the specified message in the status window if that window - * exists. - * - * @param message The status message. - */ + * Displays the specified message in the status window if that window + * exists. + * + * @param message the status message, may be null + */ void showStatus(String message); + /** + * Associate a stream to a key for this applet context, possibly replacing + * the old value. Stream associations are local to the applet context, for + * security purposes. + * + * @param key the key to associate with + * @param stream the stream value to tie to the key, or null to remove + * @throws IOException if the stream is too large + * @since 1.4 + */ + public void setString(String key, InputStream stream) throws IOException; + + /** + * Return the stream associated with a given key in this applet context, or + * null if nothing is associated. Stream associations are local to the + * applet context, for security purposes. + * + * @param key the key to look up + * @return the associated stream, or null + * @since 1.4 + */ + public InputStream getStream(String key); + + /** + * Iterate over all keys that have associated streams. Sttream associated + * are local to the applet context, for security purposes. + * + * @return an iterator over the association keys + * @since 1.4 + */ + public Iterator getStreamKeys(); } // interface AppletContext diff --git a/java/applet/AppletStub.java b/java/applet/AppletStub.java index 5ec428a6f..7694cc822 100644 --- a/java/applet/AppletStub.java +++ b/java/applet/AppletStub.java @@ -1,23 +1,23 @@ -/* AppletStub.java -- Low level interface to the browser. - Copyright (C) 1999 Free Software Foundation, Inc. - +/* AppletStub.java -- low level interface to the browser + Copyright (C) 1999, 2002 Free Software Foundation, Inc. + This file is part of GNU Classpath. - + GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - + Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole @@ -40,60 +40,63 @@ package java.applet; import java.net.URL; /** - * This interface is the low level interface between the applet and the - * browser. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface is the low level interface between the applet and the + * browser. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @see Applet#setStub(AppletStub) + * @since 1.0 + * @status updated to 1.4 + */ public interface AppletStub { /** - * Returns the URL of the document this applet is embedded in. - * - * @return The URL of the document this applet is embedded in. - */ + * Tests whether or not this applet is currently active. An applet is active + * just before the browser invokes start(), and becomes inactive just + * before the browser invokes stop(). + * + * @return <code>true</code> if this applet is active + */ + boolean isActive(); + + /** + * Returns the basename URL of the document this applet is embedded in. This + * is everything up to the final '/'. + * + * @return the URL of the document this applet is embedded in + * @see #getCodeBase() + */ URL getDocumentBase(); /** - * Returns the URL of the code base for this applet. - * - * @return The URL of the code base for this applet. - */ + * Returns the URL of the code base for this applet. + * + * @return the URL of the code base for this applet + */ URL getCodeBase(); /** - * Returns the value of the specified parameter that was specified in - * the <APPLET> tag for this applet. - * - * @param name The parameter name. - * - * @param value The parameter value, or <code>null</code> if the parameter - * does not exist. - */ + * Returns the value of the specified parameter that was specified in + * the <code><APPLET></code> tag for this applet. + * + * @param name the parameter name + * @return the parameter value, or null if the parameter does not exist + * @throws NullPointerException if name is null + */ String getParameter(String name); /** - * Returns the applet context for this applet. - * - * @return The applet context for this applet. - */ + * Returns the applet context for this applet. + * + * @return the applet context for this applet + */ AppletContext getAppletContext(); /** - * Tests whether or not this applet is currently active. - * - * @return <code>true</code> if this applet is active, <code>false</code> - * otherwise. - */ - boolean isActive(); - - /** - * Requests that the applet window for this applet be resized. - * - * @param width The new width in pixels. - * @param height The new height in pixels. - */ + * Requests that the applet window for this applet be resized. + * + * @param width the new width in pixels + * @param height the new height in pixels + */ void appletResize(int width, int height); - } // interface AppletStub - diff --git a/java/applet/AudioClip.java b/java/applet/AudioClip.java index 97cf9008a..41dd3be2a 100644 --- a/java/applet/AudioClip.java +++ b/java/applet/AudioClip.java @@ -1,23 +1,23 @@ -/* AudioClip.java -- Play an audio clip. - Copyright (C) 1999 Free Software Foundation, Inc. - +/* AudioClip.java -- play an audio clip in an applet + Copyright (C) 1999, 2002 Free Software Foundation, Inc. + This file is part of GNU Classpath. - + GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - + Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole @@ -39,26 +39,29 @@ exception statement from your version. */ package java.applet; /** - * This interface provides a simple mechanism for playing audio clips. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface provides a simple mechanism for playing audio clips. + * If multiple clips are played at once, the browser combines them into a + * composite clip. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @since 1.0 + * @status updated to 1.4 + */ public interface AudioClip { /** - * Plays the audio clip starting from the beginning. - */ + * Plays the audio clip starting from the beginning. + */ void play(); /** - * Stops playing this audio clip. There is no mechanism for restarting - * at the point where the clip is stopped. - */ + * Stops playing this audio clip. There is no mechanism for restarting + * at the point where the clip is stopped. + */ void stop(); /** - * Plays this audio clip in a continuous loop. - */ + * Plays this audio clip in a continuous loop. + */ void loop(); - } // interface AudioClip diff --git a/java/awt/AWTPermission.java b/java/awt/AWTPermission.java index 914ecd7d0..993c60d50 100644 --- a/java/awt/AWTPermission.java +++ b/java/awt/AWTPermission.java @@ -1,6 +1,5 @@ -// AWTPermission.java - AWT permissions - -/* Copyright (C) 2000, 2002 Free Software Foundation +/* AWTPermission.java -- AWT related permissions + Copyright (C) 2000, 2002 Free Software Foundation This file is part of GNU Classpath. @@ -37,11 +36,6 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -/** - * @author Tom Tromey <tromey@redhat.com> - * @date December 2, 2000 - */ - package java.awt; import java.security.BasicPermission; @@ -49,25 +43,79 @@ import java.security.BasicPermission; /** * This class implements permissions for AWT. This is a named * permission. No actions are defined. + * + * <p>The following table provides a list of all the possible AWTPermission + * permission names with a description of what that permission allows.<br> + * <table border=1> + * <tr><th>Permission Name</th><th>Permission Allows</th><th>Risks</th</tr> + * <tr> + * <td><code>accessClipboard</code></td> + * <td>posting and reading the AWT clipboard</td> + * <td>the clipboard may contain sensitive data</td></tr> + * <tr> + * <td><code>accessEventQueue</code></td> + * <td>access to the AWT event queue</td> + * <td>malicious code could remove real events and replace them with bogus + * ones, including simulating the user granting permission</td></tr> + * <tr> + * <td><code>listenToAllAWTEvents</code></td> + * <td>listen to system-wide AWT events</td> + * <td>malicious code can read passwords entered in an AWT event, and in + * combination with accessEventQueue, could fake system events</td></tr> + * <tr> + * <td><code>showWindowWithoutWarningBanner</code></td> + * <td>display a window without a banner notification of insecurity</td> + * <td>malicious code could install a Trojan horse applet that looks like + * a normal window, and thus steal data like passwords</td></tr> + * <tr> + * <td><code>readDisplayPixels</code></td> + * <td>read back pixels from the display screen</td> + * <td>malicious code could snoop on the user's actions</td></tr> + * <tr> + * <td><code>createRobot</code></td> + * <td>create an instance of java.awt.Robot</td> + * <td>these objects can generate events as though they were the user; so + * malicious code could control the system</td></tr> + * <tr> + * <td><code>fullScreenExclusive</code></td> + * <td>enter full-screen exclusive mode</td> + * <td>malicious code could masquerade as a trusted program</td><tr> + * </table> + * + * @author Tom Tromey <tromey@redhat.com> + * @since 1.2 + * @status updated to 1.4 */ public final class AWTPermission extends BasicPermission { /** + * Compatible with JDK 1.2+. + */ + private static final long serialVersionUID = 8890392402588814465L; + + /** * Construct a AWTPermission with the given name. - * @param name The permission name + * + * @param name the permission name + * @throws NullPointerException if name is null + * @throws IllegalArgumentException if name is invalid */ - public AWTPermission (String name) + public AWTPermission(String name) { - super (name); + super(name); } /** - * Construct a AWTPermission with the given name. - * @param name The permission name - * @param actions The actions; this is ignored and should be null. + * Create a new permission with the specified name. The actions argument + * is ignored, as AWT permissions have no actions. + * + * @param name the permission name + * @param actions ignored + * @throws NullPointerException if name is null + * @throws IllegalArgumentException if name is invalid */ - public AWTPermission (String name, String actions) + public AWTPermission(String name, String actions) { - super (name, actions); + super(name); } -} +} // class AWTPermission diff --git a/java/awt/Component.java b/java/awt/Component.java index 034390cb6..36406b8e0 100644 --- a/java/awt/Component.java +++ b/java/awt/Component.java @@ -1,4 +1,5 @@ -/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation +/* Component.java -- a graphics component + Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation This file is part of GNU Classpath. @@ -35,32 +36,59 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.awt; -import java.awt.event.*; -import java.awt.image.*; + +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.HierarchyBoundsListener; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.InputMethodEvent; +import java.awt.event.InputMethodListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.PaintEvent; +import java.awt.image.ColorModel; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.peer.ComponentPeer; +import java.awt.peer.LightweightPeer; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.PrintStream; import java.io.PrintWriter; -import java.lang.reflect.*; +import java.io.Serializable; +import java.lang.reflect.Array; import java.util.EventListener; import java.util.Locale; import java.util.ResourceBundle; import java.util.Vector; -import java.awt.peer.ComponentPeer; -import java.awt.peer.LightweightPeer; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyChangeListener; -// import javax.accessibility.AccessibleContext; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleComponent; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleStateSet; /** - * The root of all evil. - * - * Status: Incomplete. The event dispatch mechanism is implemented. All - * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly - * incomplete or only stubs; except for methods relating to the Drag and Drop, - * Input Method, and Accessibility frameworks: These methods are present but - * commented out. - */ -public abstract class Component implements ImageObserver, MenuContainer, - java.io.Serializable + * The root of all evil. + * + * Status: Incomplete. The event dispatch mechanism is implemented. All + * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly + * incomplete or only stubs; except for methods relating to the Drag and + * Drop, Input Method, and Accessibility frameworks: These methods are + * present but commented out. + * + * @author original author unknown + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.0 + * @status still missing 1.4 support + */ +public abstract class Component + implements ImageObserver, MenuContainer, Serializable { /** * Constant returned by the <code>getAlignmentY</code> method to indicate @@ -135,7 +163,7 @@ public abstract class Component implements ImageObserver, MenuContainer, /* Anything else is non-serializable, and should be declared "transient". */ transient Container parent; - transient java.awt.peer.ComponentPeer peer; + transient ComponentPeer peer; transient ComponentListener componentListener; transient FocusListener focusListener; @@ -210,7 +238,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @deprecated */ // Classpath's Gtk peers rely on this. - public java.awt.peer.ComponentPeer getPeer() + public ComponentPeer getPeer() { return peer; } @@ -241,9 +269,9 @@ public abstract class Component implements ImageObserver, MenuContainer, { if (peer != null) { - GraphicsConfiguration config = peer.getGraphicsConfiguration(); - if (config != null) - return config; + GraphicsConfiguration config = peer.getGraphicsConfiguration(); + if (config != null) + return config; } if (parent != null) @@ -278,9 +306,9 @@ public abstract class Component implements ImageObserver, MenuContainer, { if (peer != null) { - Toolkit tk = peer.getToolkit(); - if (tk != null) - return tk; + Toolkit tk = peer.getToolkit(); + if (tk != null) + return tk; } if (parent != null) return parent.getToolkit (); @@ -781,9 +809,9 @@ public abstract class Component implements ImageObserver, MenuContainer, public void setBounds(int x, int y, int w, int h) { if (this.x == x - && this.y == y - && this.width == w - && this.height == h) + && this.y == y + && this.width == w + && this.height == h) return; invalidate(); @@ -1024,20 +1052,20 @@ public abstract class Component implements ImageObserver, MenuContainer, { if (peer != null) { - Graphics gfx = peer.getGraphics(); - if (gfx != null) - return gfx; + Graphics gfx = peer.getGraphics(); + if (gfx != null) + return gfx; - // create graphics for lightweight: - Container parent = getParent(); - if (parent != null) - { - gfx = parent.getGraphics(); - Rectangle bounds = getBounds(); - gfx.setClip(bounds); - gfx.translate(bounds.x, bounds.y); - return gfx; - } + // create graphics for lightweight: + Container parent = getParent(); + if (parent != null) + { + gfx = parent.getGraphics(); + Rectangle bounds = getBounds(); + gfx.setClip(bounds); + gfx.translate(bounds.x, bounds.y); + return gfx; + } } return null; } @@ -1111,7 +1139,7 @@ public abstract class Component implements ImageObserver, MenuContainer, { if (!visible) return; - + if (peer != null) peer.paint(g); paint(g); @@ -1175,9 +1203,9 @@ public abstract class Component implements ImageObserver, MenuContainer, // Handle lightweight repainting by forwarding to native parent if (isLightweight() && (parent != null)) { - if (parent != null) - parent.repaint(tm, x+getX(), y+getY(), width, height); - return; + if (parent != null) + parent.repaint(tm, x+getX(), y+getY(), width, height); + return; } if (peer != null) @@ -1225,7 +1253,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * <code>false</code> otherwise. */ public boolean imageUpdate (Image img, int infoflags, int x, int y, - int w, int h) + int w, int h) { // FIXME return false; @@ -1270,7 +1298,7 @@ public abstract class Component implements ImageObserver, MenuContainer, public boolean prepareImage(Image image, ImageObserver observer) { return prepareImage(image, image.getWidth(observer), - image.getHeight(observer), observer); + image.getHeight(observer), observer); } /** @@ -1287,7 +1315,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * for rendering, <code>false</code> otherwise. */ public boolean prepareImage(Image image, int width, int height, - ImageObserver observer) + ImageObserver observer) { return peer.prepareImage(image, width, height, observer); } @@ -1305,7 +1333,7 @@ public abstract class Component implements ImageObserver, MenuContainer, public int checkImage(Image image, ImageObserver observer) { return checkImage(image, image.getWidth(observer), - image.getHeight(observer), observer); + image.getHeight(observer), observer); } /** @@ -1321,7 +1349,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @return The image observer flags indicating the status of the load. */ public int checkImage (Image image, int width, int height, - ImageObserver observer) + ImageObserver observer) { if (peer != null) return peer.checkImage (image, width, height, observer); @@ -1438,13 +1466,13 @@ public abstract class Component implements ImageObserver, MenuContainer, /** Forward AWT events to processEvent() if: * - Events have been enabled for this type of event via enableEvents(), * OR: - * - There is at least one registered listener for this type of event + * - There is at least one registered listener for this type of event * * @param event The event to dispatch * * @specnote This method is final, but we need to be able to * override it in order to handle other event types in our - * subclasses. The solution is to define a second, non-final + * subclasses. The solution is to define a second, non-final * method - dispatchEventImpl() - to actually do the work. * Investigations with Thread.dumpStack() on the dispatch thread * in JDK 1.3 show Sun's implementation is doing the same @@ -1465,38 +1493,38 @@ public abstract class Component implements ImageObserver, MenuContainer, if (e.id <= ComponentEvent.COMPONENT_LAST && e.id >= ComponentEvent.COMPONENT_FIRST && (componentListener != null - || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)) + || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= KeyEvent.KEY_LAST && e.id >= KeyEvent.KEY_FIRST - && (keyListener != null - || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0)) + && (keyListener != null + || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= MouseEvent.MOUSE_LAST && e.id >= MouseEvent.MOUSE_FIRST - && (mouseListener != null - || mouseMotionListener != null - || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) + && (mouseListener != null + || mouseMotionListener != null + || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= FocusEvent.FOCUS_LAST && e.id >= FocusEvent.FOCUS_FIRST - && (focusListener != null - || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0)) + && (focusListener != null + || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= InputMethodEvent.INPUT_METHOD_LAST && e.id >= InputMethodEvent.INPUT_METHOD_FIRST - && (inputMethodListener != null - || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0)) + && (inputMethodListener != null + || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= HierarchyEvent.HIERARCHY_LAST && e.id >= HierarchyEvent.HIERARCHY_FIRST - && (hierarchyListener != null - || hierarchyBoundsListener != null - || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) + && (hierarchyListener != null + || hierarchyBoundsListener != null + || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) processEvent(e); else if (e.id <= PaintEvent.PAINT_LAST - && e.id >= PaintEvent.PAINT_FIRST - && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0) + && e.id >= PaintEvent.PAINT_FIRST + && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0) processEvent(e); } @@ -1701,7 +1729,7 @@ public abstract class Component implements ImageObserver, MenuContainer, if (el != null) getListenerList (el, v); EventListener[] el_a = (EventListener[]) Array.newInstance(listenerType, - v.size()); + v.size()); v.copyInto(el_a); return el_a; } @@ -1712,7 +1740,7 @@ public abstract class Component implements ImageObserver, MenuContainer, { AWTEventMulticaster mc = (AWTEventMulticaster) el; getListenerList(mc.a, v); - getListenerList(mc.b, v); + getListenerList(mc.b, v); } else v.addElement(el); @@ -1777,12 +1805,12 @@ public abstract class Component implements ImageObserver, MenuContainer, { case MouseEvent.MOUSE_MOVED: case MouseEvent.MOUSE_DRAGGED: - // Just drop the old (intermediate) event and return the new one. - return newEvent; + // Just drop the old (intermediate) event and return the new one. + return newEvent; case PaintEvent.PAINT: case PaintEvent.UPDATE: - return coalescePaintEvents((PaintEvent) existingEvent, - (PaintEvent) newEvent); + return coalescePaintEvents((PaintEvent) existingEvent, + (PaintEvent) newEvent); } return null; } @@ -1813,7 +1841,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * </pre> */ private PaintEvent coalescePaintEvents(PaintEvent queuedEvent, - PaintEvent newEvent) + PaintEvent newEvent) { Rectangle r1 = queuedEvent.getUpdateRect(); Rectangle r2 = newEvent.getUpdateRect(); @@ -1853,10 +1881,10 @@ public abstract class Component implements ImageObserver, MenuContainer, else if (e instanceof MouseEvent) { if (e.id == MouseEvent.MOUSE_MOVED - || e.id == MouseEvent.MOUSE_DRAGGED) - processMouseMotionEvent((MouseEvent) e); - else - processMouseEvent((MouseEvent) e); + || e.id == MouseEvent.MOUSE_DRAGGED) + processMouseMotionEvent((MouseEvent) e); + else + processMouseEvent((MouseEvent) e); } else if (e instanceof ComponentEvent) processComponentEvent((ComponentEvent) e); @@ -1867,9 +1895,9 @@ public abstract class Component implements ImageObserver, MenuContainer, else if (e instanceof HierarchyEvent) { if (e.id == HierarchyEvent.HIERARCHY_CHANGED) - processHierarchyEvent((HierarchyEvent) e); - else - processHierarchyBoundsEvent((HierarchyEvent) e); + processHierarchyEvent((HierarchyEvent) e); + else + processHierarchyBoundsEvent((HierarchyEvent) e); } } @@ -1887,20 +1915,20 @@ public abstract class Component implements ImageObserver, MenuContainer, switch (e.id) { case ComponentEvent.COMPONENT_HIDDEN: - componentListener.componentHidden(e); - break; - + componentListener.componentHidden(e); + break; + case ComponentEvent.COMPONENT_MOVED: - componentListener.componentMoved(e); - break; - - case ComponentEvent.COMPONENT_RESIZED: - componentListener.componentResized(e); - break; - - case ComponentEvent.COMPONENT_SHOWN: - componentListener.componentShown(e); - break; + componentListener.componentMoved(e); + break; + + case ComponentEvent.COMPONENT_RESIZED: + componentListener.componentResized(e); + break; + + case ComponentEvent.COMPONENT_SHOWN: + componentListener.componentShown(e); + break; } } @@ -1918,11 +1946,11 @@ public abstract class Component implements ImageObserver, MenuContainer, switch (e.id) { case FocusEvent.FOCUS_GAINED: - focusListener.focusGained(e); - break; + focusListener.focusGained(e); + break; case FocusEvent.FOCUS_LOST: - focusListener.focusLost(e); - break; + focusListener.focusLost(e); + break; } } @@ -1939,15 +1967,15 @@ public abstract class Component implements ImageObserver, MenuContainer, return; switch (e.id) { - case KeyEvent.KEY_PRESSED: - keyListener.keyPressed(e); - break; - case KeyEvent.KEY_RELEASED: - keyListener.keyReleased(e); - break; - case KeyEvent.KEY_TYPED: - keyListener.keyTyped(e); - break; + case KeyEvent.KEY_PRESSED: + keyListener.keyPressed(e); + break; + case KeyEvent.KEY_RELEASED: + keyListener.keyReleased(e); + break; + case KeyEvent.KEY_TYPED: + keyListener.keyTyped(e); + break; } } @@ -1964,21 +1992,21 @@ public abstract class Component implements ImageObserver, MenuContainer, return; switch (e.id) { - case MouseEvent.MOUSE_CLICKED: - mouseListener.mouseClicked(e); - break; + case MouseEvent.MOUSE_CLICKED: + mouseListener.mouseClicked(e); + break; case MouseEvent.MOUSE_ENTERED: - mouseListener.mouseEntered(e); - break; - case MouseEvent.MOUSE_EXITED: - mouseListener.mouseExited(e); - break; - case MouseEvent.MOUSE_PRESSED: - mouseListener.mousePressed(e); - break; - case MouseEvent.MOUSE_RELEASED: - mouseListener.mouseReleased(e); - break; + mouseListener.mouseEntered(e); + break; + case MouseEvent.MOUSE_EXITED: + mouseListener.mouseExited(e); + break; + case MouseEvent.MOUSE_PRESSED: + mouseListener.mousePressed(e); + break; + case MouseEvent.MOUSE_RELEASED: + mouseListener.mouseReleased(e); + break; } } @@ -1995,13 +2023,13 @@ public abstract class Component implements ImageObserver, MenuContainer, return; switch (e.id) { - case MouseEvent.MOUSE_DRAGGED: - mouseMotionListener.mouseDragged(e); - break; + case MouseEvent.MOUSE_DRAGGED: + mouseMotionListener.mouseDragged(e); + break; case MouseEvent.MOUSE_MOVED: - mouseMotionListener.mouseMoved(e); - break; - } + mouseMotionListener.mouseMoved(e); + break; + } } /** @since 1.2 */ @@ -2011,13 +2039,13 @@ public abstract class Component implements ImageObserver, MenuContainer, return; switch (e.id) { - case InputMethodEvent.CARET_POSITION_CHANGED: + case InputMethodEvent.CARET_POSITION_CHANGED: inputMethodListener.caretPositionChanged(e); - break; - case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: + break; + case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: inputMethodListener.inputMethodTextChanged(e); - break; - } + break; + } } /** @since 1.3 */ @@ -2037,11 +2065,11 @@ public abstract class Component implements ImageObserver, MenuContainer, switch (e.id) { case HierarchyEvent.ANCESTOR_MOVED: - hierarchyBoundsListener.ancestorMoved(e); - break; - case HierarchyEvent.ANCESTOR_RESIZED: - hierarchyBoundsListener.ancestorResized(e); - break; + hierarchyBoundsListener.ancestorMoved(e); + break; + case HierarchyEvent.ANCESTOR_RESIZED: + hierarchyBoundsListener.ancestorResized(e); + break; } } @@ -2058,13 +2086,13 @@ public abstract class Component implements ImageObserver, MenuContainer, switch (event.id) { case PaintEvent.PAINT: - paint(gfx); - break; + paint(gfx); + break; case PaintEvent.UPDATE: - update(gfx); - break; + update(gfx); + break; default: - throw new IllegalArgumentException("unknown paint event"); + throw new IllegalArgumentException("unknown paint event"); } } @@ -2315,8 +2343,8 @@ public abstract class Component implements ImageObserver, MenuContainer, String name = getName(); if (name != null) { - param.append(name); - param.append(","); + param.append(name); + param.append(","); } param.append(width); param.append("x"); @@ -2420,7 +2448,7 @@ public abstract class Component implements ImageObserver, MenuContainer, } public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) + PropertyChangeListener listener) { if (changeSupport == null) changeSupport = new PropertyChangeSupport(this); @@ -2482,4 +2510,84 @@ lostFocus(Event event, Object what) } */ -} + /** + * This class provides accessibility support for subclasses of container. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.3 + * @XXX Shell class, to allow compilation. This needs documentation and + * correct implementation. + */ + protected abstract class AccessibleAWTComponent extends AccessibleContext + implements Serializable, AccessibleComponent + { + /** + * Compatible with JDK 1.3+. + */ + private static final long serialVersionUID = 642321655757800191L; + + /** + * Converts show/hide events to PropertyChange events. + * + * @serial the component handler + */ + protected ComponentListener accessibleAWTComponentHandler; + + /** + * Converts focus events to PropertyChange events. + * + * @serial the focus handler + */ + protected FocusListener accessibltAWTFocusHandler; + + /** + * The default constructor. + */ + protected AccessibleAWTComponent() + { + } + + public void addPropertyChangeListener(PropertyChangeListener l) {} + public void removePropertyChangeListener(PropertyChangeListener l){} + public String getAccessibleName() { return null; } + public String getAccessibleDescription() { return null; } + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.AWT_COMPONENT; + } + public AccessibleStateSet getAccessibleStateSet() { return null; } + public Accessible getAccessibleParent() { return null; } + public int getAccessibleIndexInParent() { return -1; } + public int getAccessibleChildrenCount() { return 0; } + public Accessible getAccessibleChild(int i) { return null; } + public Locale getLocale() { return null; } + public AccessibleComponent getAccessibleComponent() { return null; } + public Color getBackground() { return null; } + public void setBackground(Color c) {} + public Color getForeground() { return null; } + public void setForeground(Color c) {} + public Cursor getCursor() { return null; } + public void setCursor(Cursor cursor) {} + public Font getFont() { return null; } + public void setFont(Font f) {} + public FontMetrics getFontMetrics(Font f) { return null; } + public boolean isEnabled() { return false; } + public void setEnabled(boolean b) {} + public boolean isVisible() { return false; } + public void setVisible(boolean b) {} + public boolean isShowing() { return false; } + public boolean contains(Point p) { return false; } + public Point getLocationOnScreen() { return null; } + public Point getLocation() { return null; } + public void setLocation(Point p) {} + public Rectangle getBounds() { return null; } + public void setBounds(Rectangle r) {} + public Dimension getSize() { return null; } + public void setSize(Dimension d) {} + public Accessible getAccessibleAt(Point p) { return null; } + public boolean isFocusTraversable() { return false; } + public void requestFocus() {} + public void addFocusListener(FocusListener l) {} + public void removeFocusListener(FocusListener l) {} + } // class AccessibleAWTComponent +} // class Component diff --git a/java/awt/Container.java b/java/awt/Container.java index 0995a743c..f3e0fd8dd 100644 --- a/java/awt/Container.java +++ b/java/awt/Container.java @@ -1,4 +1,5 @@ -/* Copyright (C) 1999, 2000, 2002 Free Software Foundation +/* Container.java -- parent container class in AWT + Copyright (C) 1999, 2000, 2002 Free Software Foundation This file is part of GNU Classpath. @@ -36,28 +37,50 @@ exception statement from your version. */ package java.awt; -import java.awt.event.*; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.util.EventListener; +import java.awt.event.ContainerEvent; +import java.awt.event.ContainerListener; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.LightweightPeer; - -/* A somewhat incomplete class. */ - +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.EventListener; +import javax.accessibility.Accessible; + +/** + * A generic window toolkit object that acts as a container for other objects. + * Components are tracked in a list, and new elements are at the end of the + * list or bottom of the stacking order. + * + * @author original author unknown + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.0 + * @status still missing 1.4 support + */ public class Container extends Component { + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = 4613797578919906343L; + /* Serialized fields from the serialization spec. */ int ncomponents; Component[] component; LayoutManager layoutMgr; - /* LightweightDispatcher dispatcher; */ // wtf? + + // XXX Implement package visible class java.awt.LightweightDispatcher. + /* LightweightDispatcher dispatcher; */ + Dimension maxSize; + + /** @since 1.4 */ + boolean focusCycleRoot; + int containerSerializedDataVersion; /* Anything else is non-serializable, and should be declared "transient". */ - transient ContainerListener containerListener; + transient ContainerListener containerListener; /** * Default constructor for subclasses. @@ -81,7 +104,7 @@ public class Container extends Component * * @return The number of components in this container. * - * @deprecated This method is deprecated in favor of + * @deprecated This method is deprecated in favor of * <code>getComponentCount()</code>. */ public int countComponents() @@ -242,10 +265,10 @@ public class Container extends Component protected void addImpl (Component comp, Object constraints, int index) { if (index > ncomponents - || (index < 0 && index != -1) - || comp instanceof Window - || (comp instanceof Container - && ((Container) comp).isAncestorOf (this))) + || (index < 0 && index != -1) + || comp instanceof Window + || (comp instanceof Container + && ((Container) comp).isAncestorOf (this))) throw new IllegalArgumentException (); // Reparent component, and make sure component is instantiated if @@ -255,10 +278,10 @@ public class Container extends Component comp.parent = this; if (peer != null) { - comp.addNotify (); + comp.addNotify (); - if (comp.isLightweight()) - enableEvents(comp.eventMask); + if (comp.isLightweight()) + enableEvents(comp.eventMask); } invalidate (); @@ -270,39 +293,39 @@ public class Container extends Component // copying when growing the array. It probably doesn't matter. if (ncomponents >= component.length) { - int nl = component.length * 2; - Component[] c = new Component[nl]; - System.arraycopy (component, 0, c, 0, ncomponents); - component = c; + int nl = component.length * 2; + Component[] c = new Component[nl]; + System.arraycopy (component, 0, c, 0, ncomponents); + component = c; } if (index == -1) component[ncomponents++] = comp; else { - System.arraycopy (component, index, component, index + 1, - ncomponents - index); - component[index] = comp; - ++ncomponents; + System.arraycopy (component, index, component, index + 1, + ncomponents - index); + component[index] = comp; + ++ncomponents; } // Notify the layout manager. if (layoutMgr != null) { - if (layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - lm2.addLayoutComponent (comp, constraints); - } - else if (constraints instanceof String) - layoutMgr.addLayoutComponent ((String) constraints, comp); - else - layoutMgr.addLayoutComponent (null, comp); + if (layoutMgr instanceof LayoutManager2) + { + LayoutManager2 lm2 = (LayoutManager2) layoutMgr; + lm2.addLayoutComponent (comp, constraints); + } + else if (constraints instanceof String) + layoutMgr.addLayoutComponent ((String) constraints, comp); + else + layoutMgr.addLayoutComponent (null, comp); } // Post event to notify of adding the container. ContainerEvent ce = new ContainerEvent (this, - ContainerEvent.COMPONENT_ADDED, - comp); + ContainerEvent.COMPONENT_ADDED, + comp); getToolkit().getSystemEventQueue().postEvent(ce); } @@ -318,7 +341,7 @@ public class Container extends Component r.removeNotify (); System.arraycopy (component, index + 1, component, index, - ncomponents - index - 1); + ncomponents - index - 1); component[--ncomponents] = null; invalidate (); @@ -328,8 +351,8 @@ public class Container extends Component // Post event to notify of adding the container. ContainerEvent ce = new ContainerEvent (this, - ContainerEvent.COMPONENT_REMOVED, - r); + ContainerEvent.COMPONENT_REMOVED, + r); getToolkit().getSystemEventQueue().postEvent(ce); } @@ -342,11 +365,11 @@ public class Container extends Component { for (int i = 0; i < ncomponents; ++i) { - if (component[i] == comp) - { - remove (i); - break; - } + if (component[i] == comp) + { + remove (i); + break; + } } } @@ -418,10 +441,10 @@ public class Container extends Component // FIXME: use the tree lock? synchronized (this) { - if (! isValid ()) - { - validateTree (); - } + if (! isValid ()) + { + validateTree (); + } } } @@ -432,30 +455,30 @@ public class Container extends Component protected void validateTree() { if (valid) - return; + return; ContainerPeer cPeer = null; if ((peer != null) && !(peer instanceof LightweightPeer)) { - cPeer = (ContainerPeer) peer; - cPeer.beginValidate(); + cPeer = (ContainerPeer) peer; + cPeer.beginValidate(); } doLayout (); for (int i = 0; i < ncomponents; ++i) { - Component comp = component[i]; - if (! comp.isValid ()) - { - if (comp instanceof Container) - { - ((Container) comp).validateTree(); - } - else - { - component[i].validate(); - } - } + Component comp = component[i]; + if (! comp.isValid ()) + { + if (comp instanceof Container) + { + ((Container) comp).validateTree(); + } + else + { + component[i].validate(); + } + } } /* children will call invalidate() when they are layed out. It @@ -490,8 +513,8 @@ public class Container extends Component * Returns the preferred size of this container. * * @return The preferred size of this container. - * - * @deprecated This method is deprecated in favor of + * + * @deprecated This method is deprecated in favor of * <code>getPreferredSize()</code>. */ public Dimension preferredSize() @@ -516,8 +539,8 @@ public class Container extends Component * Returns the minimum size of this container. * * @return The minimum size of this container. - * - * @deprecated This method is deprecated in favor of + * + * @deprecated This method is deprecated in favor of * <code>getMinimumSize()</code>. */ public Dimension minimumSize() @@ -534,8 +557,8 @@ public class Container extends Component { if (layoutMgr != null && layoutMgr instanceof LayoutManager2) { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.maximumLayoutSize (this); + LayoutManager2 lm2 = (LayoutManager2) layoutMgr; + return lm2.maximumLayoutSize (this); } else return super.getMaximumSize (); @@ -552,8 +575,8 @@ public class Container extends Component { if (layoutMgr instanceof LayoutManager2) { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.getLayoutAlignmentX (this); + LayoutManager2 lm2 = (LayoutManager2) layoutMgr; + return lm2.getLayoutAlignmentX (this); } else return super.getAlignmentX(); @@ -570,8 +593,8 @@ public class Container extends Component { if (layoutMgr instanceof LayoutManager2) { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - return lm2.getLayoutAlignmentY (this); + LayoutManager2 lm2 = (LayoutManager2) layoutMgr; + return lm2.getLayoutAlignmentY (this); } else return super.getAlignmentY(); @@ -594,7 +617,7 @@ public class Container extends Component visitChildren(g, GfxPaintVisitor.INSTANCE, true); } - /** + /** * Perform a graphics operation on the children of this container. * For each applicable child, the visitChild() method will be called * to perform the graphics operation. @@ -609,18 +632,18 @@ public class Container extends Component * be visited. */ private void visitChildren(Graphics gfx, GfxVisitor visitor, - boolean lightweightOnly) + boolean lightweightOnly) { // FIXME: do locking for (int i = 0; i < ncomponents; ++i) { - Component comp = component[i]; - boolean applicable = comp.isVisible() - && (comp.isLightweight() || !lightweightOnly); + Component comp = component[i]; + boolean applicable = comp.isVisible() + && (comp.isLightweight() || !lightweightOnly); - if (applicable) - visitChild(gfx, visitor, comp); + if (applicable) + visitChild(gfx, visitor, comp); } } @@ -638,17 +661,17 @@ public class Container extends Component * @param comp The child component that should be visited. */ private void visitChild(Graphics gfx, GfxVisitor visitor, - Component comp) + Component comp) { Rectangle bounds = comp.getBounds(); Rectangle clip = gfx.getClipBounds().intersection(bounds); - + if (clip.isEmpty()) return; Graphics gfx2 = gfx.create(); gfx2.setClip(clip.x, clip.y, clip.width, clip.height); gfx2.translate(bounds.x, bounds.y); - + visitor.visit(comp, gfx2); } @@ -707,12 +730,12 @@ public class Container extends Component { if ((e.id <= ContainerEvent.CONTAINER_LAST && e.id >= ContainerEvent.CONTAINER_FIRST) - && (containerListener != null - || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) - processEvent(e); + && (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) + processEvent(e); else super.dispatchEventImpl(e); - } + } /** * Adds the specified container listener to this object's list of @@ -772,12 +795,12 @@ public class Container extends Component switch (e.id) { case ContainerEvent.COMPONENT_ADDED: - containerListener.componentAdded(e); - break; + containerListener.componentAdded(e); + break; case ContainerEvent.COMPONENT_REMOVED: - containerListener.componentRemoved(e); - break; + containerListener.componentRemoved(e); + break; } } @@ -786,7 +809,7 @@ public class Container extends Component * * @param event The event that occurred. * - * @deprecated This method is deprecated in favor of + * @deprecated This method is deprecated in favor of * <code>dispatchEvent()</code>. */ public void deliverEvent(Event e) @@ -813,14 +836,14 @@ public class Container extends Component return null; for (int i = 0; i < ncomponents; ++i) { - // Ignore invisible children... - if (!component[i].isVisible()) - continue; - - int x2 = x - component[i].x; - int y2 = y - component[i].y; - if (component[i].contains (x2, y2)) - return component[i]; + // Ignore invisible children... + if (!component[i].isVisible()) + continue; + + int x2 = x - component[i].x; + int y2 = y - component[i].y; + if (component[i].contains (x2, y2)) + return component[i]; } return this; } @@ -871,23 +894,23 @@ public class Container extends Component for (int i = 0; i < ncomponents; ++i) { - // Ignore invisible children... - if (!component[i].isVisible()) - continue; - - int x2 = x - component[i].x; - int y2 = y - component[i].y; - // We don't do the contains() check right away because - // findComponentAt would redundantly do it first thing. - if (component[i] instanceof Container) - { - Container k = (Container) component[i]; - Component r = k.findComponentAt (x2, y2); - if (r != null) - return r; - } - else if (component[i].contains (x2, y2)) - return component[i]; + // Ignore invisible children... + if (!component[i].isVisible()) + continue; + + int x2 = x - component[i].x; + int y2 = y - component[i].y; + // We don't do the contains() check right away because + // findComponentAt would redundantly do it first thing. + if (component[i] instanceof Container) + { + Container k = (Container) component[i]; + Component r = k.findComponentAt (x2, y2); + if (r != null) + return r; + } + else if (component[i].contains (x2, y2)) + return component[i]; } return this; @@ -913,9 +936,9 @@ public class Container extends Component { for (int i = ncomponents; --i >= 0; ) { - component[i].addNotify(); - if (component[i].isLightweight()) - enableEvents(component[i].eventMask); + component[i].addNotify(); + if (component[i].isLightweight()) + enableEvents(component[i].eventMask); } } @@ -944,11 +967,11 @@ public class Container extends Component { for (;;) { - if (comp == null) - return false; - if (comp == this) - return true; - comp = comp.getParent(); + if (comp == null) + return false; + if (comp == this) + return true; + comp = comp.getParent(); } } @@ -1035,46 +1058,152 @@ public class Container extends Component int start, end; if (child != null) { - for (start = 0; start < ncomponents; ++start) - { - if (component[start] == child) - break; - } - end = start; - // This special case lets us be sure to terminate. - if (end == 0) - end = ncomponents; - ++start; + for (start = 0; start < ncomponents; ++start) + { + if (component[start] == child) + break; + } + end = start; + // This special case lets us be sure to terminate. + if (end == 0) + end = ncomponents; + ++start; } else { - start = 0; - end = ncomponents; + start = 0; + end = ncomponents; } for (int j = start; j != end; ++j) { - if (j >= ncomponents) - { - // The JCL says that we should wrap here. However, that - // seems wrong. To me it seems that focus order should be - // global within in given window. So instead if we reach - // the end we try to look in our parent, if we have one. - if (parent != null) - return parent.findNextFocusComponent (this); - j -= ncomponents; - } - if (component[j] instanceof Container) - { - Component c = component[j]; - c = c.findNextFocusComponent (null); - if (c != null) - return c; - } - else if (component[j].isFocusTraversable ()) - return component[j]; + if (j >= ncomponents) + { + // The JCL says that we should wrap here. However, that + // seems wrong. To me it seems that focus order should be + // global within in given window. So instead if we reach + // the end we try to look in our parent, if we have one. + if (parent != null) + return parent.findNextFocusComponent (this); + j -= ncomponents; + } + if (component[j] instanceof Container) + { + Component c = component[j]; + c = c.findNextFocusComponent (null); + if (c != null) + return c; + } + else if (component[j].isFocusTraversable ()) + return component[j]; } return null; } -} + + /** + * This class provides accessibility support for subclasses of container. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.3 + */ + protected class AccessibleAWTContainer extends AccessibleAWTComponent + { + /** + * Compatible with JDK 1.4+. + */ + private static final long serialVersionUID = 5081320404842566097L; + + /** + * The handler to fire PropertyChange when children are added or removed. + * + * @serial the handler for property changes + */ + protected ContainerListener accessibleContainerHandler; + + /** + * The default constructor. + */ + protected AccessibleAWTContainer() + { + } + + /** + * Return the number of accessible children of the containing accessible + * object (at most the total number of its children). + * + * @return the number of accessible children + */ + public int getAccessibleChildrenCount() + { + // XXX + throw new Error("not implemented"); + } + + /** + * Return the nth accessible child of the containing accessible object. + * + * @param i the child to grab, zero-based + * @return the accessible child, or null + */ + public Accessible getAccessibleChild(int i) + { + // XXX + throw new Error("not implemented"); + } + + /** + * Return the accessible child located at point (in the parent's + * coordinates), if one exists. + * + * @param p the point to look at + * @return an accessible object at that point, or null + */ + public Accessible getAccessibleAt(Point p) + { + // XXX + throw new Error("not implemented"); + } + + /** + * This class fires a <code>PropertyChange</code> listener, if registered, + * when children are added or removed from the enclosing accessible object. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.3 + */ + protected class AccessibleContainerHandler implements ContainerListener + { + /** + * Default constructor. + */ + protected AccessibleContainerHandler() + { + } + + /** + * Fired when a component is added; forwards to the PropertyChange + * listener. + * + * @param e the container event for adding + */ + public void componentAdded(ContainerEvent e) + { + // XXX + throw new Error("not implemented"); + } + + /** + * Fired when a component is removed; forwards to the PropertyChange + * listener. + * + * @param e the container event for removing + */ + public void componentRemoved(ContainerEvent e) + { + // XXX + throw new Error("not implemented"); + } + } // class AccessibleContainerHandler + } // class AccessibleAWTPanel +} // class Container diff --git a/java/awt/DisplayMode.java b/java/awt/DisplayMode.java new file mode 100644 index 000000000..b988e20be --- /dev/null +++ b/java/awt/DisplayMode.java @@ -0,0 +1,164 @@ +/* DisplayMode.java -- a description of display mode configurations + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +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 java.awt; + +/** + * This encapsulates information about the display mode for a graphics + * device configuration. They are device dependent, and may not always be + * available. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @see GraphicsDevice + * @since 1.4 + * @status updated to 1.4 + */ +public final class DisplayMode +{ + /** + * Value of the bit depth if multiple depths are supported. + * + * @see #getBitDepth() + */ + public static final int BIT_DEPTH_MULTI = -1; + + /** + * Value of an unknown refresh rate. + * + * @see #getRefreshRate() + */ + public static final int REFRESH_RATE_UNKNOWN = 0; + + /** The width. */ + private final int width; + + /** The height. */ + private final int height; + + /** The bit depth. */ + private final int bitDepth; + + /** The refresh rate. */ + private final int refreshRate; + + /** + * Create a mode with the given parameters. + * + * @param width the width + * @param height the height + * @param bitDepth the bitDepth + * @param refreshRate the refreshRate + * @see #BIT_DEPTH_MULTI + * @see #REFRESH_RATE_UNKNOWN + */ + public DisplayMode(int width, int height, int bitDepth, int refreshRate) + { + this.width = width; + this.height = height; + this.bitDepth = bitDepth; + this.refreshRate = refreshRate; + } + + /** + * Returns the height, in pixels. + * + * @return the height + */ + public int getHeight() + { + return height; + } + + /** + * Returns the width, in pixels. + * + * @return the width + */ + public int getWidth() + { + return width; + } + + /** + * Returns the bit depth, in bits per pixel. This may be BIT_DEPTH_MULTI. + * + * @return the bit depth + * @see #BIT_DEPTH_MULTI + */ + public int getBitDepth() + { + return bitDepth; + } + + /** + * Returns the refresh rate, in hertz. This may be REFRESH_RATE_UNKNOWN. + * + * @return the refresh rate + * @see #REFRESH_RATE_UNKNOWN + */ + public int getRefreshRate() + { + return refreshRate; + } + + /** + * Test for equality. This returns true for two modes with identical + * parameters. + * + * @param o the object to compare to + * @return true if it is equal + */ + public boolean equals(Object o) + { + if (! (o instanceof DisplayMode)) + return false; + DisplayMode m = (DisplayMode) o; + return width == m.width && height == m.height && bitDepth == m.bitDepth + && refreshRate == m.refreshRate; + } + + /** + * Returns a hash code for the display mode. + * + * @return the hash code + */ + public int hashCode() + { + return width + height + bitDepth + refreshRate; + } +} // class DisplayMode diff --git a/java/awt/GraphicsConfigTemplate.java b/java/awt/GraphicsConfigTemplate.java new file mode 100644 index 000000000..52da16799 --- /dev/null +++ b/java/awt/GraphicsConfigTemplate.java @@ -0,0 +1,106 @@ +/* GraphicsConfigTemplate.java -- a template for selecting configurations + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +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 java.awt; + +import java.io.Serializable; + +/** + * This allows filtering an array of GraphicsConfigurations for the best + * one based on various requirements. The resulting configuration has had + * all non-default attributes set as required to meet or exceed the request. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @see GraphicsConfiguration + * @see GraphicsDevice + * @since 1.2 + * @status updated to 1.4 + */ +public abstract class GraphicsConfigTemplate implements Serializable +{ + /** + * Compatible with JDK 1.2+. + */ + private static final long serialVersionUID = -8061369279557787079L; + + /** States that a feature is required to select a configuration. */ + public static final int REQUIRED = 1; + + /** + * States that a feature is preferred, but not required, to select a + * configuration. In the case of multiple valid configurations, the tie + * breaks in favor of the one with the feature. + */ + public static final int PREFERRED = 2; + + /** + * States that a feature is not necessary in the configuration. In the case + * of multiple valid configurations, the tie breaks in favor of the one + * without the feature, to reduce overhead. + */ + public static final int UNNECESSARY = 3; + + /** + * The default constructor. + */ + public GraphicsConfigTemplate() + { + } + + /** + * Returns the "best" match among the array of possible configurations, given + * the criteria of this template. + * + * @param array the array to choose from + * @return the best match + * @throws NullPointerException if array is null + */ + public abstract GraphicsConfiguration getBestConfiguration + (GraphicsConfiguration[] array); + + /** + * Returns true if the given configuration supports all the features required + * by this template. + * + * @param config the configuration to test + * @return true if it is a match + * @throws NullPointerException if config is null + */ + public abstract boolean isGraphicsConfigSupported + (GraphicsConfiguration config); +} // class GraphicsConfigTemplate diff --git a/java/awt/GraphicsConfiguration.java b/java/awt/GraphicsConfiguration.java index 4e0fa6472..5497fc65c 100644 --- a/java/awt/GraphicsConfiguration.java +++ b/java/awt/GraphicsConfiguration.java @@ -51,9 +51,7 @@ public abstract class GraphicsConfiguration { } - /* public abstract GraphicsDevice getDevice(); - */ public abstract BufferedImage createCompatibleImage(int width, int height); public abstract BufferedImage createCompatibleImage(int width, int height, diff --git a/java/awt/GraphicsDevice.java b/java/awt/GraphicsDevice.java new file mode 100644 index 000000000..27d3cd67c --- /dev/null +++ b/java/awt/GraphicsDevice.java @@ -0,0 +1,271 @@ +/* GraphicsDevice.java -- information about a graphics device + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +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 java.awt; + +/** + * This describes a graphics device available to the given environment. This + * includes screen and printer devices, and the different configurations for + * each device. Also, this allows you to create virtual devices which operate + * over a multi-screen environment. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @see GraphicsEnvironment + * @see GraphicsConfiguration + * @since 1.3 + * @status updated to 1.4 + */ +public abstract class GraphicsDevice +{ + /** Device is a raster screen. */ + public static final int TYPE_RASTER_SCREEN = 0; + + /** Device is a printer. */ + public static final int TYPE_PRINTER = 1; + + /** Device is an image buffer not visible to the user. */ + public static final int TYPE_IMAGE_BUFFER = 2; + + /** The current full-screen window, or null if there is none. */ + private Window full_screen; + + /** The current display mode, or null if unknown. */ + private DisplayMode mode; + + /** + * The default constructor. + * + * @see GraphicsEnvironment#getScreenDevices() + * @see GraphicsEnvironment#getDefaultScreenDevice() + * @see GraphicsConfiguration#getDevice() + */ + protected GraphicsDevice() + { + } + + /** + * Returns the type of the device. + * + * @return the device type + * @see #TYPE_RASTER_SCREEN + * @see #TYPE_PRINTER + * @see #TYPE_IMAGE_BUFFER + */ + public abstract int getType(); + + /** + * Returns an identification string for the device. This can be + * vendor-specific, and may be useful for debugging. + * + * @return the identification + */ + public abstract String getIDstring(); + + /** + * Return all configurations valid for this device. + * + * @return an array of configurations + */ + public abstract GraphicsConfiguration[] getConfigurations(); + + /** + * Return the default configuration for this device. + * + * @return the default configuration + */ + public abstract GraphicsConfiguration getDefaultConfiguration(); + + /** + * Return the best configuration, according to the criteria in the given + * template. + * + * @param template the template to adjust by + * @return the best configuration + * @throws NullPointerException if template is null + */ + public GraphicsConfiguration getBestConfiguration + (GraphicsConfigTemplate template) + { + return template.getBestConfiguration(getConfigurations()); + } + + /** + * Returns true if the device supports full-screen exclusive mode. The + * default implementation returns true; subclass it if this is not the case. + * + * @return true if full screen support is available + * @since 1.4 + */ + public boolean isFullScreenSupported() + { + return true; + } + + /** + * Toggle the given window between full screen and normal mode. The previous + * full-screen window, if different, is restored; if the given window is + * null, no window will be full screen. If + * <code>isFullScreenSupported()</code> returns true, full screen mode is + * considered to be exclusive, which implies:<ul> + * <li>Windows cannot overlap the full-screen window. All other application + * windows will always appear beneath the full-screen window in the + * Z-order.</li> + * <li>Input method windows are disabled. It is advisable to call + * <code>Component.enableInputMethods(false)</code> to make a component + * a non-client of the input method framework.</li> + * </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. + * + * @param w the window to toggle + * @see #isFullScreenSupported() + * @see getFullScreenWindow() + * @see setDisplayMode(DisplayMode) + * @see Component#enableInputMethods(boolean) + * @since 1.4 + */ + public synchronized void setFullScreenWindow(Window w) + { + 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"); + } + + /** + * Returns the current full-screen window of the device, or null if no + * window is full-screen. + * + * @return the full-screen window + * @see #setFullScreenWindow(Window) + * @since 1.4 + */ + public Window getFullScreenWindow() + { + return full_screen; + } + + /** + * Returns whether this device supports low-level display changes. This may + * depend on whether full-screen exclusive mode is available. + * + * XXX The default implementation returns false for now. + * + * @return true if display changes are supported + * @see #setDisplayMode(DisplayMode) + * @since 1.4 + */ + public boolean isDisplayChangeSupported() + { + return false; + } + + /** + * Sets the display mode. This may be dependent on the availability of + * full-screen exclusive mode. + * + * @param mode the new mode + * @throws IllegalArgumentException if the new mode is not in getDisplayModes + * @throws UnsupportedOperationException if ! isDisplayChangeSupported() + * @see #getDisplayMode() + * @see #getDisplayModes() + * @see #isDisplayChangeSupported() + * @since 1.4 + */ + public void setDisplayMode(DisplayMode mode) + { + DisplayMode[] array = getDisplayModes(); + if (! isDisplayChangeSupported()) + throw new UnsupportedOperationException(); + int i = array == null ? 0 : array.length; + while (--i >= 0) + if (array[i].equals(mode)) + break; + if (i < 0) + throw new IllegalArgumentException(); + this.mode = mode; + } + + /** + * 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() + { + return mode; + } + + /** + * Return an array of all available display modes. This implementation + * returns a 0-length array, so subclasses must override this. + * + * @return the array of available modes + * @since 1.4 + */ + public DisplayMode[] getDisplayModes() + { + return new DisplayMode[0]; + } + + /** + * Return the number of bytes available in accelerated memory on this + * device. The device may support creation or caching on a first-come, + * first-served basis, depending on the operating system and driver. + * Memory may be a finite resource, and because of multi-threading, you + * are not guaranteed that the result of this method ensures your image + * will successfully be put in accelerated memory. A negative result means + * the memory is unlimited. The default implementation assumes no special + * memory is available, and returns 0. + * + * @return the size of accelerated memory available + * @see VolatileImage#flush() + * @see ImageCapabilities#isAccelerated() + */ + public int getAvailableAcceleratedMemory() + { + return 0; + } +} // class GraphicsDevice diff --git a/java/awt/GraphicsEnvironment.java b/java/awt/GraphicsEnvironment.java new file mode 100644 index 000000000..63e23e2f1 --- /dev/null +++ b/java/awt/GraphicsEnvironment.java @@ -0,0 +1,210 @@ +/* GraphicsEnvironment.java -- information about the graphics environment + Copyright (C) 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +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 java.awt; + +import java.awt.image.BufferedImage; +import java.util.Locale; + +/** + * This descibes the collection of GraphicsDevice and Font objects available + * on a given platform. The resources might be local or remote, and specify + * the valid configurations for displaying graphics. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @see GraphicsDevice + * @see GraphicsConfiguration + * @since 1.4 + * @status updated to 1.4 + */ +public abstract class GraphicsEnvironment +{ + /** + * The environment must be obtained from a factory or query method, hence + * this constructor is protected. + */ + protected GraphicsEnvironment() + { + } + + /** + * Returns the local graphics environment. + * + * XXX Not implemented in Classpath yet. + * @return the local environment + */ + public static GraphicsEnvironment getLocalGraphicsEnvironment() + { + throw new Error("not implemented"); + } + + /** + * Check if the local 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. + * + * XXX For now, Classpath assumes that it is never headless. + * + * @return true if the environment is headless, meaning that graphics are + * unsupported + * @since 1.4 + */ + public static boolean isHeadless() + { + // XXX Should be: getLocalGraphicsEnvironment().isHeadlessInstance(); + return false; + } + + /** + * 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. + * + * @return true if the environment is headless, meaning that graphics are + * unsupported + * @since 1.4 + */ + public boolean isHeadlessInstance() + { + return false; + } + + /** + * Get an array of all the GraphicsDevice objects. + * + * @return the available graphics devices, may be 0 length + * @throws HeadlessException if the environment is headless + */ + public abstract GraphicsDevice[] getScreenDevices(); + + /** + * Get the default screen GraphicsDevice object. + * + * @return the default screen device + * @throws HeadlessException if the environment is headless + */ + public abstract GraphicsDevice getDefaultScreenDevice(); + + /** + * Return a Graphics2D object which will render into the specified image. + * + * @param image the image to render into + * @return the object that renders into the image + */ + public abstract Graphics2D createGraphics(BufferedImage image); + + /** + * Returns an array of the one-point size fonts available in this + * environment. From there, the user can select the font and derive the + * correct one of proper size and attributes, using <code>deriveFont</code>. + * Only one master version of each font appears in this array; if a font + * can be derived from another, it must be created in that way. + * + * @return the array of available fonts + * @see #getAvailableFontFamilyNames() + * @see Font#deriveFont(int, float) + * @since 1.2 + */ + public abstract Font[] getAllFonts(); + + /** + * Returns an array of the font family names available in this environment. + * This allows flexibility in choosing the style of font, while still letting + * the Font class decide its best match. + * + * @return the array of available font families + * @see #getAllFonts() + * @see Font#getFamily() + * @since 1.2 + */ + public abstract String[] getAvailableFontFamilyNames(); + + /** + * Returns an array of the font family names available in this environment, + * localized to the current Locale if l is non-null. This allows + * flexibility in choosing the style of font, while still letting the Font + * class decide its best match. + * + * @param l the locale to use + * @return the array of available font families, localized + * @see #getAllFonts() + * @see Font#getFamily() + * @since 1.2 + */ + public abstract String[] getAvailableFontFamilyNames(Locale l); + + /** + * Returns the point where a window should be centered. You should probably + * also check that the window fits within the screen bounds. The default + * simply returns the center of the maximum window bounds; subclasses should + * override this if native objects (like scrollbars) make that off-centered. + * + * @return the centering point + * @throws HeadlessException if the environment is headless + * @see #getMaximumWindowBounds() + * @since 1.4 + */ + public Point getCenterPoint() + { + Rectangle r = getMaximumWindowBounds(); + return new Point(r.x + r.width / 2, r.y + r.height / 2); + } + + /** + * Returns the maximum bounds for a centered window object. The default + * implementation simply returns the bounds of the default configuration + * of the default screen; subclasses should override this to if native + * objects (like scrollbars) reduce what is truly available. Also, + * subclasses should override this if the window should be centered across + * a multi-screen display. + * + * @return the maximum window bounds + * @throws HeadlessException if the environment is headless + * @see #getCenterPoint() + * @see GraphicsConfiguration#getBounds() + * @see Toolkit#getScreenInsets(GraphicsConfiguration) + * @since 1.4 + */ + public Rectangle getMaximumWindowBounds() + { + return getDefaultScreenDevice().getDefaultConfiguration().getBounds(); + } +} // class GraphicsEnvironment diff --git a/java/awt/Makefile.am b/java/awt/Makefile.am index 33425f1ef..f429e854b 100644 --- a/java/awt/Makefile.am +++ b/java/awt/Makefile.am @@ -25,6 +25,7 @@ Container.java \ Cursor.java \ Dialog.java \ Dimension.java \ +DisplayMode.java \ EventDispatchThread.java \ Event.java \ EventQueue.java \ @@ -35,7 +36,10 @@ FontFormatException.java \ FontMetrics.java \ Frame.java \ Graphics2D.java \ +GraphicsConfigTemplate.java \ GraphicsConfiguration.java \ +GraphicsDevice.java \ +GraphicsEnvironment.java \ Graphics.java \ GridBagConstraints.java \ GridLayout.java \ diff --git a/java/awt/Panel.java b/java/awt/Panel.java index 06fcb3ed2..23336bc6b 100644 --- a/java/awt/Panel.java +++ b/java/awt/Panel.java @@ -1,4 +1,4 @@ -/* Panel.java -- Simple container object. +/* Panel.java -- Simple container object Copyright (C) 1999, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,59 +41,109 @@ package java.awt; import java.awt.peer.PanelPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.ComponentPeer; +import java.io.Serializable; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; /** - * A panel is a simple container class. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Panel extends Container implements java.io.Serializable -{ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>Panel</code> that has a default - * layout manager of <code>FlowLayout</code>. - */ -public -Panel() -{ - this(new FlowLayout()); -} - -/*************************************************************************/ - -/** - * Initializes a new instance of <code>Panel</code> with the specified - * layout manager. - * - * @param layoutManager The layout manager for this object. - */ -public -Panel(LayoutManager layoutManager) -{ - setLayout(layoutManager); -} - -/*************************************************************************/ - -/* - * Instance Methods + * A panel is a simple container class. It's default layout is the + * <code>FlowLayout</code> manager. + * + * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Eric Blake <ebb9@email.byu.edu> + * @see FlowLayout + * @since 1.0 + * @status updated to 1.4 */ - -/** - * Notifies this object to create its native peer. - */ -public void -addNotify() +public class Panel extends Container implements Accessible { - if (peer == null) - peer = getToolkit().createPanel(this); - super.addNotify(); -} - + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = -2728009084054400034L; + + /** The cached accessible context. */ + private transient AccessibleContext context; + + /** + * Initializes a new instance of <code>Panel</code> that has a default + * layout manager of <code>FlowLayout</code>. + */ + public Panel() + { + this(new FlowLayout()); + } + + /** + * Initializes a new instance of <code>Panel</code> with the specified + * layout manager. + * + * @param layoutManager the layout manager for this object + * @since 1.1 + */ + public Panel(LayoutManager layoutManager) + { + setLayout(layoutManager); + } + + /** + * Notifies this object to create its native peer. + * + * @see #isDisplayable() + * @see #removeNotify() + */ + public void addNotify() + { + if (peer == null) + peer = getToolkit().createPanel(this); + super.addNotify(); + } + + /** + * Gets the AccessibleContext associated with this panel, creating one if + * necessary. This always returns an instance of {@link AccessibleAWTPanel}. + * + * @return the accessibility context of this panel + * @since 1.3 + */ + public AccessibleContext getAccessibleContext() + { + if (context == null) + context = new AccessibleAWTPanel(); + return context; + } + + /** + * This class provides accessibility support for Panels, and is the + * runtime type returned by {@link #getAccessibleContext()}. + * + * @author Eric Blake <ebb9@email.byu.edu> + * @since 1.3 + */ + protected class AccessibleAWTPanel extends AccessibleAWTContainer + { + /** + * Compatible with JDK 1.4+. + */ + private static final long serialVersionUID = -6409552226660031050L; + + /** + * The default constructor. + */ + protected AccessibleAWTPanel() + { + } + + /** + * Get the role of this accessible object, a panel. + * + * @return the role of the object + * @see AccessibleRole#PANEL + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.PANEL; + } + } // class AccessibleAWTPanel } // class Panel - |