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