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