00001 package org.hfbk.util;
00002
00003 import java.awt.Container;
00004 import java.awt.Frame;
00005 import java.awt.event.WindowAdapter;
00006 import java.awt.event.WindowEvent;
00007
00008 import org.hfbk.vis.ImageLoader;
00009 import org.hfbk.vis.VisClient;
00010 import org.hfbk.vis.VisClientScripter;
00011 import org.mozilla.javascript.EcmaError;
00012 import org.mozilla.javascript.EvaluatorException;
00013
00019 public class ScriptShell extends VisClientScripter {
00020
00021 String convenience=
00022 "function list(object){" +
00023 " var methods=''; " +
00024 " for(name in object){" +
00025 " var e=object[name];" +
00026 " var t=typeof e;" +
00027 " if (t!='function')" +
00028 " print (name+': '+e); " +
00029 " }" +
00030 "}"+
00031 "function fields(object){" +
00032 " cl=object.getClass();" +
00033 " print(cl.getFields());" +
00034 "}"+
00035 "function methods(object){" +
00036 " cl=object.getClass(); " +
00037 " print(cl.getMethods()); " +
00038 "} " +
00039 "function print(object){" +
00040 " shell.println(object);" +
00041 "} " +
00042 "function kill(visnode){" +
00043 " visnode.parent.remove(visnode);" +
00044 "} " +
00045 "function exit(){" +
00046 " shell.getParent().dispose();" +
00047 "}" +
00048 "";
00049
00050
00051 Frame frame=new Frame("Vis/Shell");
00052 ShellPanel panel;
00053
00054 public ScriptShell(VisClient client){
00055 super(client);
00056
00057 frame.setIconImage(ImageLoader.getRessourceImage("icons/vis.png"));
00058 frame.addWindowListener(new WindowAdapter(){
00059 public void windowClosing(WindowEvent e) {
00060 frame.dispose();
00061 }
00062 });
00063 frame.add(panel=new ShellPanel(){
00064 public String action(String command) {
00065 try{
00066 return evaluate(command).toString();
00067 }catch(EvaluatorException e){
00068 return e.details();
00069 }catch (EcmaError e){
00070 return e.getErrorMessage();
00071 }
00072 }
00073 });
00074 put("shell",panel);
00075 evaluate(convenience);
00076
00077 frame.pack();
00078 UIUtils.blackify(frame);
00079 frame.setVisible(true);
00080 ((Container)frame.getComponent(0)).getComponent(1).requestFocus();
00081 }
00082
00083 public static void main(String[] args) {
00084 new ScriptShell(null);
00085 }
00086 }