Remove autogenerated comments
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / events / callback / JavaCallBack.java
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
4  *
5  *  This file must be used under the terms of the CeCILL.
6  *  This source file is licensed as described in the file COPYING, which
7  *  you should have received as part of this distribution.  The terms
8  *  are also available at
9  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 package org.scilab.modules.gui.events.callback;
13
14 import java.awt.event.ActionEvent;
15 import java.lang.reflect.Method;
16
17 /**
18  * Generic class to hide callback management
19  * @author bruno
20  *
21  */
22 public abstract class JavaCallBack extends CallBack {
23
24         /**
25          * @param command : the command to execute.
26          */
27         private JavaCallBack(String command) {
28                 super(command);
29         }
30
31         /**
32          * Callback Factory to easily create a callback
33          * just like in scilab.
34          * @param command : the command to execute.
35          * @return a usable Java callback
36          */
37         public static JavaCallBack create(String command) {
38                 return (new JavaCallBack(command) {
39                         public void callBack() {
40                                 try {
41                                         int lastPoint = command.lastIndexOf(".");
42                                         Class invokedClass = Class.forName(command.substring(0, lastPoint));
43                                         Method runMe = invokedClass.getMethod(command.substring(lastPoint + 1));
44                                         // Only able to launch method Class.
45                                         runMe.invoke(invokedClass.getClass(), (Object[]) null);
46                                 } catch (Exception e) {
47                                         e.printStackTrace();
48                                 }
49                         }
50                 });
51         }
52         
53         /**
54          * Callback Factory to easily create a callback
55          * just like in scilab.
56          * @param command : the command to execute.
57          * @return a usable Java callback
58          */
59         public static CallBack createOutOfXclickAndXgetmouse(String command) {
60                 return (new JavaCallBack(command) {
61                         public void callBack() {
62                                 try {
63                                         int lastPoint = command.lastIndexOf(".");
64                                         Class invokedClass = Class.forName(command.substring(0, lastPoint));
65                                         Method runMe = invokedClass.getMethod(command.substring(lastPoint + 1));
66                                         // Only able to launch method Class.
67                                         runMe.invoke(invokedClass.getClass(), (Object[]) null);
68                                 } catch (Exception e) {
69                                         e.printStackTrace();
70                                 }
71                         }
72                         
73                         /**
74                          * To match the standard Java Action management.
75                          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
76                          * @param e The event that launch the callback.
77                          */
78                         public void actionPerformed(ActionEvent e) {
79                             callBack();
80                         } 
81                 });        
82         }
83 }