Changeset 1391 for branches/GNU/src/gcc/libjava/java/applet/Applet.java
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/applet/Applet.java (modified) (2 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/applet/Applet.java
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 1 /* Applet.java -- Java base applet class 2 Copyright (C) 1999 Free Software Foundation, Inc.3 2 Copyright (C) 1999 Free Software Foundation, Inc. 3 4 4 This file is part of GNU Classpath. 5 5 6 6 GNU Classpath is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 GNU Classpath is distributed in the hope that it will be useful, but 12 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 14 General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 19 02111-1307 USA. 20 20 21 21 Linking this library statically or dynamically with other modules is 22 22 making a combined work based on this library. Thus, the terms and … … 40 40 41 41 import java.awt.Dimension; 42 43 42 44 import java.awt.Image; 45 46 47 48 43 49 import java.net.URL; 44 50 import java.util.Locale; 51 52 53 54 45 55 46 56 /** 47 * This is the base applet class. An applet is a Java program that 48 * runs inside a web browser or other applet viewer in a restricted 49 * environment. 50 * 51 * @author Aaron M. Renn ([email protected]) 52 */ 53 public class Applet extends java.awt.Panel implements java.io.Serializable 57 * This is the base applet class. An applet is a Java program that 58 * runs inside a web browser or other applet viewer in a restricted 59 * environment. 60 * 61 * <p>To be useful, a subclass should override at least start(). Also useful 62 * are init, stop, and destroy for control purposes, and getAppletInfo and 63 * getParameterInfo for descriptive purposes. 64 * 65 * @author Aaron M. Renn <[email protected]> 66 * @author Eric Blake <[email protected]> 67 * @since 1.0 68 * @status updated to 1.4 69 */ 70 public class Applet extends Panel 54 71 { 55 // The applet stub for this applet 56 private AppletStub stub; 57 58 /** 59 * Default constructor for subclasses. 60 */ 61 public Applet() {} 62 63 /** 64 * Returns the URL of the document this applet is embedded in. 65 * 66 * @return The URL of the document this applet is embedded in. 67 */ 72 /** 73 * Compatible with JDK 1.0+. 74 */ 75 private static final long serialVersionUID = -5836846270535785031L; 76 77 /** The applet stub for this applet. */ 78 private transient AppletStub stub; 79 80 /** 81 * The accessibility context for this applet. 82 * 83 * @serial the accessibleContext for this 84 * @since 1.2 85 */ 86 private AccessibleContext accessibleContext; 87 88 /** 89 * Default constructor for subclasses. 90 * 91 * @throws HeadlessException if in a headless environment 92 */ 93 public Applet() 94 { 95 if (GraphicsEnvironment.isHeadless()) 96 throw new HeadlessException(); 97 } 98 99 /** 100 * The browser calls this method to set the applet's stub, which is the 101 * low level interface to the browser. Manually setting this to null is 102 * asking for problems down the road. 103 * 104 * @param stub the applet stub for this applet 105 */ 106 public final void setStub(AppletStub stub) 107 { 108 this.stub = stub; 109 } 110 111 /** 112 * Tests whether or not this applet is currently active. An applet is active 113 * just before the browser invokes start(), and becomes inactive just 114 * before the browser invokes stop(). 115 * 116 * @return <code>true</code> if this applet is active 117 */ 118 public boolean isActive() 119 { 120 return stub.isActive(); 121 } 122 123 /** 124 * Returns the basename URL of the document this applet is embedded in. This 125 * is everything up to the final '/'. 126 * 127 * @return the URL of the document this applet is embedded in 128 * @see #getCodeBase() 129 */ 68 130 public URL getDocumentBase() 69 131 { 70 return (stub.getDocumentBase ());71 } 72 73 /** 74 * Returns the URL of the code base for this applet.75 *76 * @return The URL of the code base for this applet.77 */132 return ); 133 } 134 135 /** 136 * Returns the URL of the code base for this applet. 137 * 138 139 */ 78 140 public URL getCodeBase() 79 141 { 80 return (stub.getCodeBase ()); 81 } 82 83 /** 84 * Returns the value of the specified parameter that was specified in 85 * the <APPLET> tag for this applet. 86 * 87 * @param name The parameter name. 88 * 89 * @param value The parameter value, or <code>null</code> if the parameter 90 * does not exist. 91 */ 142 return stub.getCodeBase(); 143 } 144 145 /** 146 * Returns the value of the specified parameter that was specified in 147 * the <code><APPLET></code> tag for this applet. 148 * 149 * @param name the parameter name 150 * @return the parameter value, or null if the parameter does not exist 151 * @throws NullPointerException if name is null 152 */ 92 153 public String getParameter(String name) 93 154 { 94 return (stub.getParameter (name));95 } 96 97 /** 98 * Returns the applet context for this applet.99 *100 * @return The applet context for this applet.101 */155 return ); 156 } 157 158 /** 159 * Returns the applet context for this applet. 160 * 161 162 */ 102 163 public AppletContext getAppletContext() 103 164 { 104 return (stub.getAppletContext ()); 105 } 106 107 /** 108 * Tests whether or not this applet is currently active. 109 * 110 * @return <code>true</code> if this applet is active, <code>false</code> 111 * otherwise. 112 */ 113 public boolean isActive() 114 { 115 return (stub.isActive ()); 116 } 117 118 /** 119 * Requests that the applet window for this applet be resized. 120 * 121 * @param width The new width in pixels. 122 * @param height The new height in pixels. 123 */ 165 return stub.getAppletContext(); 166 } 167 168 /** 169 * Requests that the applet window for this applet be resized. 170 * 171 * @param width the new width in pixels 172 * @param height the new height in pixels 173 */ 124 174 public void resize(int width, int height) 125 175 { 126 stub.appletResize (width, height);127 } 128 129 /** 130 * Requests that the applet window for this applet be resized.131 *132 * @param dim The <code>Dimension</code> object with the requested133 * width and height.134 */176 stub.appletResize(width, height); 177 } 178 179 /** 180 * Requests that the applet window for this applet be resized. 181 * 182 183 184 */ 135 185 public void resize(Dimension dim) 136 186 { 137 resize (dim.width, dim.height); 138 } 139 140 /** 141 * Returns an audio clip from the specified URL. 142 * 143 * @param url The URL of the audio clip. 144 * 145 * @return The retrieved audio clip. 146 */ 187 resize(dim.width, dim.height); 188 } 189 190 /** 191 * Displays the specified message in the status window if that window 192 * exists. 193 * 194 * @param message the status message, may be null 195 */ 196 public void showStatus(String message) 197 { 198 getAppletContext().showStatus(message); 199 } 200 201 /** 202 * Returns an image from the specified URL. Note that the image is not 203 * actually retrieved until the applet attempts to display it, so this 204 * method returns immediately. 205 * 206 * @param url the URL of the image 207 * @return the retrieved image 208 * @throws NullPointerException if url is null 209 */ 210 public Image getImage(URL url) 211 { 212 return getAppletContext().getImage(url); 213 } 214 215 /** 216 * Returns an image from the specified absolute URL, and relative path 217 * from that URL. Note that the image is not actually retrieved until the 218 * applet attempts to display it, so this method returns immediately. 219 * This calls <code>getImage(new URL(url, name))</code>, but if building 220 * the new URL fails, this returns null. 221 * 222 * @param url the base URL of the image 223 * @param name the name of the image relative to the URL 224 * @return the retrieved image, or null on failure 225 * @see #getImage(URL) 226 */ 227 public Image getImage(URL url, String name) 228 { 229 try 230 { 231 return getImage(new URL(url, name)); 232 } 233 catch (MalformedURLException e) 234 { 235 return null; 236 } 237 } 238 239 /** 240 * Returns an audio clip from the specified URL. This clip is not tied to 241 * any particular applet. 242 * 243 * XXX Classpath does not yet implement this. 244 * 245 * @param url the URL of the audio clip 246 * @return the retrieved audio clip 247 * @throws NullPointerException if url is null 248 * @see #getAudioClip(URL) 249 * @since 1.2 250 */ 251 public static final AudioClip newAudioClip(URL url) 252 { 253 // This requires an implementation of AudioClip in gnu.java.applet. 254 throw new Error("Not implemented"); 255 } 256 257 /** 258 * Returns an audio clip from the specified URL. Note that the clip is not 259 * actually retrieved until the applet attempts to play it, so this method 260 * returns immediately. 261 * 262 * @param url the URL of the audio clip 263 * @return the retrieved audio clip 264 * @throws NullPointerException if url is null 265 */ 147 266 public AudioClip getAudioClip(URL url) 148 267 { 149 return (getAppletContext ().getAudioClip (url)); 150 } 151 152 /** 153 * Returns an audio clip from the specified URL and name 154 * 155 * @param url The base URL of the audio clip. 156 * @param name The name of the clip relative to the URL. 157 * 158 * @return The retrieved audio clip. 159 */ 268 return getAppletContext().getAudioClip(url); 269 } 270 271 /** 272 * Returns an audio clip from the specified absolute URL, and relative path 273 * from that URL. Note that the clip is not actually retrieved until the 274 * applet attempts to play it, so this method returns immediately. This 275 * calls <code>getAudioClip(new URL(url, name))</code>, but if building 276 * the new URL fails, this returns null. 277 * 278 * @param url the base URL of the audio clip 279 * @param name the name of the clip relative to the URL 280 * @return the retrieved audio clip, or null on failure 281 * @see #getAudioClip(URL) 282 */ 160 283 public AudioClip getAudioClip(URL url, String name) 161 284 { 162 285 try 163 286 { 164 return (getAppletContext ().getAudioClip (new URL (url.toExternalForm() 165 + name))); 166 } 167 catch(Exception e) 168 { 169 return (getAudioClip (url)); 170 } 171 } 172 173 /** 174 * Loads and plays the audio clip pointed to by the specified URL. 175 * 176 * @param The URL of the audio clip. 177 */ 178 public void play (URL url) 179 { 180 getAudioClip (url).play (); 181 } 182 183 /** 184 * Loads and plays the audio clip pointed to by the specified URL. 185 * 186 * @param The base URL of the audio clip. 187 * @param name The name of the audio clip relative to the URL. 188 */ 189 public void play (URL url, String name) 190 { 191 getAudioClip (url, name).play (); 192 } 193 194 /** 195 * Returns an image from the specified URL. Note that the image is not 196 * actually retrieved until the applet attempts to display it, so this 197 * method returns immediately. 198 * 199 * @param url The URL of the image. 200 * 201 * @return The retrieved image. 202 */ 203 public Image getImage(URL url) 204 { 205 return (getAppletContext ().getImage (url)); 206 } 207 208 /** 209 * Returns an image from the specified URL. Note that the image is not 210 * actually retrieved until the applet attempts to display it, so this 211 * method returns immediately. 212 * 213 * @param url The base URL of the image. 214 * @param name The name of the image relative to the URL. 215 * 216 * @return The retrieved image. 217 */ 218 public Image getImage(URL url, String name) 219 { 287 return getAudioClip(new URL(url, name)); 288 } 289 catch (MalformedURLException e) 290 { 291 return null; 292 } 293 } 294 295 /** 296 * Returns a descriptive string with applet defined information. The 297 * implementation in this class returns <code>null</code>, so subclasses 298 * must override to return information. 299 * 300 * @return a string describing the author, version, and applet copyright 301 */ 302 public String getAppletInfo() 303 { 304 return null; 305 } 306 307 /** 308 * Returns the locale for this applet, if it has been set. If no applet 309 * specific locale has been set, the default locale is returned. 310 * 311 * @return the locale for this applet 312 * @see Component#setLocale(Locale) 313 * @since 1.1 314 */ 315 public Locale getLocale() 316 { 317 return super.getLocale(); 318 } 319 320 /** 321 * Returns a list of parameters this applet supports. Each element of 322 * the outer array is an array of three strings with the name of the 323 * parameter, the data type or valid values, and a description. This 324 * method is optional and the default implementation returns null. 325 * 326 * @return the list of parameters supported by this applet 327 */ 328 public String[][] getParameterInfo() 329 { 330 return null; 331 } 332 333 /** 334 * Loads and plays the audio clip pointed to by the specified URL. This does 335 * nothing if the URL does not point to a valid audio clip. 336 * 337 * @param url the URL of the audio clip 338 * @throws NullPointerException if url is null 339 * @see #getAudioClip(URL) 340 */ 341 public void play(URL url) 342 { 343 AudioClip ac = getAudioClip(url); 220 344 try 221 345 { 222 return (getAppletContext ().getImage (new URL (url.toExternalForm() 223 + name))); 224 } 225 catch(Exception e) 226 { 227 return (getImage (url)); 228 } 229 } 230 231 /** 232 * Returns the locale for this applet, if it has been set. If no applet 233 * specific locale has been set, the default locale is returned. 234 * 235 * @return The locale for this applet. 236 */ 237 public Locale getLocale() 238 { 239 return (super.getLocale ()); 240 } 241 242 /** 243 * Returns a descriptive string with applet defined information. The 244 * implementation in this class returns <code>null</code>. Applets who 245 * wish to return this information should override. 246 * 247 * @return A string describing the applet. 248 */ 249 public String getAppletInfo() 250 { 251 return (null); 252 } 253 254 /** 255 * Returns a list of parameters this applet supports. Each element of 256 * the array is a list of three strings with the name of the parameter, 257 * the data type or valid values, and a description. This method is 258 * optional and the default implementation returns <code>null</code>. 259 * 260 * @return The list of parameters supported by this applet. 261 */ 262 public String[][] getParameterInfo() 263 { 264 return (null); 265 } 266 267 /** 268 * This method is called when the applet is first loaded. The default 269 * implementation does nothing. Applets that wish to do one time 270 * initialization should override. 271 */ 272 public void init() {} 273 274 /** 275 * This method is called when the applet is being unloaded. The default 276 * implementation does nothing. Applets that need to clean up resources 277 * on exit should override. 278 */ 279 public void destroy() {} 280 281 /** 282 * This method is called when the applet should start running. This is 283 * normally each time a web page containing it is loaded. The default 284 * implemention does nothing. Subclasses should override. 285 */ 286 public void start() {} 287 288 /** 289 * This method is called when the applet should stop running. This is 290 * normally when the next web page is loaded. The default implementation 291 * does nothing. 292 */ 293 public void stop() {} 294 295 /** 296 * The browser calls this method to set the applet's stub, which is the 297 * low level interface to the browser. 298 * 299 * @param stub The applet stub for this applet. 300 */ 301 public final void setStub (AppletStub stub) 302 { 303 this.stub = stub; 304 } 305 346 ac.play(); 347 } 348 catch (Exception ignored) 349 { 350 } 351 } 352 353 /** 354 * Loads and plays the audio clip pointed to by the specified absolute URL, 355 * and relative path from that URL. This does nothing if the URL cannot be 356 * constructed, or if it does not point to a valid audio clip. 357 * 358 * @param url the base URL of the audio clip 359 * @param name the name of the audio clip relative to the URL 360 * @see #getAudioClip(URL, String) 361 * @see #play(URL) 362 */ 363 public void play(URL url, String name) 364 { 365 try 366 { 367 getAudioClip(url, name).play(); 368 } 369 catch (Exception ignored) 370 { 371 } 372 } 373 374 /** 375 * This method is called when the applet is first loaded, before start(). 376 * The default implementation does nothing; override to do any one-time 377 * initialization. 378 * 379 * @see #start() 380 * @see #stop() 381 * @see #destroy() 382 */ 383 public void init() 384 { 385 } 386 387 /** 388 * This method is called when the applet should start running. This is 389 * normally each time a web page containing it is loaded. The default 390 * implemention does nothing; override for your applet to be useful. 391 * 392 * @see #init() 393 * @see #stop() 394 * @see #destroy() 395 */ 396 public void start() 397 { 398 } 399 400 /** 401 * This method is called when the applet should stop running. This is 402 * normally when the next web page is loaded. The default implementation 403 * does nothing; override for your applet to stop using resources when 404 * it is no longer visible, but may be restarted soon. 405 * 406 * @see #init() 407 * @see #start() 408 * @see #destroy() 409 */ 410 public void stop() 411 { 412 } 413 414 /** 415 * This method is called when the applet is being unloaded. The default 416 * implementation does nothing; override for your applet to clean up 417 * resources on exit. 418 * 419 * @see #init() 420 * @see #start() 421 * @see #stop() 422 */ 423 public void destroy() 424 { 425 } 426 427 /** 428 * Gets the AccessibleContext associated with this applet, creating one if 429 * necessary. This always returns an instance of {@link AccessibleApplet}. 430 * 431 * @return the accessibility context of this applet 432 * @since 1.3 433 */ 434 public AccessibleContext getAccessibleContext() 435 { 436 if (accessibleContext == null) 437 accessibleContext = new AccessibleApplet(); 438 return accessibleContext; 439 } 440 441 /** 442 * Read an applet from an object stream. This checks for a headless 443 * environment, then does the normal read. 444 * 445 * @param s the stream to read from 446 * @throws ClassNotFoundException if a class is not found 447 * @throws IOException if deserialization fails 448 * @throws HeadlessException if this is a headless environment 449 * @see GraphicsEnvironment#isHeadless() 450 * @since 1.4 451 */ 452 private void readObject(ObjectInputStream s) 453 throws ClassNotFoundException, IOException 454 { 455 if (GraphicsEnvironment.isHeadless()) 456 throw new HeadlessException(); 457 s.defaultReadObject(); 458 } 459 460 /** 461 * This class provides accessibility support for Applets, and is the 462 * runtime type returned by {@link #getAccessibleContext()}. 463 * 464 * @author Eric Blake <[email protected]> 465 * @since 1.3 466 */ 467 protected class AccessibleApplet extends AccessibleAWTPanel 468 { 469 /** 470 * Compatible with JDK 1.4+. 471 */ 472 private static final long serialVersionUID = 8127374778187708896L; 473 474 /** 475 * The default constructor. 476 */ 477 protected AccessibleApplet() 478 { 479 } 480 481 /** 482 * Get the role of this accessible object, a frame. 483 * 484 * @return the role of the object 485 * @see AccessibleRole#FRAME 486 */ 487 public AccessibleRole getAccessibleRole() 488 { 489 return AccessibleRole.FRAME; 490 } 491 492 /** 493 * Get the state set of this accessible object. In addition to the default 494 * states of a Component, the applet can also be active. 495 * 496 * @return the role of the object 497 * @see AccessibleState 498 */ 499 public AccessibleStateSet getAccessibleStateSet() 500 { 501 AccessibleStateSet s = super.getAccessibleStateSet(); 502 if (isActive()) 503 s.add(AccessibleState.ACTIVE); 504 return s; 505 } 506 } // class AccessibleApplet 306 507 } // class Applet 307 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
