/Users/lyon/j4p/src/gui/BeanShortCutFrame.java

1    package gui; 
2     
3    import ip.gui.frames.ShortCutFrame; 
4     
5    import java.awt.*; 
6    import java.awt.event.ActionEvent; 
7    import java.awt.event.ActionListener; 
8    import java.awt.event.KeyEvent; 
9    import java.beans.*; 
10   import java.lang.reflect.Method; 
11   import java.util.Hashtable; 
12    
13   public class BeanShortCutFrame extends ShortCutFrame 
14           implements BeanInfo, ActionListener { 
15       public MenuItem 
16               addMenuItem(Menu m, String s, String Command) { 
17           ComMenuItem cmi = 
18                   ComMenuItem.addMenuItem(m, s, Command, this); 
19           addMenuItemShortCut(cmi, s); 
20           return 
21                   cmi; 
22       } 
23    
24       public BeanShortCutFrame(String title) { 
25           super(title); 
26       } 
27    
28       public void keyTyped(KeyEvent e) { 
29           super.keyTyped(e); 
30           invokeMenuitemForString(getPs()); 
31       } 
32    
33       public void actionPerformed(ActionEvent e) { 
34           if (!(e.getSource() instanceof ComMenuItem)) { 
35               super.actionPerformed(e); 
36               return; 
37           } 
38           ComMenuItem cmi = (ComMenuItem) e.getSource(); 
39           invokeMenuItem(cmi); 
40       } 
41    
42       public void invokeMenuItem(ComMenuItem cmi) { 
43           checkMenuItem(cmi); 
44           cmi.invoke(); 
45       } 
46    
47       public Method getMethod(Class cls, String methodName) 
48               throws IntrospectionException { 
49           Method methods[] = cls.getMethods(); 
50           for (int i = 0; i < methods.length; i++) 
51               if (methods[i].getName().equals(methodName)) 
52                   return methods[i]; 
53           throw new IntrospectionException("No method \"" + methodName); 
54       } 
55    
56       public void addMenuItemShortCut(ComMenuItem cmi, String s) { 
57           String sc = getShortCutString(s); 
58           if (sc == null) return; 
59           h.put(sc, cmi); 
60       } 
61    
62       public String getShortCutString(String s) { 
63           int i = s.indexOf(']'); 
64           if (i < 0) return null; 
65           return s.substring(0, i + 1); 
66       } 
67    
68    
69       public void invokeMenuitemForString(String s) { 
70           Object o = h.get(s); 
71           if (!(o instanceof ComMenuItem)) return; 
72           invokeMenuItem((ComMenuItem) o); 
73       } 
74    
75       public void checkMenuItem(ComMenuItem cmi) { 
76           if (cmi.m == null) 
77               try { 
78                   Method m = getMethod( 
79                           this.getClass(), cmi.commandString); 
80                   cmi.m = m; 
81               } catch (Exception ex) { 
82                   System.out.println(ex); 
83               } 
84       } 
85    
86       protected Hashtable h = new Hashtable(); 
87    
88       public BeanDescriptor getBeanDescriptor() { 
89           return null; 
90       } 
91    
92       /** 
93        * Deny knowledge of properties. You can override this 
94        * if you wish to provide explicit property info. 
95        */ 
96       public PropertyDescriptor[] getPropertyDescriptors() { 
97           return null; 
98       } 
99    
100      /** 
101       * Deny knowledge of a default property. You can override this 
102       * if you wish to define a default property for the bean. 
103       */ 
104      public int getDefaultPropertyIndex() { 
105          return -1; 
106      } 
107   
108      /** 
109       * Deny knowledge of event sets. You can override this 
110       * if you wish to provide explicit event set info. 
111       */ 
112      public EventSetDescriptor[] getEventSetDescriptors() { 
113          return null; 
114      } 
115   
116      /** 
117       * Deny knowledge of a default event. You can override this 
118       * if you wish to define a default event for the bean. 
119       */ 
120      public int getDefaultEventIndex() { 
121          return -1; 
122      } 
123   
124      /** 
125       * Deny knowledge of methods. You can override this 
126       * if you wish to provide explicit method info. 
127       */ 
128      public MethodDescriptor[] getMethodDescriptors() { 
129          return null; 
130      } 
131   
132      /** 
133       * Claim there are no other relevant BeanInfo objects.  You 
134       * may override this if you want to (for example) return a 
135       * BeanInfo for a base class. 
136       */ 
137      public BeanInfo[] getAdditionalBeanInfo() { 
138          return null; 
139      } 
140   
141      /** 
142       * Claim there are no icons available.  You can override 
143       * this if you want to provide icons for your bean. 
144       */ 
145      public Image getIcon(int iconKind) { 
146          return null; 
147      } 
148   
149  }