Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
CommandLister.java
1 package ij.plugin;
2 import ij.*;
3 import ij.text.*;
4 import ij.util.*;
5 import java.util.*;
6 import java.awt.*;
7 import java.awt.event.*;
8 
10 public class CommandLister implements PlugIn {
11 
12  public void run(String arg) {
13  if (arg.equals("shortcuts"))
14  listShortcuts();
15  else
16  listCommands();
17  }
18 
19  public void listCommands() {
20  Hashtable commands = Menus.getCommands();
21  Vector v = new Vector();
22  for (Enumeration en=commands.keys(); en.hasMoreElements();) {
23  String command = (String)en.nextElement();
24  v.addElement(command+"\t"+(String)commands.get(command));
25  }
26  showList("Commands", "Command\tPlugin", v);
27  }
28 
29  public void listShortcuts() {
30  Hashtable shortcuts = Menus.getShortcuts();
31  Vector v = new Vector();
32  for (Enumeration en=shortcuts.keys(); en.hasMoreElements();) {
33  Integer key = (Integer)en.nextElement();
34  int keyCode = key.intValue();
35  boolean upperCase = false;
36  if (keyCode>200) {
37  upperCase = true;
38  keyCode -= 200;
39  }
40  String shortcut = KeyEvent.getKeyText(keyCode);
41  if (!upperCase && shortcut.length()==1) {
42  char c = shortcut.charAt(0);
43  if (c>=65 && c<=90)
44  c += 32;
45  char[] chars = new char[1];
46  chars[0] = c;
47  shortcut = new String(chars);
48  }
49  if (shortcut.length()>1)
50  shortcut = " " + shortcut;
51  v.addElement(shortcut+"\t"+(String)shortcuts.get(key));
52  }
53  showList("Keyboard Shortcuts", "Hot Key\tCommand", v);
54  }
55 
56  void showList(String title, String headings, Vector v) {
57  String[] list = new String[v.size()];
58  v.copyInto((String[])list);
59  StringSorter.sort(list);
60  StringBuffer sb = new StringBuffer();
61  for (int i=0; i<list.length; i++) {
62  sb.append(list[i]);
63  sb.append("\n");
64  }
65  TextWindow tw = new TextWindow(title, headings, sb.toString(), 300, 400);
66  }
67 }