From e98da3dcf547827050a49d61ba26841c159b71d6 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Wed, 12 Jul 2000 04:52:04 +0000 Subject: [PATCH] backport: Applet.java: New file. 2000-07-12 Bryce McKinlay Merged implementation of java.applet from classpath: * java/applet/Applet.java: New file. * java/applet/AppletContext.java: New file. * java/applet/AppletStub.java: New file. * java/applet/AudioClip.java: New file. * Makefile.am: Added new java.applet classes. * Makefile.in: Rebuilt. From-SVN: r34981 --- libjava/ChangeLog | 11 ++ libjava/Makefile.am | 4 + libjava/Makefile.in | 6 + libjava/java/applet/Applet.java | 296 +++++++++++++++++++++++++++++++++ libjava/java/applet/AppletContext.java | 108 ++++++++++++ libjava/java/applet/AppletStub.java | 88 ++++++++++ libjava/java/applet/AudioClip.java | 53 ++++++ 7 files changed, 566 insertions(+) create mode 100644 libjava/java/applet/Applet.java create mode 100644 libjava/java/applet/AppletContext.java create mode 100644 libjava/java/applet/AppletStub.java create mode 100644 libjava/java/applet/AudioClip.java diff --git a/libjava/ChangeLog b/libjava/ChangeLog index e99ca61..ce60672 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,16 @@ 2000-07-12 Bryce McKinlay + Merged implementation of java.applet from classpath: + * java/applet/Applet.java: New file. + * java/applet/AppletContext.java: New file. + * java/applet/AppletStub.java: New file. + * java/applet/AudioClip.java: New file. + + * Makefile.am: Added new java.applet classes. + * Makefile.in: Rebuilt. + +2000-07-12 Bryce McKinlay + AWT Stuff: * java/util/ResourceBundle.java (getLocale): stub. * Makefile.am: Added new AWT classes. diff --git a/libjava/Makefile.am b/libjava/Makefile.am index e48a35b..f0a1a64 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -660,6 +660,10 @@ gnu/java/lang/ClassHelper.java \ gnu/java/security/provider/Gnu.java \ gnu/java/security/provider/SHA.java \ gnu/java/security/provider/SHA1PRNG.java \ +java/applet/Applet.java \ +java/applet/AppletStub.java \ +java/applet/AppletContext.java \ +java/applet/AudioClip.java \ java/io/BufferedInputStream.java \ java/io/BufferedOutputStream.java \ java/io/BufferedReader.java \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 3657a60..def9d6f 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -430,6 +430,10 @@ gnu/java/lang/ClassHelper.java \ gnu/java/security/provider/Gnu.java \ gnu/java/security/provider/SHA.java \ gnu/java/security/provider/SHA1PRNG.java \ +java/applet/Applet.java \ +java/applet/AppletStub.java \ +java/applet/AppletContext.java \ +java/applet/AudioClip.java \ java/io/BufferedInputStream.java \ java/io/BufferedOutputStream.java \ java/io/BufferedReader.java \ @@ -1011,6 +1015,8 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/java/security/provider/Gnu.P \ .deps/gnu/java/security/provider/SHA.P \ .deps/gnu/java/security/provider/SHA1PRNG.P .deps/interpret.P \ +.deps/java/applet/Applet.P .deps/java/applet/AppletContext.P \ +.deps/java/applet/AppletStub.P .deps/java/applet/AudioClip.P \ .deps/java/awt/AWTError.P .deps/java/awt/AWTEvent.P \ .deps/java/awt/AWTEventMulticaster.P .deps/java/awt/AWTException.P \ .deps/java/awt/ActiveEvent.P .deps/java/awt/Adjustable.P \ diff --git a/libjava/java/applet/Applet.java b/libjava/java/applet/Applet.java new file mode 100644 index 0000000..fe96239 --- /dev/null +++ b/libjava/java/applet/Applet.java @@ -0,0 +1,296 @@ +/* Applet.java -- Java base applet class + Copyright (C) 1999 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. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + + +package java.applet; + +import java.awt.Dimension; +import java.awt.Image; +import java.net.URL; +import java.util.Locale; + +/** + * 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 +{ + // The applet stub for this applet + private AppletStub stub; + + /** + * Default constructor for subclasses. + */ + public Applet() {} + + /** + * Returns the URL of the document this applet is embedded in. + * + * @return The URL of the document this applet is embedded in. + */ + public URL getDocumentBase() + { + return (stub.getDocumentBase ()); + } + + /** + * 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 ()); + } + + /** + * 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 null if the parameter + * does not exist. + */ + public String getParameter(String name) + { + return (stub.getParameter (name)); + } + + /** + * Returns the applet context for this applet. + * + * @return The applet context for this applet. + */ + public AppletContext getAppletContext() + { + return (stub.getAppletContext ()); + } + + /** + * Tests whether or not this applet is currently active. + * + * @return true if this applet is active, false + * otherwise. + */ + public boolean isActive() + { + return (stub.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) + { + stub.appletResize (width, height); + } + + /** + * Requests that the applet window for this applet be resized. + * + * @param dim The Dimension object with the requested + * width and height. + */ + public void resize(Dimension dim) + { + resize (dim.width, dim.height); + } + + /** + * Returns an audio clip from the specified URL. + * + * @param url The URL of the audio clip. + * + * @return The retrieved audio clip. + */ + public AudioClip getAudioClip(URL 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. + */ + public AudioClip getAudioClip(URL url, String name) + { + try + { + return (getAppletContext ().getAudioClip (new URL (url.toExternalForm() + + name))); + } + catch(Exception e) + { + return (getAudioClip (url)); + } + } + + /** + * Loads and plays the audio clip pointed to by the specified URL. + * + * @param The URL of the audio clip. + */ + public void play (URL url) + { + getAudioClip (url).play (); + } + + /** + * 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) + { + getAudioClip (url, name).play (); + } + + /** + * 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) + { + return (getAppletContext ().getImage (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 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) + { + try + { + return (getAppletContext ().getImage (new URL (url.toExternalForm() + + name))); + } + catch(Exception e) + { + 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() + { + return (super.getLocale ()); + } + + /** + * Returns a descriptive string with applet defined information. The + * implementation in this class returns null. Applets who + * wish to return this information should override. + * + * @return A string describing the applet. + */ + public String getAppletInfo() + { + 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 null. + * + * @return The list of parameters supported by this applet. + */ + public String[][] getParameterInfo() + { + 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 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 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() {} + + /** + * 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() {} + + /** + * 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.stub = stub; + } + +} // class Applet + diff --git a/libjava/java/applet/AppletContext.java b/libjava/java/applet/AppletContext.java new file mode 100644 index 0000000..e8c2c93 --- /dev/null +++ b/libjava/java/applet/AppletContext.java @@ -0,0 +1,108 @@ +/* AppletContext.java -- Access the applet's runtime environment. + Copyright (C) 1999 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. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + + +package java.applet; + +import java.awt.Image; +import java.net.URL; +import java.util.Enumeration; + +/** + * 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) + */ +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? + */ + 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? + */ + 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 null if an applet with + * the requested name cannot be 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. + */ + 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. + */ + 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. + */ + void showDocument(URL url, String target); + + /** + * Displays the specified message in the status window if that window + * exists. + * + * @param message The status message. + */ + void showStatus(String message); + +} // interface AppletContext diff --git a/libjava/java/applet/AppletStub.java b/libjava/java/applet/AppletStub.java new file mode 100644 index 0000000..2684264 --- /dev/null +++ b/libjava/java/applet/AppletStub.java @@ -0,0 +1,88 @@ +/* AppletStub.java -- Low level interface to the browser. + Copyright (C) 1999 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. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + +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) + */ +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. + */ + URL getDocumentBase(); + + /** + * 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 null if the parameter + * does not exist. + */ + String getParameter(String name); + + /** + * 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 true if this applet is active, false + * 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. + */ + void appletResize(int width, int height); + +} // interface AppletStub + diff --git a/libjava/java/applet/AudioClip.java b/libjava/java/applet/AudioClip.java new file mode 100644 index 0000000..add9748 --- /dev/null +++ b/libjava/java/applet/AudioClip.java @@ -0,0 +1,53 @@ +/* AudioClip.java -- Play an audio clip. + Copyright (C) 1999 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. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ + + +package java.applet; + +/** + * This interface provides a simple mechanism for playing audio clips. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface AudioClip +{ + /** + * 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. + */ + void stop(); + + /** + * Plays this audio clip in a continuous loop. + */ + void loop(); + +} // interface AudioClip -- 2.7.4