コード例 #1
0
  private void addMenuToTray() {
    HashMap categories = new HashMap();

    // create menu list
    Iterator plugins = PluginManager.getInstance().getAvailablePlugins();
    plugins = PluginComparator.sortPlugins(plugins);

    while (plugins.hasNext()) {
      Plugin p = (Plugin) plugins.next();

      JMenu category = (JMenu) categories.get(p.getCategory());
      if (category == null) {
        category = new JMenu(p.getCategory());
        categories.put(p.getCategory(), category);

        // copy menu to real one
        if (!p.getCategory().equals("Invisible")) this.trayIcon.add(category);
      }

      ImageIcon icon = new ImageIcon();
      try {
        icon = new ImageIcon(new URL(p.getDirectory() + p.getIcon()));
        icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
      } catch (Exception e) {
        // error at icon loading
      }

      JMenuItem menu = new JMenuItem(p.getTitle(), icon);
      menu.setName(p.getName());
      menu.setToolTipText(p.getToolTip());
      menu.addActionListener(this);
      category.add(menu);
    }

    this.trayIcon.addSeparator();

    // windows
    this.trayIcon.add(new WindowMenu(this));

    // open main interface
    JMenuItem menu = new JMenuItem(tr("open"));
    menu.setName("org.lucane.applications.maininterface");
    menu.addActionListener(this);
    this.trayIcon.add(menu);

    // exit
    menu = new JMenuItem(tr("exit"));
    menu.setName("exit");
    menu.addActionListener(this);
    this.trayIcon.add(menu);
  }
コード例 #2
0
  private void runPlugin(String pluginName) {
    ConnectInfo[] friends = null;
    Plugin plugin = PluginManager.getInstance().getPlugin(pluginName);

    // get users
    if (plugin.isStandalone()) friends = new ConnectInfo[0];
    else {
      ListBox userList =
          new ListBox(
              null, plugin.getTitle(), tr("msg.selectUsers"), Client.getInstance().getUserList());
      Object[] users = userList.selectItems();
      if (users != null) {
        friends = new ConnectInfo[users.length];
        for (int i = 0; i < friends.length; i++)
          friends[i] = Communicator.getInstance().getConnectInfo((String) users[i]);
      }
    }

    // run the plugin if the user didn't click on cancel
    if (friends != null) PluginManager.getInstance().run(pluginName, friends);
  }