Пример #1
0
 // XXX 99/9/10 probably should be "private"
 public MenuItem addMenuItem(Menu m, String s) {
   MenuItem mItem = new MenuItem(amh.getMessage(s));
   mItem.addActionListener(new UserActionListener());
   return m.add(mItem);
 }
Пример #2
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();
  }