src/share/classes/sun/applet/AppletViewerPanel.java
author Jaroslav Tulach <jtulach@netbeans.org>
Mon, 22 Jun 2009 17:38:36 +0200
brancheliminateswing
changeset 1256 a4d32dc556eb
parent 0 37a05a11f281
permissions -rw-r--r--
All parts of the code compile after the 'client' separation
     1 /*
     2  * Copyright 1995-2005 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 
    26 package sun.applet;
    27 
    28 import java.util.*;
    29 import java.net.URL;
    30 import java.net.MalformedURLException;
    31 import java.applet.*;
    32 
    33 
    34 /**
    35  * Sample applet panel class. The panel manages and manipulates the
    36  * applet as it is being loaded. It forks a seperate thread in a new
    37  * thread group to call the applet's init(), start(), stop(), and
    38  * destroy() methods.
    39  *
    40  * @author      Arthur van Hoff
    41  */
    42 class AppletViewerPanel extends AppletPanel {
    43 
    44     /* Are we debugging? */
    45     static boolean debug = false;
    46 
    47     /**
    48      * The document url.
    49      */
    50     URL documentURL;
    51 
    52     /**
    53      * The base url.
    54      */
    55     URL baseURL;
    56 
    57     /**
    58      * The attributes of the applet.
    59      */
    60     Hashtable atts;
    61 
    62     /*
    63      * JDK 1.1 serialVersionUID
    64      */
    65     private static final long serialVersionUID = 8890989370785545619L;
    66 
    67     /**
    68      * Construct an applet viewer and start the applet.
    69      */
    70     AppletViewerPanel(URL documentURL, Hashtable atts) {
    71         this.documentURL = documentURL;
    72         this.atts = atts;
    73 
    74         String att = getParameter("codebase");
    75         if (att != null) {
    76             if (!att.endsWith("/")) {
    77                 att += "/";
    78             }
    79             try {
    80                 baseURL = new URL(documentURL, att);
    81             } catch (MalformedURLException e) {
    82             }
    83         }
    84         if (baseURL == null) {
    85             String file = documentURL.getFile();
    86             int i = file.lastIndexOf('/');
    87             if (i >= 0 && i < file.length() - 1) {
    88                 try {
    89                     baseURL = new URL(documentURL, file.substring(0, i + 1));
    90                 } catch (MalformedURLException e) {
    91                 }
    92             }
    93         }
    94 
    95         // when all is said & done, baseURL shouldn't be null
    96         if (baseURL == null)
    97                 baseURL = documentURL;
    98 
    99 
   100     }
   101 
   102     /**
   103      * Get an applet parameter.
   104      */
   105     public String getParameter(String name) {
   106         return (String)atts.get(name.toLowerCase());
   107     }
   108 
   109     /**
   110      * Get the document url.
   111      */
   112     public URL getDocumentBase() {
   113         return documentURL;
   114 
   115     }
   116 
   117     /**
   118      * Get the base url.
   119      */
   120     public URL getCodeBase() {
   121         return baseURL;
   122     }
   123 
   124     /**
   125      * Get the width.
   126      */
   127     public int getWidth() {
   128         String w = getParameter("width");
   129         if (w != null) {
   130             return Integer.valueOf(w).intValue();
   131         }
   132         return 0;
   133     }
   134 
   135 
   136     /**
   137      * Get the height.
   138      */
   139     public int getHeight() {
   140         String h = getParameter("height");
   141         if (h != null) {
   142             return Integer.valueOf(h).intValue();
   143         }
   144         return 0;
   145     }
   146 
   147     /**
   148      * Get initial_focus
   149      */
   150     public boolean hasInitialFocus()
   151     {
   152 
   153         // 6234219: Do not set initial focus on an applet
   154         // during startup if applet is targeted for
   155         // JDK 1.1/1.2. [stanley.ho]
   156         if (isJDK11Applet() || isJDK12Applet())
   157             return false;
   158 
   159         String initialFocus = getParameter("initial_focus");
   160 
   161         if (initialFocus != null)
   162         {
   163             if (initialFocus.toLowerCase().equals("false"))
   164                 return false;
   165         }
   166 
   167         return true;
   168     }
   169 
   170     /**
   171      * Get the code parameter
   172      */
   173     public String getCode() {
   174         return getParameter("code");
   175     }
   176 
   177 
   178     /**
   179      * Return the list of jar files if specified.
   180      * Otherwise return null.
   181      */
   182     public String getJarFiles() {
   183         return getParameter("archive");
   184     }
   185 
   186     /**
   187      * Return the value of the object param
   188      */
   189     public String getSerializedObject() {
   190         return getParameter("object");// another name?
   191     }
   192 
   193 
   194     /**
   195      * Get the applet context. For now this is
   196      * also implemented by the AppletPanel class.
   197      */
   198     public AppletContext getAppletContext() {
   199         return (AppletContext)getParent();
   200     }
   201 
   202     static void debug(String s) {
   203         if(debug)
   204             System.err.println("AppletViewerPanel:::" + s);
   205     }
   206 
   207     static void debug(String s, Throwable t) {
   208         if(debug) {
   209             t.printStackTrace();
   210             debug(s);
   211         }
   212     }
   213 }