home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 3.2 KB | 130 lines |
- /*
- * @(#)AppletViewerPanel.java 1.4 96/04/08
- *
- * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package sun.applet;
-
- import java.util.*;
- import java.io.*;
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.awt.*;
- import java.applet.*;
- import java.awt.image.MemoryImageSource;
- import java.awt.image.ColorModel;
-
-
- /**
- * Sample applet panel class. The panel manages and manipulates the
- * applet as it is being loaded. It forks a seperate thread in a new
- * thread group to call the applet's init(), start(), stop(), and
- * destroy() methods.
- *
- * @version 1.4, 04/08/96
- * @author Arthur van Hoff
- */
- class AppletViewerPanel extends AppletPanel {
- /**
- * The document url.
- */
- URL documentURL;
-
- /**
- * The base url.
- */
- URL baseURL;
-
- /**
- * The attributes of the applet.
- */
- Hashtable atts;
-
- /**
- * Construct an applet viewer and start the applet.
- */
- AppletViewerPanel(URL documentURL, Hashtable atts) {
- this.documentURL = documentURL;
- this.atts = atts;
-
- String att = getParameter("zipbase");
- if (att != null) {
- if (!att.endsWith("/")) {
- try {
- baseURL = new URL(documentURL, att);
- } catch (MalformedURLException e) {
- }
- }
- }
- if (baseURL == null) {
- att = getParameter("codebase");
- if (att != null) {
- if (!att.endsWith("/")) {
- att += "/";
- }
- try {
- baseURL = new URL(documentURL, att);
- } catch (MalformedURLException e) {
- }
- }
- }
- if (baseURL == null) {
- String file = documentURL.getFile();
- int i = file.lastIndexOf('/');
- if (i > 0 && i < file.length() - 1) {
- try {
- baseURL = new URL(documentURL, file.substring(0, i + 1));
- } catch (MalformedURLException e) {
- }
- }
- }
-
- // when all is said & done, baseURL shouldn't be null
- if (baseURL == null)
- baseURL = documentURL;
- }
-
- /**
- * Get an applet parameter.
- */
- public String getParameter(String name) {
- return (String)atts.get(name.toLowerCase());
- }
-
- /**
- * Get the document url.
- */
- public URL getDocumentBase() {
- return documentURL;
- }
-
- /**
- * Get the base url.
- */
- public URL getCodeBase() {
- return baseURL;
- }
-
- /**
- * Get the applet context. For now this is
- * also implemented by the AppletPanel class.
- */
- public AppletContext getAppletContext() {
- return (AppletContext)getParent();
- }
- }
-