jdk/src/java.desktop/share/classes/sun/applet/AppletViewer.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 31061 fead7d86d75f
child 37550 c8252b8fea3d
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22565
2f3102102bd9 8032397: Remove sun.misc.Ref
darcy
parents: 21785
diff changeset
     2
 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.print.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.print.attribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.applet.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.AppContext;
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28231
diff changeset
    41
import sun.misc.ManagedLocalsThread;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A frame to show the applet tag in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
23642
3ac83ad3fb6a 8037174: Fix serial lint warnings in sun.applet
darcy
parents: 22565
diff changeset
    46
@SuppressWarnings("serial") // JDK-implementation class
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    47
final class TextFrame extends Frame {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Create the tag frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
    52
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    TextFrame(int x, int y, String title, String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        setTitle(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        TextArea txt = new TextArea(20, 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        txt.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        txt.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        add("Center", txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        add("South", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Button b = new Button(amh.getMessage("button.dismiss", "Dismiss"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        p.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        class ActionEventListener implements ActionListener {
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    67
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        b.addActionListener(new ActionEventListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        move(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        WindowListener windowEventListener = new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    80
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            public void windowClosing(WindowEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        addWindowListener(windowEventListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static AppletMessageHandler amh = new AppletMessageHandler("textframe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/**
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    93
 * Lets us construct one using unix-style one shot behaviors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    95
final class StdAppletViewerFactory implements AppletViewerFactory {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
    97
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public AppletViewer createAppletViewer(int x, int y,
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
    99
                                           URL doc, Hashtable<String, String> atts) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return new AppletViewer(x, y, doc, atts, System.out, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   103
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public MenuBar getBaseMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return new MenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   108
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public boolean isStandalone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * The applet viewer makes it possible to run a Java applet without using a browser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * For details on the syntax that <B>appletviewer</B> supports, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <a href="../../../docs/tooldocs/appletviewertags.html">AppletViewer Tags</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * (The document named appletviewertags.html in the JDK's docs/tooldocs directory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *  once the JDK docs have been installed.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
23642
3ac83ad3fb6a 8037174: Fix serial lint warnings in sun.applet
darcy
parents: 22565
diff changeset
   121
@SuppressWarnings("serial") // JDK implementation class
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   122
public class AppletViewer extends Frame implements AppletContext, Printable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Some constants...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static String defaultSaveFile = "Applet.ser";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * The panel in which the applet is being displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    AppletViewerPanel panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * The status line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    Label label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * output status messages to this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    PrintStream statusMsgStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * For cloning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    AppletViewerFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private final class UserActionListener implements ActionListener {
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   152
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            processUserAction(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   159
     * Create the applet viewer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   161
    @SuppressWarnings("deprecation")
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   162
    public AppletViewer(int x, int y, URL doc, Hashtable<String, String> atts,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        PrintStream statusMsgStream, AppletViewerFactory factory) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this.factory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.statusMsgStream = statusMsgStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        setTitle(amh.getMessage("tool.title", atts.get("code")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        MenuBar mb = factory.getBaseMenuBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Menu m = new Menu(amh.getMessage("menu.applet"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        addMenuItem(m, "menuitem.restart");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        addMenuItem(m, "menuitem.reload");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        addMenuItem(m, "menuitem.stop");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        addMenuItem(m, "menuitem.save");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        addMenuItem(m, "menuitem.start");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        addMenuItem(m, "menuitem.clone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        m.add(new MenuItem("-"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        addMenuItem(m, "menuitem.tag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        addMenuItem(m, "menuitem.info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        addMenuItem(m, "menuitem.edit").disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        addMenuItem(m, "menuitem.encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        m.add(new MenuItem("-"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        addMenuItem(m, "menuitem.print");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        m.add(new MenuItem("-"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        addMenuItem(m, "menuitem.props");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        m.add(new MenuItem("-"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        addMenuItem(m, "menuitem.close");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (factory.isStandalone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            addMenuItem(m, "menuitem.quit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        mb.add(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        setMenuBar(mb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        add("Center", panel = new AppletViewerPanel(doc, atts));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        add("South", label = new Label(amh.getMessage("label.hello")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        panel.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        appletPanels.addElement(panel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        move(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        WindowListener windowEventListener = new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   208
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            public void windowClosing(WindowEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                appletClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   213
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            public void windowIconified(WindowEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                appletStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   218
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            public void windowDeiconified(WindowEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                appletStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        class AppletEventListener implements AppletListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            final Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            public AppletEventListener(Frame frame)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                this.frame = frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   233
            @Override
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   234
            @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            public void appletStateChanged(AppletEvent evt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                AppletPanel src = (AppletPanel)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                switch (evt.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    case AppletPanel.APPLET_RESIZE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        if(src != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                            resize(preferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    case AppletPanel.APPLET_LOADING_COMPLETED: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        Applet a = src.getApplet(); // sun.applet.AppletPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        // Fixed #4754451: Applet can have methods running on main
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        // thread event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        // The cause of this bug is that the frame of the applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        // is created in main thread group. Thus, when certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                        // AWT/Swing events are generated, the events will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        // dispatched through the wrong event dispatch thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        // To fix this, we rearrange the AppContext with the frame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        // so the proper event queue will be looked up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        // Swing also maintains a Frame list for the AppContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        // so we will have to rearrange it as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        if (a != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                            AppletPanel.changeFrameAppContext(frame, SunToolkit.targetToAppContext(a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                            AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        addWindowListener(windowEventListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        panel.addAppletListener(new AppletEventListener(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // Start the applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        showStatus(amh.getMessage("status.start"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        initEventQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    // XXX 99/9/10 probably should be "private"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public MenuItem addMenuItem(Menu m, String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        MenuItem mItem = new MenuItem(amh.getMessage(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        mItem.addActionListener(new UserActionListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return m.add(mItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Send the initial set of events to the appletviewer event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * On start-up the current behaviour is to load the applet and call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Applet.init() and Applet.start().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private void initEventQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // appletviewer.send.event is an undocumented and unsupported system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // property which is used exclusively for testing purposes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        String eventList = System.getProperty("appletviewer.send.event");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (eventList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // Add the standard events onto the event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            panel.sendEvent(AppletPanel.APPLET_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            panel.sendEvent(AppletPanel.APPLET_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // We're testing AppletViewer.  Force the specified set of events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            // onto the event queue, wait for the events to be processed, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            // exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // The list of events that will be executed is provided as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            // ","-separated list.  No error-checking will be done on the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            String [] events = splitSeparator(",", eventList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            for (int i = 0; i < events.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                System.out.println("Adding event to queue: " + events[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if (events[i].equals("dispose"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    panel.sendEvent(AppletPanel.APPLET_DISPOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                else if (events[i].equals("load"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    panel.sendEvent(AppletPanel.APPLET_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                else if (events[i].equals("init"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    panel.sendEvent(AppletPanel.APPLET_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                else if (events[i].equals("start"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                else if (events[i].equals("stop"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    panel.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                else if (events[i].equals("destroy"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    panel.sendEvent(AppletPanel.APPLET_DESTROY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                else if (events[i].equals("quit"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    panel.sendEvent(AppletPanel.APPLET_QUIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                else if (events[i].equals("error"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    panel.sendEvent(AppletPanel.APPLET_ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    // non-fatal error if we get an unrecognized event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    System.out.println("Unrecognized event name: " + events[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            while (!panel.emptyEventQueue()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            appletSystemExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Split a string based on the presence of a specified separator.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * an array of arbitrary length.  The end of each element in the array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * indicated by the separator of the end of the string.  If there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * separator immediately before the end of the string, the final element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * will be empty.  None of the strings will contain the separator.  Useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * when separating strings such as "foo/bar/bas" using separator "/".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param sep  The separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param s    The string to split.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return     An array of strings.  Each string in the array is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *             by the location of the provided sep in the original string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *             s.  Whitespace not stripped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private String [] splitSeparator(String sep, String s) {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   357
        Vector<String> v = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int tokenStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        int tokenEnd   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            v.addElement(s.substring(tokenStart, tokenEnd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            tokenStart = tokenEnd+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // Add the final element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        v.addElement(s.substring(tokenStart));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        String [] retVal = new String[v.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        v.copyInto(retVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Methods for java.applet.AppletContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   377
    private static Map<URL, AudioClip> audioClips = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Get an audio clip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   382
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public AudioClip getAudioClip(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        checkConnect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        synchronized (audioClips) {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   386
            AudioClip clip = audioClips.get(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (clip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                audioClips.put(url, clip = new AppletAudioClip(url));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   394
    private static Map<URL, AppletImageRef> imageRefs = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Get an image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   399
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public Image getImage(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return getCachedImage(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
22565
2f3102102bd9 8032397: Remove sun.misc.Ref
darcy
parents: 21785
diff changeset
   404
    /**
2f3102102bd9 8032397: Remove sun.misc.Ref
darcy
parents: 21785
diff changeset
   405
     * Get an image.
2f3102102bd9 8032397: Remove sun.misc.Ref
darcy
parents: 21785
diff changeset
   406
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    static Image getCachedImage(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // System.getSecurityManager().checkConnection(url.getHost(), url.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        synchronized (imageRefs) {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   410
            AppletImageRef ref = imageRefs.get(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                ref = new AppletImageRef(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                imageRefs.put(url, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
22565
2f3102102bd9 8032397: Remove sun.misc.Ref
darcy
parents: 21785
diff changeset
   415
            return ref.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Flush the image cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    static void flushImageCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        imageRefs.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   426
    static Vector<AppletPanel> appletPanels = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Get an applet by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   431
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public Applet getApplet(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        AppletSecurity security = (AppletSecurity)System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        name = name.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        SocketPermission panelSp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            new SocketPermission(panel.getCodeBase().getHost(), "connect");
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   437
        for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   438
            AppletPanel p = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            String param = p.getParameter("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if (param != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                param = param.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (name.equals(param) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                p.getDocumentBase().equals(panel.getDocumentBase())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                SocketPermission sp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    new SocketPermission(p.getCodeBase().getHost(), "connect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                if (panelSp.implies(sp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    return p.applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Return an enumeration of all the accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * applets on this page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   461
    @Override
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   462
    public Enumeration<Applet> getApplets() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        AppletSecurity security = (AppletSecurity)System.getSecurityManager();
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   464
        Vector<Applet> v = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        SocketPermission panelSp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            new SocketPermission(panel.getCodeBase().getHost(), "connect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   468
        for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   469
            AppletPanel p = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (p.getDocumentBase().equals(panel.getDocumentBase())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                SocketPermission sp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    new SocketPermission(p.getCodeBase().getHost(), "connect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (panelSp.implies(sp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    v.addElement(p.applet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return v.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Ignore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   485
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public void showDocument(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Ignore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   492
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public void showDocument(URL url, String target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Show status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   499
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public void showStatus(String status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        label.setText(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   504
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public void setStream(String key, InputStream stream)throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // We do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   509
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public InputStream getStream(String key){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // We do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   515
    @Override
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   516
    public Iterator<String> getStreamKeys(){
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // We do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * System parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   524
    static Hashtable<String, String> systemParam = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        systemParam.put("codebase", "codebase");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        systemParam.put("code", "code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        systemParam.put("alt", "alt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        systemParam.put("width", "width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        systemParam.put("height", "height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        systemParam.put("align", "align");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        systemParam.put("vspace", "vspace");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        systemParam.put("hspace", "hspace");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Print the HTML tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   540
    public static void printTag(PrintStream out, Hashtable<String, String> atts) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        out.print("<applet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   543
        String v = atts.get("codebase");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            out.print(" codebase=\"" + v + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   548
        v = atts.get("code");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            v = "applet.class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        out.print(" code=\"" + v + "\"");
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   553
        v = atts.get("width");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            v = "150";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        out.print(" width=" + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   559
        v = atts.get("height");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            v = "100";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        out.print(" height=" + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   565
        v = atts.get("name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            out.print(" name=\"" + v + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        out.println(">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // A very slow sorting algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        int len = atts.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        String params[] = new String[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        len = 0;
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   575
        for (Enumeration<String> e = atts.keys() ; e.hasMoreElements() ;) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   576
            String param = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            for (; i < len ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                if (params[i].compareTo(param) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            System.arraycopy(params, i, params, i + 1, len - i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            params[i] = param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            len++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        for (int i = 0 ; i < len ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            String param = params[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            if (systemParam.get(param) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                out.println("<param name=" + param +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            " value=\"" + atts.get(param) + "\">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        out.println("</applet>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Make sure the atrributes are uptodate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   601
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public void updateAtts() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        Dimension d = panel.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        Insets in = panel.insets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        panel.atts.put("width",
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   606
                       Integer.toString(d.width - (in.left + in.right)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        panel.atts.put("height",
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   608
                       Integer.toString(d.height - (in.top + in.bottom)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Restart the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    void appletRestart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        panel.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        panel.sendEvent(AppletPanel.APPLET_DESTROY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        panel.sendEvent(AppletPanel.APPLET_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Reload the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    void appletReload() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        panel.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        panel.sendEvent(AppletPanel.APPLET_DESTROY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        panel.sendEvent(AppletPanel.APPLET_DISPOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        /**
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   630
         * Fixed #4501142: Classloader sharing policy doesn't
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * take "archive" into account. This will be overridden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         * by Java Plug-in.                     [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         * Make sure we don't have two threads running through the event queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            panel.joinAppletThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            panel.release();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            return;   // abort the reload
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        panel.createAppletThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        panel.sendEvent(AppletPanel.APPLET_LOAD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        panel.sendEvent(AppletPanel.APPLET_INIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Save the applet to a well known file (for now) as a serialized object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   656
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    void appletSave() {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   658
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   660
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                // XXX: this privileged block should be made smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                // by initializing a private static variable with "user.dir"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                // Applet needs to be stopped for serialization to succeed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                // Since panel.sendEvent only queues the event, there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                // chance that the event will not be processed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                // serialization begins.  However, by sending the event before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                // FileDialog is created, enough time is given such that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                // situation is unlikely to ever occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                panel.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                FileDialog fd = new FileDialog(AppletViewer.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                               amh.getMessage("appletsave.filedialogtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                               FileDialog.SAVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                // needed for a bug under Solaris...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                fd.setDirectory(System.getProperty("user.dir"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                fd.setFile(defaultSaveFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                fd.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                String fname = fd.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                if (fname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    // Restart applet if Save is cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    return null;                // cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                String dname = fd.getDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                File file = new File(dname, fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
21785
fc0bfa7d9d95 8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*
pchelko
parents: 5506
diff changeset
   689
                try (FileOutputStream fos = new FileOutputStream(file);
fc0bfa7d9d95 8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*
pchelko
parents: 5506
diff changeset
   690
                     BufferedOutputStream bos = new BufferedOutputStream(fos);
fc0bfa7d9d95 8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*
pchelko
parents: 5506
diff changeset
   691
                     ObjectOutputStream os = new ObjectOutputStream(bos)) {
fc0bfa7d9d95 8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*
pchelko
parents: 5506
diff changeset
   692
fc0bfa7d9d95 8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*
pchelko
parents: 5506
diff changeset
   693
                    showStatus(amh.getMessage("appletsave.err1", panel.applet.toString(), file.toString()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    os.writeObject(panel.applet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    System.err.println(amh.getMessage("appletsave.err2", ex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Clone the viewer and the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   708
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    void appletClone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        Point p = location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        updateAtts();
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   712
        @SuppressWarnings("unchecked")
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   713
        Hashtable<String, String> tmp = (Hashtable<String, String>) panel.atts.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA,
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   715
                                   panel.documentURL, tmp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Show the applet tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   721
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    void appletTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        ByteArrayOutputStream out = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        updateAtts();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        printTag(new PrintStream(out), panel.atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        showStatus(amh.getMessage("applettag"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        Point p = location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("applettag.textframe"), out.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Show the applet info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   735
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    void appletInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        String str = panel.applet.getAppletInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            str = amh.getMessage("appletinfo.applet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        str += "\n\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        String atts[][] = panel.applet.getParameterInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (atts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            for (int i = 0 ; i < atts.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                str += atts[i][0] + " -- " + atts[i][1] + " -- " + atts[i][2] + "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            str += amh.getMessage("appletinfo.param");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        Point p = location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        new TextFrame(p.x + XDELTA, p.y + YDELTA, amh.getMessage("appletinfo.textframe"), str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Show character encoding type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    void appletCharacterEncoding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        showStatus(amh.getMessage("appletencoding", encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * Edit the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    void appletEdit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Print the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    void appletPrint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        PrinterJob pj = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (pj != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            if (pj.printDialog(aset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                pj.setPrintable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    pj.print(aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    statusMsgStream.println(amh.getMessage("appletprint.finish"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                } catch (PrinterException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                   statusMsgStream.println(amh.getMessage("appletprint.fail"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                statusMsgStream.println(amh.getMessage("appletprint.cancel"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            statusMsgStream.println(amh.getMessage("appletprint.fail"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   794
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public int print(Graphics graphics, PageFormat pf, int pageIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        if (pageIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            return Printable.NO_SUCH_PAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            Graphics2D g2d = (Graphics2D)graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            g2d.translate(pf.getImageableX(), pf.getImageableY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            panel.applet.printAll(graphics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            return Printable.PAGE_EXISTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    static AppletProps props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public static synchronized void networkProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (props == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            props = new AppletProps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        props.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        props.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * Start the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    void appletStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        panel.sendEvent(AppletPanel.APPLET_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Stop the applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    void appletStop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        panel.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Shutdown a viewer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Stop, Destroy, Dispose and Quit a viewer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    private void appletShutdown(AppletPanel p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        p.sendEvent(AppletPanel.APPLET_STOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        p.sendEvent(AppletPanel.APPLET_DESTROY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        p.sendEvent(AppletPanel.APPLET_DISPOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        p.sendEvent(AppletPanel.APPLET_QUIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Close this viewer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Stop, Destroy, Dispose and Quit an AppletView, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * reclaim resources and exit the program if this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * the last applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    void appletClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        // The caller thread is event dispatch thread, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        // spawn a new thread to avoid blocking the event queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        // when calling appletShutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        final AppletPanel p = panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28231
diff changeset
   857
        new ManagedLocalsThread(new Runnable()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        {
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   859
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            public void run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                appletShutdown(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                appletPanels.removeElement(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                if (countApplets() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                    appletSystemExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Exit the program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Exit from the program (if not stand alone) - do no clean-up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    private void appletSystemExit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        if (factory.isStandalone())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * Quit all viewers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Shutdown all viewers properly then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * exit from the program (if not stand alone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    protected void appletQuit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        // The caller thread is event dispatch thread, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        // spawn a new thread to avoid blocking the event queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // when calling appletShutdown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        //
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28231
diff changeset
   893
        new ManagedLocalsThread(new Runnable()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        {
23667
37f0fbe26e84 8028050: Typo correction needed s/Classlaoder/Classloader/
serb
parents: 23642
diff changeset
   895
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            public void run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   898
                for (Enumeration<AppletPanel> e = appletPanels.elements() ; e.hasMoreElements() ;) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
   899
                    AppletPanel p = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                    appletShutdown(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                appletSystemExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * Handle events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public void processUserAction(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        String label = ((MenuItem)evt.getSource()).getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        if (amh.getMessage("menuitem.restart").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            appletRestart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        if (amh.getMessage("menuitem.reload").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            appletReload();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        if (amh.getMessage("menuitem.clone").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            appletClone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        if (amh.getMessage("menuitem.stop").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            appletStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        if (amh.getMessage("menuitem.save").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            appletSave();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (amh.getMessage("menuitem.start").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            appletStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (amh.getMessage("menuitem.tag").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            appletTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        if (amh.getMessage("menuitem.info").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            appletInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        if (amh.getMessage("menuitem.encoding").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            appletCharacterEncoding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (amh.getMessage("menuitem.edit").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            appletEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (amh.getMessage("menuitem.print").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            appletPrint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if (amh.getMessage("menuitem.props").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            networkProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if (amh.getMessage("menuitem.close").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            appletClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (factory.isStandalone() && amh.getMessage("menuitem.quit").equals(label)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            appletQuit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        //statusMsgStream.println("evt = " + evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * How many applets are running?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    public static int countApplets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        return appletPanels.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * The current character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    static int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * Scan spaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    public static void skipSpace(Reader in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        while ((c >= 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
               ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * Scan identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    public static String scanIdentifier(Reader in) throws IOException {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1014
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            if (((c >= 'a') && (c <= 'z')) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                ((c >= 'A') && (c <= 'Z')) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                ((c >= '0') && (c <= '9')) || (c == '_')) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1019
                sb.append((char) c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            } else {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1022
                return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * Scan tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1030
    public static Hashtable<String, String> scanTag(Reader in) throws IOException {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1031
        Hashtable<String, String> atts = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        skipSpace(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        while (c >= 0 && c != '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            String att = scanIdentifier(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            String val = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            skipSpace(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (c == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                int quote = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                skipSpace(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                if ((c == '\'') || (c == '\"')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                    quote = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1045
                StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                while ((c > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                       (((quote < 0) && (c != ' ') && (c != '\t') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                         (c != '\n') && (c != '\r') && (c != '>'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                        || ((quote >= 0) && (c != quote)))) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1050
                    sb.append((char) c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                if (c == quote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                skipSpace(in);
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23667
diff changeset
  1057
                val = sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            //statusMsgStream.println("PUT " + att + " = '" + val + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            if (! val.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                atts.put(att.toLowerCase(java.util.Locale.ENGLISH), val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                if ((c == '>') || (c < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                    ((c >= 'a') && (c <= 'z')) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    ((c >= 'A') && (c <= 'Z')) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    ((c >= '0') && (c <= '9')) || (c == '_'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            //skipSpace(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        return atts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /* values used for placement of AppletViewer's frames */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    private static int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    private static int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    private static final int XDELTA = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    private static final int YDELTA = XDELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    static String encoding = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 31061
diff changeset
  1084
    private static Reader makeReader(InputStream is) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (encoding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                return new BufferedReader(new InputStreamReader(is, encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            } catch (IOException x) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        InputStreamReader r = new InputStreamReader(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        encoding = r.getEncoding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        return new BufferedReader(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    /**
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 29922
diff changeset
  1096
     * Scan an html file for {@code <applet>} tags
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    public static void parse(URL url, String enc) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        encoding = enc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        parse(url, System.out, new StdAppletViewerFactory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    public static void parse(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        parse(url, System.out, new StdAppletViewerFactory());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    public static void parse(URL url, PrintStream statusMsgStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                             AppletViewerFactory factory) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        // <OBJECT> <EMBED> tag flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        boolean isAppletTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        boolean isObjectTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        boolean isEmbedTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        // warning messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        String requiresNameWarning = amh.getMessage("parse.warning.requiresname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        String paramOutsideWarning = amh.getMessage("parse.warning.paramoutside");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        String appletRequiresCodeWarning = amh.getMessage("parse.warning.applet.requirescode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        String appletRequiresHeightWarning = amh.getMessage("parse.warning.applet.requiresheight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        String appletRequiresWidthWarning = amh.getMessage("parse.warning.applet.requireswidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        String objectRequiresCodeWarning = amh.getMessage("parse.warning.object.requirescode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        String objectRequiresHeightWarning = amh.getMessage("parse.warning.object.requiresheight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        String objectRequiresWidthWarning = amh.getMessage("parse.warning.object.requireswidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        String embedRequiresCodeWarning = amh.getMessage("parse.warning.embed.requirescode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        String embedRequiresHeightWarning = amh.getMessage("parse.warning.embed.requiresheight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        String embedRequiresWidthWarning = amh.getMessage("parse.warning.embed.requireswidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        String appNotLongerSupportedWarning = amh.getMessage("parse.warning.appnotLongersupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        java.net.URLConnection conn = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        Reader in = makeReader(conn.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        /* The original URL may have been redirected - this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
         * sets it to whatever URL/codebase we ended up getting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        url = conn.getURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        int ydisp = 1;
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1136
        Hashtable<String, String> atts = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        while(true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            if (c == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            if (c == '<') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                if (c == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                    String nm = scanIdentifier(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    if (nm.equalsIgnoreCase("applet") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                        nm.equalsIgnoreCase("object") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                        nm.equalsIgnoreCase("embed")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                        // We can't test for a code tag until </OBJECT>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                        // because it is a parameter, not an attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                        if(isObjectTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                            if (atts.get("code") == null && atts.get("object") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                statusMsgStream.println(objectRequiresCodeWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                                atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                        if (atts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                            // XXX 5/18 In general this code just simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                            // shouldn't be part of parsing.  It's presence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                            // causes things to be a little too much of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                            // hack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                            factory.createAppletViewer(x, y, url, atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                            x += XDELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                            y += YDELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                            // make sure we don't go too far!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                            if ((x > d.width - 300) || (y > d.height - 300)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                                x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                                y = 2 * ydisp * YDELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                                ydisp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                        atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                        isAppletTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                        isObjectTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                        isEmbedTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    String nm = scanIdentifier(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    if (nm.equalsIgnoreCase("param")) {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1186
                        Hashtable<String, String> t = scanTag(in);
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1187
                        String att = t.get("name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                        if (att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                            statusMsgStream.println(requiresNameWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                        } else {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1191
                            String val = t.get("value");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                            if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                                statusMsgStream.println(requiresNameWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                            } else if (atts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                                atts.put(att.toLowerCase(), val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                                statusMsgStream.println(paramOutsideWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    else if (nm.equalsIgnoreCase("applet")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                        isAppletTag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                        atts = scanTag(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                        if (atts.get("code") == null && atts.get("object") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                            statusMsgStream.println(appletRequiresCodeWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                        } else if (atts.get("width") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                            statusMsgStream.println(appletRequiresWidthWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                        } else if (atts.get("height") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                            statusMsgStream.println(appletRequiresHeightWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    else if (nm.equalsIgnoreCase("object")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                        isObjectTag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                        atts = scanTag(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                        // The <OBJECT> attribute codebase isn't what
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                        // we want. If its defined, remove it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                        if(atts.get("codebase") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                            atts.remove("codebase");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                        if (atts.get("width") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                            statusMsgStream.println(objectRequiresWidthWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                        } else if (atts.get("height") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                            statusMsgStream.println(objectRequiresHeightWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                    else if (nm.equalsIgnoreCase("embed")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                        isEmbedTag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                        atts = scanTag(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                        if (atts.get("code") == null && atts.get("object") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                            statusMsgStream.println(embedRequiresCodeWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                        } else if (atts.get("width") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                            statusMsgStream.println(embedRequiresWidthWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                        } else if (atts.get("height") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                            statusMsgStream.println(embedRequiresHeightWarning);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                            atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    else if (nm.equalsIgnoreCase("app")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                        statusMsgStream.println(appNotLongerSupportedWarning);
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1249
                        Hashtable<String, String> atts2 = scanTag(in);
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1250
                        nm = atts2.get("class");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                        if (nm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                            atts2.remove("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                            atts2.put("code", nm + ".class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                        }
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24969
diff changeset
  1255
                        nm = atts2.get("src");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                        if (nm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                            atts2.remove("src");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                            atts2.put("codebase", nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                        if (atts2.get("width") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                            atts2.put("width", "100");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                        if (atts2.get("height") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                            atts2.put("height", "100");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                        printTag(statusMsgStream, atts2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                        statusMsgStream.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * Old main entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    public static void main(String argv[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        // re-route everything to the new main entry point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        Main.main(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    private static AppletMessageHandler amh = new AppletMessageHandler("appletviewer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    private static void checkConnect(URL url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                java.security.Permission perm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                    url.openConnection().getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                if (perm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    security.checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    security.checkConnect(url.getHost(), url.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            } catch (java.io.IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    security.checkConnect(url.getHost(), url.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
}