Beispiel #1
0
 /** Exit the program. Exit from the program (if not stand alone) - do no clean-up */
 private void appletSystemExit() {
   if (factory.isStandalone()) System.exit(0);
 }
Beispiel #2
0
  /** Handle events. */
  public void processUserAction(ActionEvent evt) {

    String label = ((MenuItem) evt.getSource()).getLabel();

    if (amh.getMessage("menuitem.restart").equals(label)) {
      appletRestart();
      return;
    }

    if (amh.getMessage("menuitem.reload").equals(label)) {
      appletReload();
      return;
    }

    if (amh.getMessage("menuitem.clone").equals(label)) {
      appletClone();
      return;
    }

    if (amh.getMessage("menuitem.stop").equals(label)) {
      appletStop();
      return;
    }

    if (amh.getMessage("menuitem.save").equals(label)) {
      appletSave();
      return;
    }

    if (amh.getMessage("menuitem.start").equals(label)) {
      appletStart();
      return;
    }

    if (amh.getMessage("menuitem.tag").equals(label)) {
      appletTag();
      return;
    }

    if (amh.getMessage("menuitem.info").equals(label)) {
      appletInfo();
      return;
    }

    if (amh.getMessage("menuitem.encoding").equals(label)) {
      appletCharacterEncoding();
      return;
    }

    if (amh.getMessage("menuitem.edit").equals(label)) {
      appletEdit();
      return;
    }

    if (amh.getMessage("menuitem.print").equals(label)) {
      appletPrint();
      return;
    }

    if (amh.getMessage("menuitem.props").equals(label)) {
      networkProperties();
      return;
    }

    if (amh.getMessage("menuitem.close").equals(label)) {
      appletClose();
      return;
    }

    if (factory.isStandalone() && amh.getMessage("menuitem.quit").equals(label)) {
      appletQuit();
      return;
    }
    // statusMsgStream.println("evt = " + evt);
  }
Beispiel #3
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();
  }