2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
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
12 package org.scilab.modules.gui.events.callback;
14 import java.awt.event.ActionEvent;
15 import java.lang.reflect.Method;
18 * Generic class to hide callback management
22 public abstract class JavaCallBack extends CallBack {
25 * @param command : the command to execute.
27 private JavaCallBack(String command) {
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
37 public static JavaCallBack create(String command) {
38 return (new JavaCallBack(command) {
39 public void callBack() {
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 // TODO Auto-generated catch block
55 * Callback Factory to easily create a callback
56 * just like in scilab.
57 * @param command : the command to execute.
58 * @return a usable Java callback
60 public static CallBack createOutOfXclickAndXgetmouse(String command) {
61 return (new JavaCallBack(command) {
62 public void callBack() {
64 int lastPoint = command.lastIndexOf(".");
65 Class invokedClass = Class.forName(command.substring(0, lastPoint));
66 Method runMe = invokedClass.getMethod(command.substring(lastPoint + 1));
67 // Only able to launch method Class.
68 runMe.invoke(invokedClass.getClass(), (Object[]) null);
69 } catch (Exception e) {
70 // TODO Auto-generated catch block
76 * To match the standard Java Action management.
77 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
78 * @param e The event that launch the callback.
80 public void actionPerformed(ActionEvent e) {