<commit_before>package org.micromanager.pluginmanagement;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JMenu;
import javax.swing.JMenuBar;

import mmcorej.TaggedImage;

import org.micromanager.api.DataProcessor;
import org.micromanager.api.MMPlugin;
import org.micromanager.api.MMProcessorPlugin;
import org.micromanager.MMStudio;
import org.micromanager.utils.GUIUtils;
import org.micromanager.utils.ReportingUtils;

/*
 * This class is responsible for general plugin management.
 */
public class PluginManager {
   private JMenu pluginMenu_;
   private final Map<String, JMenu> pluginSubMenus_ = new HashMap<String, JMenu>();
   private final PluginLoader pluginLoader_;

   private MMStudio studio_;
   private JMenuBar menuBar_;

   public PluginManager(MMStudio studio, JMenuBar menuBar) {
      studio_ = studio;
      menuBar_ = menuBar;
      pluginLoader_ = new PluginLoader(this);
   }

   public Thread initializePlugins() {
      pluginMenu_ = GUIUtils.createMenuInMenuBar(menuBar_, "Plugins");

      Thread loadThread = new Thread(new ThreadGroup("Plugin loading"),
            new Runnable() {
               @Override
               public void run() {
                  pluginLoader_.loadPlugins();
               }
      });
      // Needed for loading clojure-based jars:
      loadThread.setContextClassLoader(getClass().getClassLoader());
      loadThread.start();
      return loadThread;
   }

   /**
    * Adds plugin items to the plugins menu
    * Adds submenus (currently only 1 level deep)
    * @param plugin - plugin to be added to the menu
    */
   public void addPluginToMenu(final PluginItem plugin) {
      List<String> path = plugin.getMenuPath();
      final PluginManager thisInstance = this;
      if (path.size() == 1) { // Add plugin to top-level menu
         GUIUtils.addMenuItem(pluginMenu_, plugin.getMenuItem(), plugin.getTooltip(),
                 new Runnable() {
            public void run() {
               thisInstance.displayPlugin(plugin);
            }
         });
      }
      else if (path.size() == 2) { // Add plugin to submenu
         String groupName = path.get(0);
         JMenu submenu = pluginSubMenus_.get(groupName);
         if (submenu == null) {
            submenu = new JMenu(groupName);
            pluginSubMenus_.put(groupName, submenu);
            submenu.validate();
            pluginMenu_.add(submenu);
            if (groupName.equals("Image Processing")) {
               // Sorry for this hard-coded special behavior
               addImageProcessorConfigureMenuItem(submenu);
               submenu.addSeparator();
            }
         }<commit_msg>Fix on-the-fly processor menu item<commit_after>package org.micromanager.pluginmanagement;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JMenu;
import javax.swing.JMenuBar;

import mmcorej.TaggedImage;

import org.micromanager.api.DataProcessor;
import org.micromanager.api.MMPlugin;
import org.micromanager.api.MMProcessorPlugin;
import org.micromanager.MMStudio;
import org.micromanager.utils.GUIUtils;
import org.micromanager.utils.ReportingUtils;

/*
 * This class is responsible for general plugin management.
 */
public class PluginManager {
   private JMenu pluginMenu_;
   private final Map<String, JMenu> pluginSubMenus_ = new HashMap<String, JMenu>();
   private final PluginLoader pluginLoader_;

   private MMStudio studio_;
   private JMenuBar menuBar_;

   public PluginManager(MMStudio studio, JMenuBar menuBar) {
      studio_ = studio;
      menuBar_ = menuBar;
      pluginLoader_ = new PluginLoader(this);
   }

   public Thread initializePlugins() {
      pluginMenu_ = GUIUtils.createMenuInMenuBar(menuBar_, "Plugins");

      Thread loadThread = new Thread(new ThreadGroup("Plugin loading"),
            new Runnable() {
               @Override
               public void run() {
                  pluginLoader_.loadPlugins();
               }
      });
      // Needed for loading clojure-based jars:
      loadThread.setContextClassLoader(getClass().getClassLoader());
      loadThread.start();
      return loadThread;
   }

   /**
    * Adds plugin items to the plugins menu
    * Adds submenus (currently only 1 level deep)
    * @param plugin - plugin to be added to the menu
    */
   public void addPluginToMenu(final PluginItem plugin) {
      List<String> path = plugin.getMenuPath();
      final PluginManager thisInstance = this;
      if (path.size() == 1) { // Add plugin to top-level menu
         GUIUtils.addMenuItem(pluginMenu_, plugin.getMenuItem(), plugin.getTooltip(),
                 new Runnable() {
            public void run() {
               thisInstance.displayPlugin(plugin);
            }
         });
      }
      else if (path.size() == 2) { // Add plugin to submenu
         String groupName = path.get(0);
         JMenu submenu = pluginSubMenus_.get(groupName);
         if (submenu == null) {
            submenu = new JMenu(groupName);
            pluginSubMenus_.put(groupName, submenu);
            submenu.validate();
            pluginMenu_.add(submenu);
            if (groupName.equals("On-The-Fly Processors")) {
               // Sorry for this hard-coded special behavior
               addImageProcessorConfigureMenuItem(submenu);
               submenu.addSeparator();
            }
         }
{'fraction_non_alphanumeric': 0.09518518518518519, 'fraction_numerical': 0.0014814814814814814, 'mean_word_length': 2.5744540039708803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1693622', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1458, 'n_words': 374}