Adds a plugin based command to the end of a specified menu. @param plugin the plugin (e.g. "Inverter_", "Inverter_("arg")") @param menuCode PLUGINS_MENU, IMPORT_MENU, SAVE_AS_MENU or HOT_KEYS @param command the menu item label (set to "" to uninstall) @param shortcut the keyboard shortcut (e.g.
(String plugin, char menuCode, String command, String shortcut, ImageJ ij)
| 1553 | * @return returns an error code(NORMAL_RETURN,COMMAND_IN_USE_ERROR, etc.) |
| 1554 | */ |
| 1555 | public static int installPlugin(String plugin, char menuCode, String command, String shortcut, ImageJ ij) { |
| 1556 | if (command.equals("")) //uninstall |
| 1557 | return NORMAL_RETURN; |
| 1558 | if (commandInUse(command)) |
| 1559 | return COMMAND_IN_USE; |
| 1560 | if (!validShortcut(shortcut)) |
| 1561 | return INVALID_SHORTCUT; |
| 1562 | if (shortcutInUse(shortcut)) |
| 1563 | return SHORTCUT_IN_USE; |
| 1564 | |
| 1565 | Menu menu; |
| 1566 | switch (menuCode) { |
| 1567 | case PLUGINS_MENU: menu = pluginsMenu; break; |
| 1568 | case IMPORT_MENU: menu = getMenu("File>Import"); break; |
| 1569 | case SAVE_AS_MENU: menu = getMenu("File>Save As"); break; |
| 1570 | case SHORTCUTS_MENU: menu = shortcutsMenu; break; |
| 1571 | case ABOUT_MENU: menu = getMenu("Help>About Plugins"); break; |
| 1572 | case FILTERS_MENU: menu = getMenu("Process>Filters"); break; |
| 1573 | case TOOLS_MENU: menu = getMenu("Analyze>Tools"); break; |
| 1574 | case UTILITIES_MENU: menu = utilitiesMenu; break; |
| 1575 | default: return 0; |
| 1576 | } |
| 1577 | int code = convertShortcutToCode(shortcut); |
| 1578 | MenuItem item; |
| 1579 | boolean functionKey = code>=KeyEvent.VK_F1 && code<=KeyEvent.VK_F12; |
| 1580 | if (code==0) |
| 1581 | item = new MenuItem(command); |
| 1582 | else if (functionKey) { |
| 1583 | command += " [F"+(code-KeyEvent.VK_F1+1)+"]"; |
| 1584 | shortcuts.put(Integer.valueOf(code),command); |
| 1585 | item = new MenuItem(command); |
| 1586 | } else { |
| 1587 | shortcuts.put(Integer.valueOf(code),command); |
| 1588 | int keyCode = code; |
| 1589 | boolean shift = false; |
| 1590 | if (keyCode>=265 && keyCode<=290) { |
| 1591 | keyCode -= 200; |
| 1592 | shift = true; |
| 1593 | } |
| 1594 | item = new MenuItem(command, new MenuShortcut(keyCode, shift)); |
| 1595 | } |
| 1596 | menu.add(item); |
| 1597 | item.addActionListener(ij); |
| 1598 | pluginsTable.put(command, plugin); |
| 1599 | shortcut = code>0 && !functionKey?"["+shortcut+"]":""; |
| 1600 | pluginsPrefs.addElement(menuCode+",\""+command+shortcut+"\","+plugin); |
| 1601 | return NORMAL_RETURN; |
| 1602 | } |
| 1603 | |
| 1604 | /** Deletes a command installed by Plugins/Shortcuts/Add Shortcut. */ |
| 1605 | public static int uninstallPlugin(String command) { |
no test coverage detected