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