12 private static final String TITLE =
"Hotkeys";
13 private static String command =
"";
14 private static String shortcut =
"";
16 public void run(String arg) {
17 if (arg.equals(
"install"))
19 else if (arg.equals(
"remove"))
28 void installHotkey() {
29 String[] commands = getAllCommands();
30 GenericDialog gd =
new GenericDialog(
"Create Shortcut");
31 gd.addChoice(
"Command:", commands, command);
32 gd.addStringField(
"Shortcut:", shortcut, 3);
36 command = gd.getNextChoice();
37 shortcut = gd.getNextString();
38 if (shortcut.equals(
"")) {
42 if (shortcut.length()>1)
43 shortcut = shortcut.replace(
'f',
'F');
44 String plugin =
"ij.plugin.Hotkeys("+
"\""+command+
"\")";
47 case Menus.INVALID_SHORTCUT:
48 IJ.
showMessage(TITLE,
"The shortcut must be a single character or F1-F12.");
50 case Menus.SHORTCUT_IN_USE:
51 IJ.
showMessage(
"The \""+shortcut+
"\" shortcut is already being used.");
60 String[] commands = getInstalledCommands();
62 IJ.showMessage(
"Remove...",
"No installed commands found.");
65 GenericDialog gd =
new GenericDialog(
"Remove");
66 gd.addChoice(
"Command:", commands,
"");
67 gd.addMessage(
"The command is not removed\nuntil ImageJ is restarted.");
71 command = gd.getNextChoice();
72 int err = Menus.uninstallPlugin(command);
73 boolean removed =
true;
74 if(err==Menus.COMMAND_NOT_FOUND)
75 removed = deletePlugin(command);
77 IJ.showStatus(
"\""+command +
"\" removed; ImageJ restart required");
79 IJ.showStatus(
"\""+command +
"\" not removed");
82 boolean deletePlugin(String command) {
83 String plugin = (String)Menus.getCommands().get(command);
84 String name = plugin+
".class";
85 File file =
new File(Menus.getPlugInsPath(), name);
86 if (file==null || !file.exists())
89 return IJ.showMessageWithCancel(
"Delete Plugin?",
"Permanently delete \""+name+
"\"?");
92 String[] getAllCommands() {
93 Vector v =
new Vector();
94 for (Enumeration en=Menus.getCommands().keys(); en.hasMoreElements();) {
95 String cmd = (String)en.nextElement();
96 if (!cmd.startsWith(
"*"))
99 String[] list =
new String[v.size()];
100 v.copyInto((String[])list);
101 StringSorter.sort(list);
105 String[] getInstalledCommands() {
106 Vector v =
new Vector();
107 Hashtable commandTable = Menus.getCommands();
108 for (Enumeration en=commandTable.keys(); en.hasMoreElements();) {
109 String cmd = (String)en.nextElement();
110 if (cmd.startsWith(
"*"))
113 String plugin = (String)commandTable.get(cmd);
114 if (plugin.indexOf(
"_")>=0 && !plugin.startsWith(
"ij."))
120 String[] list =
new String[v.size()];
121 v.copyInto((String[])list);
122 StringSorter.sort(list);