private void buildInnerMenu(MenuActionPlugin plugin, JComponent menuContainer) { try { ProtegeAction action = plugin.newInstance(); final JMenuItem menuItem = createMenuItem(plugin, action); KeyStroke ks = plugin.getAccelerator(); ks = fixAcceleratorForMacOSX(ks); menuItem.setAccelerator(ks); menuContainer.add(menuItem); invokeInnerMenuMethods(action, menuItem, menuContainer); actions.add(action); } catch (Exception e) { logger.warn("Error building menu: {}", e.getMessage(), e); } catch (NoClassDefFoundError noClass) { logger.error("Error loading menu plugin {} ({})", plugin.getId(), plugin.getName()); } }
/** * Compares two <code>MenuActionPlugin</code>s based on their * groups. Groups are compared alphabetically. If their groups are * equal then the group indexes are compared, which are also compared * alphabetically. */ public int compare(MenuActionPlugin o1, MenuActionPlugin o2) { int result = o1.getGroup().compareTo(o2.getGroup()); if (result == 0) { result = o1.getGroupIndex().compareTo(o2.getGroupIndex()); } return result; } }
private boolean hasParentMenu(MenuActionPlugin plugin) { return plugin.getParentId().length() > 0; }
private void buildCompositeMenu(MenuActionPlugin plugin, JComponent menuContainer, List<MenuActionPlugin> children) { // Add a JMenu JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); MenuActionPlugin lastPlugin = null; for (MenuActionPlugin childPlugin : children) { if (lastPlugin != null) { if (!lastPlugin.getGroup().equals(childPlugin.getGroup())) { menu.addSeparator(); } } addMenu(childPlugin, menu); //recursive call lastPlugin = childPlugin; } }
private JMenuItem createMenuItem(MenuActionPlugin plugin, ProtegeAction action) { if (plugin.isCheckBox()) { return new JCheckBoxMenuItem(action); } else if (plugin.isRadioButton()) { JRadioButtonMenuItem radioButtonMenuItem = new JRadioButtonMenuItem(action); ButtonGroup group = getButtonGroup(plugin); if (group != null) { group.add(radioButtonMenuItem); } return radioButtonMenuItem; } return new JMenuItem(action); }
private void buildDynamicMenu(MenuActionPlugin plugin, JComponent menuContainer) { // Construct dynamic menu. This is basically a menu, whose children are determined at runtime. final JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); try { // The menu must be a dynamic action menu. final ProtegeDynamicAction action = (ProtegeDynamicAction) plugin.newInstance(); invokeDynamicMenuMethods(action, menu); menu.addMenuListener(getDynamicMenuListener(menu, action)); actions.add(action); } catch (Throwable e) { logger.error("An error occurred whilst building a dynamic menu. Plugin name: {}", plugin.getName(), e); } }
private void buildInnerMenu(MenuActionPlugin plugin, JComponent menuContainer) { try { ProtegeAction action = plugin.newInstance(); final JMenuItem menuItem = createMenuItem(plugin, action); KeyStroke ks = plugin.getAccelerator(); ks = fixAcceleratorForMacOSX(ks); menuItem.setAccelerator(ks); menuContainer.add(menuItem); invokeInnerMenuMethods(action, menuItem, menuContainer); actions.add(action); } catch (Exception e) { logger.error(e); } }
public JPopupMenu buildPopupMenu(final PopupMenuId menuId) { JPopupMenu popupMenu = new JPopupMenu(); parentChildMap.clear(); Map<String, MenuActionPlugin> idPluginMap = getPlugins(); for (MenuActionPlugin plugin : idPluginMap.values()) { MenuActionPlugin parent = idPluginMap.get(plugin.getParentId()); getChildren(parent).add(plugin); } // Should now have a hierarchy of plugins Collection<MenuActionPlugin> popupPlugins = getSortedList(getChildren(null)); String lastGroup = ""; for(MenuActionPlugin plugin : popupPlugins) { if(isPopupMenuItem(plugin)) { PopupMenuId popupMenuId = new PopupMenuId(plugin.getParentId()); if (popupMenuId.equals(menuId)) { if (!lastGroup.isEmpty() && !lastGroup.equals(plugin.getGroup())) { popupMenu.add(new JSeparator()); } lastGroup = plugin.getGroup(); addMenu(plugin, popupMenu); } } } return popupMenu; }
private Map<String, MenuActionPlugin> getPlugins() { // Create a map to hold the results in. This maps menu plugin ids to their // menus so that we can form an ordering of parent child menu plugins Map<String, MenuActionPlugin> result = new HashMap<>(); MenuActionPluginLoader pluginLoader = new MenuActionPluginLoader(editorKit); for (MenuActionPlugin plugin : pluginLoader.getPlugins()) { result.put(plugin.getId(), plugin); logger.debug("Added MenuActionPlugin: {}", plugin); } return result; }
private ButtonGroup getButtonGroup(MenuActionPlugin plugin) { String group = plugin.getGroup(); if (group == null) { return null; } ButtonGroup buttonGroup = group2ButtonGroupMap.get(group); if (buttonGroup == null) { buttonGroup = new ButtonGroup(); group2ButtonGroupMap.put(group, buttonGroup); } return buttonGroup; }
private void buildTopLevelMenu(MenuActionPlugin plugin, JComponent menuContainer) { // This is a top level menu. It is probably a place holder, so add it. JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); }
private void addMenu(MenuActionPlugin plugin, JComponent menuContainer) { List<MenuActionPlugin> children = getSortedList(getChildren(plugin)); if (!children.isEmpty()) { //this is a recursive function, it is important to have a stop condition buildCompositeMenu(plugin, menuContainer, children); } else { if (plugin.isDynamic()) { buildDynamicMenu(plugin, menuContainer); } else { if (hasParentMenu(plugin)) { buildInnerMenu(plugin, menuContainer); } else { buildTopLevelMenu(plugin, menuContainer); } } } }
private JMenuItem createMenuItem(MenuActionPlugin plugin, ProtegeAction action) { if (plugin.isCheckBox()) { return new JCheckBoxMenuItem(action); } else if (plugin.isRadioButton()) { JRadioButtonMenuItem radioButtonMenuItem = new JRadioButtonMenuItem(action); ButtonGroup group = getButtonGroup(plugin); if (group != null) { group.add(radioButtonMenuItem); } return radioButtonMenuItem; } return new JMenuItem(action); }
private void buildDynamicMenu(MenuActionPlugin plugin, JComponent menuContainer) { // Construct dynamic menu. This is basically a menu, whose children are determined at runtime. final JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); try { // The menu must be a dynamic action menu. final ProtegeDynamicAction action = (ProtegeDynamicAction) plugin.newInstance(); invokeDynamicMenuMethods(action, menu); menu.addMenuListener(getDynamicMenuListener(menu, action)); actions.add(action); } catch (Exception e) { logger.error(e); } }
private void buildCompositeMenu(MenuActionPlugin plugin, JComponent menuContainer, List<MenuActionPlugin> children) { // Add a JMenu JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); MenuActionPlugin lastPlugin = null; for (MenuActionPlugin childPlugin : children) { if (lastPlugin != null) { if (!lastPlugin.getGroup().equals(childPlugin.getGroup())) { menu.addSeparator(); } } addMenu(childPlugin, menu); //recursive call lastPlugin = childPlugin; } }
private Map<String, MenuActionPlugin> getPlugins() { // Create a map to hold the results in. This maps menu plugin ids to their // menus so that we can form an ordering of parent child menu plugins Map<String, MenuActionPlugin> result = new HashMap<String, MenuActionPlugin>(); MenuActionPluginLoader pluginLoader = new MenuActionPluginLoader(editorKit); for (MenuActionPlugin plugin : pluginLoader.getPlugins()) { result.put(plugin.getId(), plugin); } return result; }
private ButtonGroup getButtonGroup(MenuActionPlugin plugin) { String group = plugin.getGroup(); if (group == null) { return null; } ButtonGroup buttonGroup = group2ButtonGroupMap.get(group); if (buttonGroup == null) { buttonGroup = new ButtonGroup(); group2ButtonGroupMap.put(group, buttonGroup); } return buttonGroup; }
private void buildTopLevelMenu(MenuActionPlugin plugin, JComponent menuContainer) { // This is a top level menu. It is probably a place holder, so add it. JMenu menu = new JMenu(plugin.getName()); menuContainer.add(menu); }
private void addMenu(MenuActionPlugin plugin, JComponent menuContainer) { logCreateMenu(plugin, menuContainer); List<MenuActionPlugin> children = getSortedList(getChildren(plugin)); if (!children.isEmpty()) { //this is a recursive function, it is important to have a stop condition buildCompositeMenu(plugin, menuContainer, children); } else { if (plugin.isDynamic()) { buildDynamicMenu(plugin, menuContainer); } else { if (hasParentMenu(plugin)) { buildInnerMenu(plugin, menuContainer); } else { buildTopLevelMenu(plugin, menuContainer); } } } }
private void buildInnerMenu(MenuActionPlugin plugin, JComponent menuContainer) { try { ProtegeAction action = plugin.newInstance(); final JMenuItem menuItem = createMenuItem(plugin, action); KeyStroke ks = plugin.getAccelerator(); ks = fixAcceleratorForMacOSX(ks); menuItem.setAccelerator(ks); menuContainer.add(menuItem); invokeInnerMenuMethods(action, menuItem, menuContainer); actions.add(action); } catch (Exception e) { ProtegeApplication.getErrorLog().logError(e); } catch (NoClassDefFoundError noClass) { logger.error("Error loading menu plugin " + plugin.getId() + "(" + plugin.getName() + ")"); ProtegeApplication.getErrorLog().logError(noClass); } }