Exemple #1
0
  /** Reload the applet. */
  void appletReload() {
    panel.sendEvent(AppletPanel.APPLET_STOP);
    panel.sendEvent(AppletPanel.APPLET_DESTROY);
    panel.sendEvent(AppletPanel.APPLET_DISPOSE);

    /**
     * Fixed #4501142: Classlaoder sharing policy doesn't take "archive" into account. This will be
     * overridden by Java Plug-in. [stanleyh]
     */
    AppletPanel.flushClassLoader(panel.getClassLoaderCacheKey());

    /*
     * Make sure we don't have two threads running through the event queue
     * at the same time.
     */
    try {
      panel.joinAppletThread();
      panel.release();
    } catch (InterruptedException e) {
      return; // abort the reload
    }

    panel.createAppletThread();
    panel.sendEvent(AppletPanel.APPLET_LOAD);
    panel.sendEvent(AppletPanel.APPLET_INIT);
    panel.sendEvent(AppletPanel.APPLET_START);
  }
Exemple #2
0
  /** Return an enumeration of all the accessible applets on this page. */
  public Enumeration getApplets() {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    Vector v = new Vector();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");

    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      if (p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");
        if (panelSp.implies(sp)) {
          v.addElement(p.applet);
        }
      }
    }
    return v.elements();
  }
Exemple #3
0
  /** Get an applet by name. */
  public Applet getApplet(String name) {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    name = name.toLowerCase();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");
    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      String param = p.getParameter("name");
      if (param != null) {
        param = param.toLowerCase();
      }
      if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");

        if (panelSp.implies(sp)) {
          return p.applet;
        }
      }
    }
    return null;
  }
Exemple #4
0
  /**
   * Send the initial set of events to the appletviewer event queue. On start-up the current
   * behaviour is to load the applet and call Applet.init() and Applet.start().
   */
  private void initEventQueue() {
    // appletviewer.send.event is an undocumented and unsupported system
    // property which is used exclusively for testing purposes.
    String eventList = System.getProperty("appletviewer.send.event");

    if (eventList == null) {
      // Add the standard events onto the event queue.
      panel.sendEvent(AppletPanel.APPLET_LOAD);
      panel.sendEvent(AppletPanel.APPLET_INIT);
      panel.sendEvent(AppletPanel.APPLET_START);
    } else {
      // We're testing AppletViewer.  Force the specified set of events
      // onto the event queue, wait for the events to be processed, and
      // exit.

      // The list of events that will be executed is provided as a
      // ","-separated list.  No error-checking will be done on the list.
      String[] events = splitSeparator(",", eventList);

      for (int i = 0; i < events.length; i++) {
        System.out.println("Adding event to queue: " + events[i]);
        if (events[i].equals("dispose")) panel.sendEvent(AppletPanel.APPLET_DISPOSE);
        else if (events[i].equals("load")) panel.sendEvent(AppletPanel.APPLET_LOAD);
        else if (events[i].equals("init")) panel.sendEvent(AppletPanel.APPLET_INIT);
        else if (events[i].equals("start")) panel.sendEvent(AppletPanel.APPLET_START);
        else if (events[i].equals("stop")) panel.sendEvent(AppletPanel.APPLET_STOP);
        else if (events[i].equals("destroy")) panel.sendEvent(AppletPanel.APPLET_DESTROY);
        else if (events[i].equals("quit")) panel.sendEvent(AppletPanel.APPLET_QUIT);
        else if (events[i].equals("error")) panel.sendEvent(AppletPanel.APPLET_ERROR);
        else
          // non-fatal error if we get an unrecognized event
          System.out.println("Unrecognized event name: " + events[i]);
      }

      while (!panel.emptyEventQueue()) ;
      appletSystemExit();
    }
  }
Exemple #5
0
 /** Stop the applet. */
 void appletStop() {
   panel.sendEvent(AppletPanel.APPLET_STOP);
 }
Exemple #6
0
 /** Start the applet. */
 void appletStart() {
   panel.sendEvent(AppletPanel.APPLET_START);
 }
