Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletViewerPanel.java
38829 views
/*1* Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.applet;2627import java.util.*;28import java.io.*;29import java.net.URL;30import java.net.MalformedURLException;31import java.awt.*;32import java.applet.*;33import sun.tools.jar.*;343536/**37* Sample applet panel class. The panel manages and manipulates the38* applet as it is being loaded. It forks a seperate thread in a new39* thread group to call the applet's init(), start(), stop(), and40* destroy() methods.41*42* @author Arthur van Hoff43*/44class AppletViewerPanel extends AppletPanel {4546/* Are we debugging? */47static boolean debug = false;4849/**50* The document url.51*/52URL documentURL;5354/**55* The base url.56*/57URL baseURL;5859/**60* The attributes of the applet.61*/62Hashtable atts;6364/*65* JDK 1.1 serialVersionUID66*/67private static final long serialVersionUID = 8890989370785545619L;6869/**70* Construct an applet viewer and start the applet.71*/72AppletViewerPanel(URL documentURL, Hashtable atts) {73this.documentURL = documentURL;74this.atts = atts;7576String att = getParameter("codebase");77if (att != null) {78if (!att.endsWith("/")) {79att += "/";80}81try {82baseURL = new URL(documentURL, att);83} catch (MalformedURLException e) {84}85}86if (baseURL == null) {87String file = documentURL.getFile();88int i = file.lastIndexOf('/');89if (i >= 0 && i < file.length() - 1) {90try {91baseURL = new URL(documentURL, file.substring(0, i + 1));92} catch (MalformedURLException e) {93}94}95}9697// when all is said & done, baseURL shouldn't be null98if (baseURL == null)99baseURL = documentURL;100101102}103104/**105* Get an applet parameter.106*/107public String getParameter(String name) {108return (String)atts.get(name.toLowerCase());109}110111/**112* Get the document url.113*/114public URL getDocumentBase() {115return documentURL;116117}118119/**120* Get the base url.121*/122public URL getCodeBase() {123return baseURL;124}125126/**127* Get the width.128*/129public int getWidth() {130String w = getParameter("width");131if (w != null) {132return Integer.valueOf(w).intValue();133}134return 0;135}136137138/**139* Get the height.140*/141public int getHeight() {142String h = getParameter("height");143if (h != null) {144return Integer.valueOf(h).intValue();145}146return 0;147}148149/**150* Get initial_focus151*/152public boolean hasInitialFocus()153{154155// 6234219: Do not set initial focus on an applet156// during startup if applet is targeted for157// JDK 1.1/1.2. [stanley.ho]158if (isJDK11Applet() || isJDK12Applet())159return false;160161String initialFocus = getParameter("initial_focus");162163if (initialFocus != null)164{165if (initialFocus.toLowerCase().equals("false"))166return false;167}168169return true;170}171172/**173* Get the code parameter174*/175public String getCode() {176return getParameter("code");177}178179180/**181* Return the list of jar files if specified.182* Otherwise return null.183*/184public String getJarFiles() {185return getParameter("archive");186}187188/**189* Return the value of the object param190*/191public String getSerializedObject() {192return getParameter("object");// another name?193}194195196/**197* Get the applet context. For now this is198* also implemented by the AppletPanel class.199*/200public AppletContext getAppletContext() {201return (AppletContext)getParent();202}203204static void debug(String s) {205if(debug)206System.err.println("AppletViewerPanel:::" + s);207}208209static void debug(String s, Throwable t) {210if(debug) {211t.printStackTrace();212debug(s);213}214}215}216217218