9 import java.lang.reflect.*;
14 private static String[] menus = {
"Shortcuts",
"Plugins",
"Import",
"Save As",
15 "Filters",
"Tools",
"Utilities"};
16 private static final String TITLE =
"Installer";
17 private static String command =
"";
18 private static String shortcut =
"";
19 private static String defaultPlugin =
"";
20 private static String menuStr = menus[0];
22 public void run(String arg) {
26 void installPlugin() {
27 String[] plugins = getPlugins();
28 if (plugins==null || plugins.length==0) {
32 GenericDialog gd =
new GenericDialog(
"Install Plugin",
IJ.
getInstance());
33 gd.addChoice(
"Plugin:", plugins, defaultPlugin);
34 gd.addChoice(
"Menu:", menus, menuStr);
35 gd.addStringField(
"Command:", command, 16);
36 gd.addStringField(
"Shortcut:", shortcut, 3);
37 gd.addStringField(
"Argument:",
"", 12);
41 String plugin = gd.getNextChoice();
42 menuStr = gd.getNextChoice();
43 command = gd.getNextString();
44 shortcut = gd.getNextString();
45 String argument = gd.getNextString();
47 defaultPlugin = plugin;
48 if (command.equals(
"")) {
52 if (shortcut.length()>1)
53 shortcut = shortcut.replace(
'f',
'F');
55 if (menuStr.equals(menus[0]))
56 menu = Menus.SHORTCUTS_MENU;
57 else if (menuStr.equals(menus[1]))
58 menu = Menus.PLUGINS_MENU;
59 else if (menuStr.equals(menus[2]))
60 menu = Menus.IMPORT_MENU;
61 else if (menuStr.equals(menus[3]))
62 menu = Menus.SAVE_AS_MENU;
63 else if (menuStr.equals(menus[4]))
64 menu = Menus.FILTERS_MENU;
65 else if (menuStr.equals(menus[5]))
66 menu = Menus.TOOLS_MENU;
67 else if (menuStr.equals(menus[6]))
68 menu = Menus.UTILITIES_MENU;
69 if (!argument.equals(
""))
70 plugin +=
"(\"" + argument +
"\")";
71 int err = Menus.installPlugin(plugin,menu,command,shortcut,IJ.getInstance());
73 case Menus.COMMAND_IN_USE:
74 IJ.showMessage(TITLE,
"The command \""+command+
"\" \nis already being used.");
76 case Menus.INVALID_SHORTCUT:
77 IJ.showMessage(TITLE,
"The shortcut must be a single character or \"F1\"-\"F12\".");
79 case Menus.SHORTCUT_IN_USE:
80 IJ.showMessage(
"The \""+shortcut+
"\" shortcut is already being used.");
87 if (!plugin.endsWith(
")"))
91 void installAbout(String plugin) {
92 boolean hasShowAboutMethod=
false;
93 PluginClassLoader loader =
new PluginClassLoader(Menus.getPlugInsPath());
95 Class c = loader.loadClass(plugin);
96 Method m = c.getDeclaredMethod(
"showAbout",
new Class[0]);
98 hasShowAboutMethod =
true;
100 catch (Exception e) {}
102 if (hasShowAboutMethod)
103 Menus.installPlugin(plugin+
"(\"about\")",Menus.ABOUT_MENU,plugin+
"...",
"",IJ.getInstance());
106 String[] getPlugins() {
107 String path = Menus.getPlugInsPath();
110 File f =
new File(path);
111 String[] list = f.list();
112 if (list==null)
return null;
113 Vector v =
new Vector();
114 for (
int i=0; i<list.length; i++) {
115 String className = list[i];
116 boolean isClassFile = className.endsWith(
".class");
117 if (className.indexOf(
'_')>=0 && isClassFile && className.indexOf(
'$')<0 ) {
118 className = className.substring(0, className.length()-6);
119 v.addElement(className);
122 getSubdirectoryPlugins(path, className, v);
125 list =
new String[v.size()];
126 v.copyInto((String[])list);
127 StringSorter.sort(list);
132 void getSubdirectoryPlugins(String path, String dir, Vector v) {
134 if (dir.endsWith(
".java"))
136 File f =
new File(path, dir);
137 if (!f.isDirectory())
139 String[] list = f.list();
143 for (
int i=0; i<list.length; i++) {
144 String name = list[i];
145 if (name.indexOf(
'_')>=0 && name.endsWith(
".class") && name.indexOf(
'$')<0 ) {
146 name = name.substring(0, name.length()-6);