Exemplo n.º 1
0
 private WPPluginManager(UUID uuid, String logPrefix, ClassLoader classLoader) {
   allPlugins = org.pepsoft.util.PluginManager.findPlugins(Plugin.class, FILENAME, classLoader);
   Set<String> namesEncountered = new HashSet<>();
   for (Iterator<Plugin> i = allPlugins.iterator(); i.hasNext(); ) {
     Plugin plugin = i.next();
     if ((plugin.getUUIDs() != null) && (uuid != null) && (!plugin.getUUIDs().contains(uuid))) {
       logger.error(
           logPrefix
               + plugin.getName()
               + " plugin is not authorised for this installation; not loading it");
       i.remove();
       continue;
     }
     String name = plugin.getName();
     if (namesEncountered.contains(name)) {
       throw new RuntimeException("Multiple plugins with the same name (" + name + ") detected!");
     } else {
       namesEncountered.add(name);
     }
     logger.info(logPrefix + "Loaded plugin: " + name + " (version " + plugin.getVersion() + ")");
   }
 }
Exemplo n.º 2
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);
  }