Exemple #7
0
 /** Restart the applet. */
 void appletRestart() {
   panel.sendEvent(AppletPanel.APPLET_STOP);
   panel.sendEvent(AppletPanel.APPLET_DESTROY);
   panel.sendEvent(AppletPanel.APPLET_INIT);
   panel.sendEvent(AppletPanel.APPLET_START);
 }
Exemple #8
0
 /** Make sure the atrributes are uptodate. */
 public void updateAtts() {
   Dimension d = panel.size();
   Insets in = panel.insets();
   panel.atts.put("width", Integer.toString(d.width - (in.left + in.right)));
   panel.atts.put("height", Integer.toString(d.height - (in.top + in.bottom)));
 }
Exemple #9
0
  /** Create the applet viewer */
  public AppletViewer(
      int x,
      int y,
      URL doc,
      Hashtable atts,
      PrintStream statusMsgStream,
      AppletViewerFactory factory) {
    this.factory = factory;
    this.statusMsgStream = statusMsgStream;
    setTitle(amh.getMessage("tool.title", atts.get("code")));

    MenuBar mb = factory.getBaseMenuBar();

    Menu m = new Menu(amh.getMessage("menu.applet"));

    addMenuItem(m, "menuitem.restart");
    addMenuItem(m, "menuitem.reload");
    addMenuItem(m, "menuitem.stop");
    addMenuItem(m, "menuitem.save");
    addMenuItem(m, "menuitem.start");
    addMenuItem(m, "menuitem.clone");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.tag");
    addMenuItem(m, "menuitem.info");
    addMenuItem(m, "menuitem.edit").disable();
    addMenuItem(m, "menuitem.encoding");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.print");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.props");
    m.add(new MenuItem("-"));
    addMenuItem(m, "menuitem.close");
    if (factory.isStandalone()) {
      addMenuItem(m, "menuitem.quit");
    }

    mb.add(m);

    setMenuBar(mb);

    add("Center", panel = new AppletViewerPanel(doc, atts));
    add("South", label = new Label(amh.getMessage("label.hello")));
    panel.init();
    appletPanels.addElement(panel);

    pack();
    move(x, y);
    setVisible(true);

    WindowListener windowEventListener =
        new WindowAdapter() {

          public void windowClosing(WindowEvent evt) {
            appletClose();
          }

          public void windowIconified(WindowEvent evt) {
            appletStop();
          }

          public void windowDeiconified(WindowEvent evt) {
            appletStart();
          }
        };

    class AppletEventListener implements AppletListener {
      final Frame frame;

      public AppletEventListener(Frame frame) {
        this.frame = frame;
      }

      public void appletStateChanged(AppletEvent evt) {
        AppletPanel src = (AppletPanel) evt.getSource();

        switch (evt.getID()) {
          case AppletPanel.APPLET_RESIZE:
            {
              if (src != null) {
                resize(preferredSize());
                validate();
              }
              break;
            }
          case AppletPanel.APPLET_LOADING_COMPLETED:
            {
              Applet a = src.getApplet(); // j86.sun.applet.AppletPanel

              // Fixed #4754451: Applet can have methods running on main
              // thread event queue.
              //
              // The cause of this bug is that the frame of the applet
              // is created in main thread group. Thus, when certain
              // AWT/Swing events are generated, the events will be
              // dispatched through the wrong event dispatch thread.
              //
              // To fix this, we rearrange the AppContext with the frame,
              // so the proper event queue will be looked up.
              //
              // Swing also maintains a Frame list for the AppContext,
              // so we will have to rearrange it as well.
              //
              if (a != null)
                AppletPanel.changeFrameAppContext(frame, SunToolkit.targetToAppContext(a));
              else AppletPanel.changeFrameAppContext(frame, AppContext.getAppContext());

              break;
            }
        }
      }
    };

    addWindowListener(windowEventListener);
    panel.addAppletListener(new AppletEventListener(this));

    // Start the applet
    showStatus(amh.getMessage("status.start"));
    initEventQueue();
  }