001: /*
002: * @(#)AppletViewerPanel.java 1.33 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package sun.applet;
029:
030: import java.util.*;
031: import java.io.*;
032: import java.net.URL;
033: import java.net.MalformedURLException;
034: import java.awt.*;
035: import java.applet.*;
036:
037: //import sun.tools.jar.*;
038:
039: /**
040: * Sample applet panel class. The panel manages and manipulates the
041: * applet as it is being loaded. It forks a seperate thread in a new
042: * thread group to call the applet's init(), start(), stop(), and
043: * destroy() methods.
044: *
045: * @version 1.29, 08/19/02
046: * @author Arthur van Hoff
047: */
048: class AppletViewerPanel extends AppletPanel {
049: /* Are we debugging? */
050: static boolean debug = false;
051: /**
052: * The document url.
053: */
054: URL documentURL;
055: /**
056: * The base url.
057: */
058: URL baseURL;
059: /**
060: * The attributes of the applet.
061: */
062: Hashtable atts;
063: /*
064: * JDK 1.1 serialVersionUID
065: */
066: private static final long serialVersionUID = 8890989370785545619L;
067:
068: /**
069: * Construct an applet viewer and start the applet.
070: */
071: AppletViewerPanel(URL documentURL, Hashtable atts) {
072: this .documentURL = documentURL;
073: this .atts = atts;
074: String att = getParameter("codebase");
075: if (att != null) {
076: if (!att.endsWith("/")) {
077: att += "/";
078: }
079: try {
080: baseURL = new URL(documentURL, att);
081: } catch (MalformedURLException e) {
082: }
083: }
084: if (baseURL == null) {
085: String file = documentURL.getFile();
086: int i = file.lastIndexOf('/');
087: if (i >= 0 && i < file.length() - 1) {
088: try {
089: baseURL = new URL(documentURL, file.substring(0,
090: i + 1));
091: } catch (MalformedURLException e) {
092: }
093: }
094: }
095: // when all is said & done, baseURL shouldn't be null
096: if (baseURL == null)
097: baseURL = documentURL;
098: }
099:
100: /**
101: * Get an applet parameter.
102: */
103: public String getParameter(String name) {
104: return (String) atts.get(name.toLowerCase());
105: }
106:
107: /**
108: * Get the document url.
109: */
110: public URL getDocumentBase() {
111: return documentURL;
112: }
113:
114: /**
115: * Get the base url.
116: */
117: public URL getCodeBase() {
118: return baseURL;
119: }
120:
121: /**
122: * Get the width.
123: */
124: public int getWidth() {
125: String w = getParameter("width");
126: if (w != null) {
127: return Integer.valueOf(w).intValue();
128: }
129: return 0;
130: }
131:
132: /**
133: * Get the height.
134: */
135: public int getHeight() {
136: String h = getParameter("height");
137: if (h != null) {
138: return Integer.valueOf(h).intValue();
139: }
140: return 0;
141: }
142:
143: /**
144: * Get the code parameter
145: */
146: public String getCode() {
147: return getParameter("code");
148: }
149:
150: /**
151: * Return the list of jar files if specified.
152: * Otherwise return null.
153: */
154: public String getJarFiles() {
155: return getParameter("archive");
156: }
157:
158: /**
159: * Return the value of the object param
160: */
161: public String getSerializedObject() {
162: return getParameter("object");// another name?
163: }
164:
165: /**
166: * Get the applet context. For now this is
167: * also implemented by the AppletPanel class.
168: */
169: public AppletContext getAppletContext() {
170: return (AppletContext) getParent();
171: }
172:
173: static void debug(String s) {
174: if (debug)
175: System.err.println("AppletViewerPanel:::" + s);
176: }
177:
178: static void debug(String s, Throwable t) {
179: if (debug) {
180: t.printStackTrace();
181: debug(s);
182: }
183: }
184: }
|