/Users/lyon/j4p/src/ip/gui/applets/ConsoleApplet.java

1    package ip.gui.applets; 
2     
3    import ip.color.*; 
4    import ip.gui.frames.TopFrame; 
5    import ip.transforms.TransformTable; 
6     
7    import java.applet.Applet; 
8    import java.awt.*; 
9    import java.awt.event.ActionEvent; 
10   import java.awt.event.ActionListener; 
11   import java.lang.reflect.Method; 
12   import java.util.StringTokenizer; 
13    
14   public class ConsoleApplet 
15           extends Applet implements ActionListener { 
16       TextField textField; 
17       String newline; 
18       String title = "Kahindu by D. Lyon"; 
19       TopFrame tf = new TopFrame(title); 
20    
21       public void init() { 
22           tf.setVisible(true); 
23           textField = new TextField(80); 
24           //Add Components to the Applet. 
25           GridBagLayout gridBag = new GridBagLayout(); 
26           setLayout(gridBag); 
27           GridBagConstraints c = new GridBagConstraints(); 
28           c.gridwidth = GridBagConstraints.REMAINDER; 
29    
30           c.fill = GridBagConstraints.HORIZONTAL; 
31           gridBag.setConstraints(textField, c); 
32           add(textField); 
33    
34           textField.addActionListener(this); 
35    
36           newline = System.getProperty("line.separator"); 
37       } 
38    
39       public static void main(String args[]) { 
40           ConsoleApplet c = new ConsoleApplet(); 
41           Frame f = new Frame(); 
42           f.add(c); 
43           c.setVisible(true); 
44           f.setVisible(true); 
45           c.init(); 
46    
47       } 
48    
49       public void actionPerformed(ActionEvent evt) { 
50           String text = textField.getText(); 
51    
52           try { 
53               //String line; 
54               //DataInputStream dis = new DataInputStream(System.in); 
55               //while ((line=dis.readLine())!= null) { 
56               //System.out.println(line); 
57               StringTokenizer st = new StringTokenizer(text); 
58               //while (st.hasMoreTokens() ) { 
59               String t1 = st.nextToken(); 
60               //System.out.println(t1); 
61               if (t1.equalsIgnoreCase("help")) { //if first token is help 
62                   if (st.countTokens() == 0) {//case1: help 
63                       //System.out.println(st.countTokens()); 
64                       tf.printMethods(); 
65                   } 
66    
67                   if (st.countTokens() == 1) {//case2: help className 
68                       //System.out.println("in case 2"); 
69                       String t2 = st.nextToken(); 
70                       // System.out.println(t2); 
71                       String test1 = "ip.gui."; 
72                       Class r = Class.forName(test1.concat(t2)); 
73                       //System.out.println("r="+r); 
74                       tf.printMethods(r.getMethods()); 
75                   }//end if case2 
76               }//end if 
77               else {  //if first token is not help 
78                   //if (st.countTokens()==0) {   //case3: classname.method 
79                   //System.out.println("classname.method"); 
80    
81                   StringTokenizer st1 = new StringTokenizer(t1, "."); 
82    
83                   System.out.println(t1); 
84                   String cntok = st1.nextToken(); 
85                   //System.out.println(cntok); 
86                   String mntok = st1.nextToken(); 
87                   //System.out.println(mntok); 
88                   Class r = Class.forName("ip.gui." + cntok); 
89                   Class pArray[] = new Class[0]; 
90                   int tokenNum = st.countTokens(); 
91                   //Object pArray[] = new Object[tokenNum]; 
92                   //for ( int i = 0;i < tokenNum; i++ ) { 
93                   //  pArray[i] = st.nextToken(); 
94                   //} 
95                   /*if(st.countTokens()==0){ 
96                       pArray[]=new Class[0]; 
97                   } 
98                   if(st.countTokens()==1){ 
99                       pArray[]=new Class[1]; 
100                      pArray[0]=st.nextToken(); 
101   
102                  } 
103                  if(st.countTokens()==2){ 
104                      Class pArray[]=new Class[2]; 
105                      //pArray[0]=(Class)st.nextToken(); 
106                      //pArray[1]=(Class)st.nextToken(); 
107                  } 
108                  if(st.countTokens()==3){ 
109                      Class pArray[]=new Class[3]; 
110                      //pArray[0]=(Class)st.nextToken(); 
111                      //pArray[1]=(Class)st.nextToken(); 
112                      //pArray[2]=(Class)st.nextToken(); 
113                  } 
114                  */ 
115   
116                  Method m = r.getMethod(mntok, pArray); 
117   
118                  /*if (cntok.equalsIgnoreCase("AdaptiveLog")){ 
119                      AdaptiveLog a = new AdaptiveLog(tf); 
120                      m.invoke(a,pArray); 
121                  }*/ 
122                  if (cntok.equalsIgnoreCase("AffineFrame")) { 
123                      m.invoke(tf, pArray); 
124                  } else if (cntok.equalsIgnoreCase("AppletFrame")) { 
125                      m.invoke(tf, pArray); 
126                  } else if (cntok.equalsIgnoreCase("BeanFrame")) { 
127                      m.invoke(tf, pArray); 
128                  } else if (cntok.equalsIgnoreCase("BeanTester")) { 
129                      m.invoke(tf, pArray); 
130                  } else if (cntok.equalsIgnoreCase("BooLog")) { 
131                      m.invoke(tf, pArray); 
132                  } else if (cntok.equalsIgnoreCase("BoundaryFrame")) { 
133                      m.invoke(tf, pArray); 
134                  } 
135                  /*else if (cntok.equalsIgnoreCase("Byte")){ 
136                      Byte a = new Byte(tf); 
137                      m.invoke(a,pArray); 
138                  }*/ 
139                  else if (cntok.equalsIgnoreCase("Ccir601_2cbcr")) { 
140                      Ccir601_2cbcr a = new Ccir601_2cbcr(tf); 
141                      m.invoke(a, pArray); 
142                  } else if (cntok.equalsIgnoreCase("ClosableFrame")) { 
143                      m.invoke(tf, pArray); 
144                  } else if (cntok.equalsIgnoreCase("ColorFrame")) { 
145                      m.invoke(tf, pArray); 
146                  } else if (cntok.equalsIgnoreCase("ColorGridFrame")) { 
147                      m.invoke(tf, pArray); 
148                  } 
149                  /*else if (cntok.equalsIgnoreCase("ColorHash")){ 
150                      ColorHash a = new ColorHash(tf); 
151                      m.invoke(a,pArray); 
152                  }*/ 
153                  /*else if (cntok.equalsIgnoreCase("ComMenuItem")){ 
154                      ComMenuItem a = new ComMenuItem(); 
155                      m.invoke(a,pArray); 
156                  }*/ 
157                  else if (cntok.equalsIgnoreCase("ConvolutionFrame")) { 
158                      m.invoke(tf, pArray); 
159                  }    // Need to test 
160                  /*  Class CShort doesn't need to be included*/ 
161                  /*  Class DoLog doesn't need to be included*/ 
162                  /*  Class DoubleLog doesn't need to be included*/ 
163                  else if (cntok.equalsIgnoreCase("DrawFrame")) { 
164                      m.invoke(tf, pArray); 
165                  } else if (cntok.equalsIgnoreCase("DrawTest")) { 
166                      m.invoke(tf, pArray); 
167                  } else if (cntok.equalsIgnoreCase("EdgeFrame")) { 
168                      m.invoke(tf, pArray); 
169                  } 
170                  /*  Class Edgel doesn't need to be included*/ 
171                  else if (cntok.equalsIgnoreCase("EventTester")) { 
172                      m.invoke(tf, pArray); 
173                  } 
174                  /*   Class ExpandoLog doesn't need to be included */ 
175                  /*   Class ExponentialLog doesn't need to be included */ 
176                  else if (cntok.equalsIgnoreCase("FFTFrame")) { 
177                      m.invoke(tf, pArray); 
178                  } else if (cntok.equalsIgnoreCase("FFTImage")) { 
179                      m.invoke(tf, pArray); 
180                  } else if (cntok.equalsIgnoreCase("FFTRadix2")) { 
181                      m.invoke(tf, pArray); 
182                  } else if (cntok.equalsIgnoreCase("FileMenu")) { 
183                      m.invoke(tf, pArray); 
184                  } else if (cntok.equalsIgnoreCase("FilterFrame")) { 
185                      m.invoke(tf, pArray); 
186                  } else if (cntok.equalsIgnoreCase("FloatPlane")) { 
187                      m.invoke(tf, pArray); 
188                  } else if (cntok.equalsIgnoreCase("GrabFrame")) { 
189                      m.invoke(tf, pArray); 
190                  } else if (cntok.equalsIgnoreCase("Graph")) { 
191                      m.invoke(tf, pArray); 
192                  } 
193                  /*   Class GrayLog doesn't need to be included */ 
194                  /*   Class Haar doesn't need to be included */ 
195                  else if (cntok.equalsIgnoreCase("Histogram")) { 
196                      m.invoke(tf, pArray); 
197                  } else if (cntok.equalsIgnoreCase("Hls")) { 
198                      m.invoke(tf, pArray); 
199                  } else if (cntok.equalsIgnoreCase("Haar")) { 
200                      m.invoke(tf, pArray); 
201                  } else if (cntok.equalsIgnoreCase("IconFrame")) { 
202                      m.invoke(tf, pArray); 
203                  } else if (cntok.equalsIgnoreCase("ImageFrame")) { 
204                      m.invoke(tf, pArray); 
205                  } else if (cntok.equalsIgnoreCase("Lifting")) { 
206                      m.invoke(tf, pArray); 
207                  } else if (cntok.equalsIgnoreCase("MartelliFrame")) { 
208                      m.invoke(tf, pArray); 
209                  } else if (cntok.equalsIgnoreCase("Mat3")) { 
210                      m.invoke(tf, pArray); 
211                  } else if (cntok.equalsIgnoreCase("Mat4")) { 
212                      m.invoke(tf, pArray); 
213                  } else if (cntok.equalsIgnoreCase("MatLog")) { 
214                      m.invoke(tf, pArray); 
215                  } else if (cntok.equalsIgnoreCase("MedianCut")) { 
216                      m.invoke(tf, pArray); 
217                  } else if (cntok.equalsIgnoreCase("MessLog")) { 
218                      m.invoke(tf, pArray); 
219                  } else if (cntok.equalsIgnoreCase("MorphFrame")) { 
220                      m.invoke(tf, pArray); 
221                  } else if (cntok.equalsIgnoreCase("NegateFrame")) { 
222                      m.invoke(tf, pArray); 
223                  } else if (cntok.equalsIgnoreCase("OpenFrame")) { 
224                      m.invoke(tf, pArray); 
225                  } else if (cntok.equalsIgnoreCase("PaintFrame")) { 
226                      m.invoke(tf, pArray); 
227                  } else if (cntok.equalsIgnoreCase("ProgressFrame")) { 
228                      m.invoke(tf, pArray); 
229                  } else if (cntok.equalsIgnoreCase("examples.Random")) { 
230                      m.invoke(tf, pArray); 
231                  } else if (cntok.equalsIgnoreCase("SaveFrame")) { 
232                      m.invoke(tf, pArray); 
233                  } else if (cntok.equalsIgnoreCase("FrameOne")) { 
234                      m.invoke(tf, pArray); 
235                  } else if (cntok.equalsIgnoreCase("SnellWlx")) { 
236                      m.invoke(tf, pArray); 
237                  } else if (cntok.equalsIgnoreCase("SpatialFilterFrame")) { 
238                      m.invoke(tf, pArray); 
239                  } else if (cntok.equalsIgnoreCase("TopFrame")) { 
240                      m.invoke(tf, pArray); 
241                  } else if (cntok.equalsIgnoreCase("TransformTable")) { 
242                      TransformTable a = new TransformTable(1); 
243                      m.invoke(a, pArray); 
244                  } else if (cntok.equalsIgnoreCase("Yuv")) { 
245                      Yuv a = new Yuv(tf); 
246                      m.invoke(a, pArray); 
247                  } else if (cntok.equalsIgnoreCase("Yiq")) { 
248                      Yiq a = new Yiq(tf); 
249                      m.invoke(a, pArray); 
250                  } else if (cntok.equalsIgnoreCase("Xyzd65")) { 
251                      Xyzd65 a = new Xyzd65(tf); 
252                      m.invoke(a, pArray); 
253                  } else if (cntok.equalsIgnoreCase("Wu")) {//not work 
254                      Wu a = new Wu(); 
255                      m.invoke(a, pArray); 
256                  } else if (cntok.equalsIgnoreCase("XformFrame")) { 
257                      m.invoke(tf, pArray); 
258                  } else if (cntok.equalsIgnoreCase("WaveletFrame")) { 
259                      m.invoke(tf, pArray); 
260                  } else if (cntok.equalsIgnoreCase("SpatialFilterFrame")) { 
261                      m.invoke(tf, pArray); 
262                  } else if (cntok.equalsIgnoreCase("ShortCutFrame")) { 
263                      m.invoke(tf, pArray); 
264                  } else if (cntok.equalsIgnoreCase("ColorFrame")) { 
265                      m.invoke(tf, pArray); 
266                  } 
267   
268              } 
269              //  }//end of while 
270              //  }//end of while 
271          } //end of try 
272          catch (Exception e) { 
273              System.out.println(e); 
274          } 
275          // textField.selectAll(); 
276      }//end of actionPerformed() 
277   
278   
279      public void paint(Graphics g) { 
280          g.drawString("Command line interface", 30, 30); 
281      } 
282   
283  } 
284