\documentclass{article} \usepackage{axiom} \begin{document} \title{JMAN} \author{Timothy Daly} \maketitle \begin{abstract} We need a method of doing GUI operations portably in Axiom. There are various attempts at making a GUI available but few are really cross-platform. Initially we attempted to use TK from lisp. This turned out to be a huge learning curve since we needed to reproduce pre-defined screens which already exist in Axiom. Screen configuration was very hard and there did not appear to be a way to display graphics using the lisp took (ltk). Instead, we've decided to take the long path. We use Java as our front end and create an API which allows us to produce the required screens. The downside is that we have to write the Java front end. The upside is that we have complete control of the primitives. \end{abstract} \eject \tableofcontents \eject \section{Overview} There is a major portability issue in Axiom. The Hyperdoc and Graphics functions are written in C and use X11 windows. We need to be able to replace the Graphics and Hyperdoc functions with a more portable implementation. Initially this was going to be a [[cygwin]] mechanism because it implements an X11 on Windows. This fails because we eventually decided to use the [[Msys]] windows environment. Next it was decided that we would use McClim, the common lisp graphics. This fails because McClim does not yet work properly. Next we tried to use [[ltk]] the lisp TK toolkit interface. This fails because there does not appear to be a way to get TK to display images. Finally we settled on rewriting TK into Java which would make it portable and make the code freely available since we wrote it ourselves. Thus this is an implementation of the TK replacement code. It is intended to run in a stand-alone lisp and communicate to the Axiom lisp image using sockets. In order to build this from the ground up we need to implement a display (see the display class) and a console which would accept lisp s-expressions and return the results. That way we can implement a stand-alone version of the system. The console is intended to communicate to the display over sockets. Axiom will work just like the console class and use the same socket interface. So for development purposes we need to be able to type a set of s-expressions and evaluate them. This is done in several steps. Step 0 is to implement a fixed file that contains a set of display s-expressions and execute the fixed file. Step 1 is to implement an all-java solution using a console to talk to a socket connected to the display class. Step 2 is to implement a lisp-java interface so commands can be typed from the console. Step 3 is to allow Axiom to start the lisp and let the lisp drive the display class. We may also want to explore allowing Axiom to drive the display class directly. \subsection{The fixed file development step} The idea here is to read a line from a file, evaluate the line, and return the result. In this case we will read a line that says <>= "(W1 window make 200 200 400 400)" "(W1 window layout borderlayout)" "(I1 image make blueaxiom.jpg)" "(L2 label make)" "(L2 label image I1)" "(P3 panel make)" "(P3 panel layout borderlayout)" "(P3 panel add L2 Center)" "(W1 window add P3 Center)" "(W1 window show)" @ <>= "(W1 window make 200 200 400 400)" "(W1 window layout borderlayout)" "(B1 button make one)" "(B2 button make two)" "(L1 label make)" "(L1 label text HYPERDOC)" "(B3 button make three)" "(B4 button make four)" "(P1 panel make)" "(P1 panel layout borderlayout)" "(P1 panel add B1 West)" "(P2 panel make)" "(P2 panel layout borderlayout)" "(P2 panel add B2 West)" "(P2 panel add L1 Center)" "(P2 panel add B3 East)" "(P1 panel add P2 Center)" "(P1 panel add B4 East)" "(W1 window add P1 North)" "(I1 image make blueaxiom.jpg)" "(L2 label make)" "(L2 label image I1)" "(P3 panel make)" "(P3 panel layout borderlayout)" "(P3 panel add L2 Center)" "(W1 window add P3 Center)" "(W1 window show)" @ using a java buffered stream. Next we build a [[Display]] object and call the eval method, passing the line we read. The [[Display]] object parses and executes the line. This causes it to build a window, add it to the hash tble under a new key, and show it. The key is returned as the ``name'' of the window. \subsubsection{method readTestCase} <>= public void readTestCase(String file) { try { in = new BufferedReader(new FileReader("testcase")); print(eval(readTestFile(in.readLine()))); print(eval(readTestFile(in.readLine()))); print(eval(readTestFile(in.readLine()))); } catch(Exception e) { e.printStackTrace(); System.exit(0); } } @ \subsubsection{method readTestFile} <>= public String readTestFile(String file) { return(file); } @ \subsubsection{method eval} <>= public String eval(String line) { String result = display.eval(line); return(result); } @ \subsubsection{method print} <>= public void print(String line) { System.err.println(line); } @ \subsubsection{step 0 code} <>= class testStep0 { BufferedReader in = null; Display display = new Display(); <> <> <> <> } @ \section{jman.lisp} \subsection{jman.lisp} \subsubsection{function do-execute} The do-execute function is a lisp-portable function to start a separate program. We use this function to start the Java program which is our front end. <>= (defun do-execute (program args &optional (wt nil)) "execute program with args a list containing the arguments passed to the program if wt is non-nil, the function will wait for the execution of the program to return. returns a two way stream connected to stdin/stdout of the program" (format t "do-execute ~a ~a ~a~%" program args wt) (let ((fullstring program)) (dolist (a args) (setf fullstring (concatenate 'string fullstring " " a))) #+(or :ibcl :kcl :akcl :gcl :ccl) (let ((proc (si::system (apply #'si::string-concatenate program " " args))))) #+:cmu (let ((proc (run-program program args :input :stream :output :stream :wait wt))) (unless proc (error "Cannot create process.")) (make-two-way-stream (ext:process-output proc) (ext:process-input proc))) #+:clisp (let ((proc (ext:run-program program :arguments args :input :stream :output :stream :wait t))) (unless proc (error "Cannot create process.")) proc) #+:sbcl (let ((proc (sb-ext:run-program program args :input :stream :output :stream :wait wt))) (unless proc (error "Cannot create process.")) (make-two-way-stream (process-output proc) (process-input proc))) #+:lispworks (system:open-pipe fullstring :direction :io) #+:allegro (let ((proc (excl:run-shell-command (apply #'vector program program args) :input :stream :output :stream :wait wt))) (unless proc (error "Cannot create process.")) proc) #+:ecl (ext:run-program program args :input :stream :output :stream :error :output) #+:openmcl (let ((proc (ccl:run-program program args :input :stream :output :stream :wait wt))) (unless proc (error "Cannot create process.")) (make-two-way-stream (ccl:external-process-output-stream proc) (ccl:external-process-input-stream proc))))) @ \subsubsection{open-socket} <>= (deftype socket () #+abcl 'to-way-stream #+allegro 'excl::socket-stream #+clisp 'stream #+(or cmu scl) 'sys:fd-stream #+gcl 'stream #+lispworks 'comm:socket-stream #+openmcl 'ccl::socket #+(and sbcl db-sockets) 'sb-sys:fd-stream #+(and sbcl net.sbcl.sockets) 'net.sbcl.sockets:stream-socket #-(or abcl allegro clisp cmu gcl lispworks openmcl (and sbcl (or db-sockets net.sbcl.sockets)) scl) 'stream) (defun open-socket (host port &optional bin) "Open a socket connection to HOST at PORT." (declare (type (or integer string) host) (fixnum port) (type boolean bin)) (let ((host (etypecase host (string host) (integer (hostent-name (resolve-host-ipaddr host)))))) #+abcl (ext:get-socket-stream (sys:make-socket host port) :element-type (if bin '(unsigned-byte 8) 'character)) #+allegro (socket:make-socket :remote-host host :remote-port port :format (if bin :binary :text)) #+clisp (#+lisp=cl ext:socket-connect #-lisp=cl lisp:socket-connect port host :element-type (if bin '(unsigned-byte 8) 'character)) #+(or cmu scl) (sys:make-fd-stream (ext:connect-to-inet-socket host port) :buffering (if bin :full :line) :input t :output t :element-type (if bin '(unsigned-byte 8) 'character)) #+gcl (si:socket port :host host) #+lispworks (comm:open-tcp-stream host port :direction :io :element-type (if bin 'unsigned-byte 'base-char)) #+mcl (ccl:make-socket :remote-host host :remote-port port :format (if binary-p :binary :text)) #+(and sbcl db-sockets) (let ((socket (make-instance 'sockets:inet-socket :type :stream :protocol :tcp))) (sockets:socket-connect socket (sockets::host-ent-address (sockets:get-host-by-name host)) port) (sockets:socket-make-stream socket :input t :output t :buffering (if bin :none :line) :element-type (if bin '(unsigned-byte 8) 'character))) #+(and sbcl net.sbcl.sockets) (net.sbcl.sockets:make-socket (if bin 'net.sbcl.sockets:binary-stream-socket 'net.sbcl.sockets:character-stream-socket) :port port :host host) #-(or abcl allegro clisp cmu gcl lispworks mcl (and sbcl (or net.sbcl.sockets db-sockets)) scl) (error 'not-implemented :proc (list 'open-socket host port bin)))) @ This is the top level jman process. It runs in a lisp listener. The lisp used is specified by the [[${LISP}]] variable in the Makefile. \subsubsection{jman.lisp} <>= <> <> (defun testcase () (mapcar #'send '( <> ))) (defun send (sexpr) (format *socket* "~a~%" sexpr)) (defun telnet (host port fn) (format t "~a~%" (setq *socket* (open-socket "127.0.0.1" 14000))) (apply fn nil)) (defun main () (format t "~%hello, world~%") (setq jmanconsole (do-execute "java" '("Jman" "accept" "14000"))) (do ((result nil)) (result) (princ ".") (setq result (read jmanconsole nil))) (format t "running testcase~%") (telnet "127.0.0.1" 14000 #'testcase) (format t "goodbye, world~%") (bye)) (main) @ %java code \section{Jman.java} \subsection{java imports} <>= import com.sun.image.codec.jpeg.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import java.io.*; import java.net.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.text.html.*; @ \subsection{class Parm} \subsubsection{Properties props} The [[props]] is a hashtable containing known initialization constants. It holds the results from reading the Jman.ini file. <>= public static Properties props; @ \subsubsection{boolean loaded} The [[loaded]] boolean is true if we found and loaded the initialization file. <>= private static boolean loaded = false; @ \subsubsection{method loadParms} Load the file Jman.ini and parse all of the initialization forms in it. These are stored in a hash table and can be retrieved by the various [[get]] methods, e.g. [[getFont]] for Fonts. <>= public static void loadParms() { props = new Properties(); initDefaults(); try { props.load(new FileInputStream("Jman.ini")); loaded = true; } catch(IOException e) { System.err.println("Parm:file Jman.ini not found. Using defaults."); } } @ \subsubsection{method debugging} debugging is a simple predicate used for adding debugging tests. It can be turned on and off using the flag in Jman.ini <>= public static boolean debugging() { if (getParm("Debug").equals("on")) return(true); return(false); } @ \subsubsection{method tracing} tracing is a simple predicate used for adding trace messages It can be turned on and off using the flag in Jman.ini <>= public static boolean tracing() { if (getParm("CatchTrace").equals("on")) return(true); return(false); } @ The [[getColor]] method calls [[getParm]] to look up the value and uses [[parseColor]] to parse out a color. <>= public static Color getColor(String key) { return(parseColor(getParm(key))); } @ \subsubsection{method parseColor} The [[parseColor]] method takes a 6 hex digit string and returns a java Color object. The string argument should be of the form ``[Color rrggbb]'' where red=rr green=gg blue=bb in hex e.g. [Color 123456] == java.awt.Color[r=18,g=52,b=86] Converts the return value to an java Color object. <>= public static Color parseColor(String value) { int[] nums = new int[6]; char hexchar; for(int i = 0; i<6; i++) { hexchar = value.charAt(7+i); switch (hexchar) { case 'a': case 'A': nums[i]=10; break; case 'b': case 'B': nums[i]=11; break; case 'c': case 'C': nums[i]=12; break; case 'd': case 'D': nums[i]=13; break; case 'e': case 'E': nums[i]=14; break; case 'f': case 'F': nums[i]=15; break; default: nums[i]=Integer.parseInt(hexchar+""); break; } } int red = nums[0]*16+nums[1]; int green = nums[2]*16+nums[3]; int blue = nums[4]*16+nums[5]; return(new Color(red,green,blue)); } @ \subsubsection{method getBorder} The [[getBorder]] calls getParm to look up the value and parses out a border. The value should be of the form ``[Border type a b c d]'' where a b c d are the border insets and type is one of \{ EMPTY MATTE ETCHED \} Converts the return value to an border as a java Border object. <>= public static Border getBorder(String key) { String value = getParm(key); Border result = new EmptyBorder(1,1,1,1); final int EMPTY = 0; final int MATTE = 1; final int ETCHED = 2; int borderType = EMPTY; int point = 0; int mark = 0; int a = 1; int b = 1; int c = 1; int d = 1; if ((mark = value.indexOf("EMPTY")) != -1) borderType = EMPTY; if ((mark = value.indexOf("MATTE")) != -1) borderType = MATTE; if ((mark = value.indexOf("ETCHED")) != -1) borderType = ETCHED; if (mark != -1) { switch (borderType) { case EMPTY: point = value.indexOf(' ',mark)+1; mark = value.indexOf(' ',point); a = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(' ',point); b = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(' ',point); c = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(']',point); d = Integer.parseInt(value.substring(point,mark)); result = new EmptyBorder(a,b,c,d); break; case MATTE: point = value.indexOf(' ',mark)+1; mark = value.indexOf(' ',point); a = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(' ',point); b = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(' ',point); c = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf(' ',point); d = Integer.parseInt(value.substring(point,mark)); point=mark+1; mark=value.indexOf('[',point); if (mark == -1) { Catch.log("Parm:parseBorder","bad Color in Border: "+value, new Exception("Jman.ini:bad Color in Border: "+value)); System.err.println( "Parm:parseBorder: bad Color in Border: "+value); } else result=new MatteBorder(a,b,c,d,parseColor(value.substring(mark))); break; case ETCHED: point = value.indexOf('[',mark); mark = value.indexOf(']',point); Color highlight = parseColor(value.substring(point,mark)); point = value.indexOf('[',mark); mark = value.indexOf(']',point); Color shadow = parseColor(value.substring(point,mark)); result = new EtchedBorder(highlight,shadow); break; } } return(result); } @ The [[getFont]] calls [[getParm]] to look up the value and parses out a font. The value should be of the form [Color name type size] where name=font name, type= font type, size= font pointsize e.g. [Font Dialog Font.PLAIN 12] == java.awt.Font[family=dialog,name=Dialog,style=plain,size=12] Converts the return value to a java Font object. <>= public static Font getFont(String key) { String value = getParm(key); int point = 6; int mark = value.indexOf(' ',point); String name = value.substring(point,mark); point = mark+1; mark = value.indexOf(' ',point); String type = value.substring(point,mark); int fonttype = Font.PLAIN; if (type.toUpperCase().equals("BOLD")) fonttype = Font.BOLD; if (type.toUpperCase().equals("ITALIC")) fonttype = Font.ITALIC; point = mark+1; mark = value.indexOf(']',point); int size = Integer.parseInt(value.substring(point,mark)); return(new Font(name,fonttype,size)); } @ \subsubsection{method getParmQuiet} The [[getArrayParm]] looks up the key in a hashtable and returns the value found. It will not complain if the key is missing. If the key is not found a hardcoded default value is returned. <>= public static String getParmQuiet(String key) { if (loaded == false) loadParms(); return((String)props.get(key)); } @ \subsubsection{method getParm} The [[getParm]] looks up the key in a hashtable and returns the value found. If the key is not found a hardcoded default value is returned. Be aware that calling getParm directly will return the exact initialization string. However some of the initialization strings in [[Jman.ini]] have our own extended syntax to handle colors, borders, etc. If you want to get the correct java object you should call the appropriate get method. <>= public static String getParm(String key) { if (loaded == false) loadParms(); String value = (String)props.get(key); if ((!(key.equals("Debug"))) && ((String)props.get("Debug")).equals("on")) System.err.println("Parm:getParm "+key+"="+value); if (value == null) { Catch.log("Parm:getParm","key="+key+" has no value in Jman.ini", new Exception("Jman.ini is missing the key "+key)); System.err.println("Parm:getParm:key="+key+ " has no value in Jman.ini"); } return(value); } @ \subsubsection{method setParm} The [[setParm]] can be used to change existing or add new parms. Be aware that calling getParm directly will return the exact initialization string. However some of the initialization strings in [[Jman.ini]] have our own extended syntax to handle colors, borders, etc. There are no setter methods to handle the extended syntax. This is just a public interface to the [[parm]] hashtable. <>= public static void setParm(String key, String value) { if (loaded == false) loadParms(); props.put(key,value); } @ \subsubsection{method getParmInteger} The [[getParmInteger]] calls getParm to look up the value and parses out an int. If the key is not found a hardcoded default value is returned Converts the return value to an integer. <>= public static int getParmInteger(String key) { return(Integer.parseInt(getParm(key))); } @ \subsubsection{method initDefaults} The [[initDefault]] hardcodes default values for initialization constants. If the key is not found in Jman.ini we provide a default value here. <>= private static void initDefaults() { props.put("version","Jman.ini not found"); props.put("SplashImage","blueaxiom.jpg"); props.put("SplashWait","2000"); props.put("Debug","on"); props.put("CatchLog","on"); } @ \subsubsection{method main Parm} This is unit test code for the Parm class. Note that this is not included in the generated code. <>= public static void main(String[] args) { loadParms(); setParm("testColor","[Color 123456]"); System.err.println(getColor("testColor")); setParm("testColor","[Color FFFFFF]"); System.err.println(getColor("testColor")); setParm("testBorder","[Border MATTE 5 5 5 5]"); System.err.println(getBorder("testBorder")); System.err.println("MainPanel.defaultFont"); System.err.println(getFont("MainPanel.defaultFont")); for(Enumeration e = props.keys(); e.hasMoreElements();) { String next = (String)e.nextElement(); System.err.println((String)next+"="+props.get(next)); } setParm("Debug","off"); System.err.println("Debug="+props.get("Debug")); setParm("Debug","on"); System.err.println("Debug="+props.get("Debug")); } @ \subsubsection{class Parm} The [[Parm]] class manages initialization constants. This class is the interface to the file "Jman.ini". The file contains various constants used by the application. This class loads the Jman.ini constants into a Properties hashtable. If a required constant is not specified then a hardcoded default value is used instead. Hardcoded defaults exist here rather than in the corresponding classes to centralize the management of constants. <>= class Parm { <> <> <> <> <> <> <> <> <> <> <> <> <> <> } @ \subsection{class Catch} \subsubsection{method log} <>= /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param e is the exception that was thrown */ public static void log(String classAndMethod, String data, ActionEvent e) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); if (e != null) { logFile.println( "Catch:"+classAndMethod+" "+data+" "+e.getActionCommand()); } else logFile.println("Catch:"+classAndMethod+" "+data); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("CatchTrace").equals("on")) { if (e != null) { System.err.println("Catch:"+classAndMethod+" "+data+ " "+e.getActionCommand()); } else System.err.println("Catch:"+classAndMethod+" "+data); } } /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param e is the exception that was thrown */ public static void log(String classAndMethod, String data, Exception e) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); if (e != null) { logFile.println("Catch:"+classAndMethod+" "+data+" "+e.getMessage()); e.printStackTrace(logFile); } else logFile.println("Catch:"+classAndMethod+" "+data); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("CatchTrace").equals("on")) { if (e != null) { System.err.println("Catch:"+classAndMethod+" "+data+ " "+e.getMessage()); } else System.err.println("Catch:"+classAndMethod+" "+data); } } /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param data2 is a String of informational values * @param e is the exception that was thrown */ public static void log(String classAndMethod, String data, String data2) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); logFile.println("Catch:"+classAndMethod+" "+data+" "+data2); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("CatchTrace").equals("on")) System.err.println("Catch:"+classAndMethod+" "+data+" "+data2); } /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param data2 is a String of informational values * @param e is the exception that was thrown */ public static void log(String classAndMethod, int data2, String data) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); logFile.println("Catch:"+classAndMethod+" "+data); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("CatchTrace").equals("on")) System.err.println("Catch:"+classAndMethod+" "+data); } /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param e is the exception that was thrown */ public static void log(String classAndMethod, String data) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); logFile.println("Catch:"+classAndMethod+" "+data); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("CatchTrace").equals("on")) System.err.println("Catch:"+classAndMethod+" "+data); } /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is an array of String of tokens * @param e is the exception that was thrown */ public static void log(String classAndMethod, String[] data) { if (Parm.getParm("CatchLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("CatchFile"))); for(int i=0; i>= /** if CatchLog=on in Jman.ini then write log * if CatchTrace=on in Jman.ini then trace to stdout * @param classAndMethod is a string containing both names * @param data is a String of informational values * @param e is the exception that was thrown */ public static void error(String classAndMethod, String data) { if (Parm.getParm("ErrorLog").equals("on")) try { if (logFile == null) logFile = new PrintWriter( new FileOutputStream(Parm.getParm("ErrorFile"))); logFile.println("ERROR:"+classAndMethod+" "+data); logFile.flush(); } catch(Exception ioe) { ioe.printStackTrace(System.err); } if (Parm.getParm("ErrorTrace").equals("on")) System.err.println("ERROR:"+classAndMethod+" "+data); } @ \subsubsection{method main Catch} Catch unit test code. Note that this is not included in the generated sources. <>= public static void main(String[] args) { Catch.log("Catch:main",null,new Exception("main unit test1")); Catch.log("Catch:main","unit test 2",new Exception("main unit test2")); } @ \subsubsection{class Catch} <>= class Catch { private static PrintWriter logFile; <> <> } @ \subsection{class Splash} \subsubsection{method splash} The splash method takes the name of an [[image]] to display (a String), creates a window in the center of the display and leaves it there until the [[dwell]] time (an int) runs out. The image is assumed to be displayable by Java (likely a [[.jpg]] file). If the image is given as a null or a zero length string then the image and the dwell time are gotten from the .ini file. <>= public void splash(String image, int dwell) { if (image.length() > 0) { Catch.log("Splash:splash","start",image); splashImage = new ImageIcon(image); splashTime = dwell; } else { Catch.log("Splash:splash","start",Parm.getParm("SplashImage")); splashImage = new ImageIcon(Parm.getParm("SplashImage")); splashTime = Parm.getParmInteger("SplashWait"); } JLabel splashLabel = new JLabel(splashImage); splashWindow = new JWindow() { public void setVisible(boolean visible) { if (visible) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); setSize(splashImage.getIconWidth(), splashImage.getIconHeight()); setLocation((dim.width - splashImage.getIconWidth())/2, (dim.height - splashImage.getIconHeight())/2); } super.setVisible(visible); } }; splashWindow.getContentPane().add(splashLabel); splashWindow.validate(); splashWindow.setVisible(true); splashTicker=new javax.swing.Timer(splashTime,this); splashTicker.setRepeats(false); splashTicker.addActionListener(this); splashTicker.start(); } @ The Splash class reads in a splash image (named in the [[Jman.ini]] file) and displays it on the screen for a few moments. When the timer pops the [[actionPerformed]] message is called and it sets the [[done]] boolean to true. If you wish to know when the image is gone call [[running]] which will return true if the image is still visible, false otherwise. The image to display is given by the [[SplashImage]] entry in [[Jman.ini]]. The time to display the image is given by the [[SplashWait]] entry. <>= class Splash implements ActionListener { ImageIcon splashImage; javax.swing.Timer splashTicker; String splashFile; JWindow splashWindow; Boolean done = false; int splashTime = 3000; public void actionPerformed(ActionEvent e) { splashWindow.setVisible(false); splashTicker.stop(); splashWindow.dispose(); done = true; } <> public Boolean running() { if (! done) return true; else return false; } } @ \subsection{class Jman} \subsubsection{method listen} <>= public static void listen(String args[]) { Ear master; String m,n,p,u,h; long d=60000; m =""; n =""; p =""; u ="daly"; h ="127.0.0.1"; System.err.println("listen"); for(int i = 0; i < args.length; i++) { if (args[i].equals("-mail")) m =args[i+1]; if (args[i].equals("-nomail")) n =args[i+1]; if (args[i].equals("-pass")) p = args[i+1]; if (args[i].equals("-user")) u = args[i+1]; if (args[i].equals("-host")) h = args[i+1]; if (args[i].equals("-delay")) d = new Long(args[i+1]).longValue(); if (args[i].equals("-help")) { System.err.println("\nEar -- Ear for Java"); System.err.println("Mouse click -- see headers"); System.err.println("Control-mouse click --"+ " change parameters/quit"); System.err.println(" -mail filename "); System.err.println(" -nomail filename "); System.err.println(" -user username"); System.err.println(" -pass password"); System.err.println(" -host mailhost"); System.err.println(" -delay milliseconds"); System.err.println(" --help\n\n"); System.exit(0); } } System.err.println("MailResource"); MailResource res=new PopServer(d, u, p, h); System.err.println("ear"); master = new Ear("Ear",m,n,res); System.err.println("dim"); Dimension dim=Toolkit.getDefaultToolkit().getScreenSize(); System.err.println("master"); master.setLocation(dim.width-70, 65); } @ \subsubsection{method main} <>= public static void main(String args[]) {// splash blueaxiom.jpg if (args[0].startsWith("splash")) { Splash Splash = new Splash(); if (args[1].length() > 0) Splash.splash(args[1],3000); else Splash.splash("blueaxiom.jpg",3000); while (Splash.running()); System.err.println("splash done"); } // listen if (args[0].startsWith("listen")) { System.err.println("marg"); String marg[] = {"-user","daly","-pass","pass1wor","-host","pop.idsi.net"}; System.err.println("calling listen"); listen(marg); } // testcase if (args[0].startsWith("testcase")) { testStep0 test = new testStep0(); test.readTestCase("testfile"); } // accept 14000 if (args[0].startsWith("accept")) { try { ServerSocket serversock = new ServerSocket(Integer.parseInt(args[1])); System.out.println(args[1]); Socket sock = serversock.accept(); System.err.println("accepted"); InputStream is = sock.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); testStep0 ts = new testStep0(); while(true) { String line = in.readLine(); ts.print(ts.eval(ts.readTestFile(line))); } } catch(Exception e) { } } } @ \subsection{class Display} [[Display]] is a general purpose java object that we can drive from a socket. The basic idea is that this object implements a set of commands that can be used to construct and manipulate objects, usually swing objects. The [[Display]] object maintains a hash table that contains the objects it knows about. The key is a user-supplied string. So the general game is that the user supplies a list which consists of an object name used as a hash table key and a method name which will be invoked on the result of the hash table lookup. The rest of the list are the arguments to the method. \subsubsection{constructor Display} The constructor does nothing except initialize the class variables. Notice that there can be many [[Display]] objects and thus many windows. <>= public Display() { widgets = new Hashtable(); widgettype = new Hashtable(); // JButton jbutton = null; // JFrame jframe = null; // JPanel jpanel = null; } @ \subsubsection{method tokenize} The tokenize method will break the list into an array of strings. The expected input is of the form: \begin{verbatim} "(hashname method arg1 arg2 ...)" \end{verbatim} which will result in \begin{verbatim} tokens[0] = "(" tokens[1] = "hashname" tokens[2] = "method" tokens[3] = "arg1" tokens[4] = "arg2" ... tokens[n] = ")" \end{verbatim} The first token is the hash table key of an object in the [[widgets]] hashtable. What the hashkey means depends on a couple factors. If the object is new and the method normally creates an object then the object is added to the hash table under the hashkey. If the object is old and the method normally creates an object then the object replaces the previous object in the hashtable. If the object is new and the method expects an existing object then the method returns [[failed]]. If the object is old and the method expects an existing object then the object is used to perform the method. The second token is the method name. It names a method on [[Display]] which currently must be predefined but it should be possible to dynamically create new methods. The third token depends on the method. Sometimes it is the hashkey of an existing object, such as when you want to add a button to an existing object. Other times it is used to disambiguate the type of the object fetched from the hashtable as Java isn't clever enough to figure this out. Tokens that refer to objects where they are required by the method call use the hashkey of the object. Notice that the parentheses are preserved in the tokens in case one of the arguments to a method is itself a list. The [[tokenize]] function treats everything as strings. Numbers or special handling have to be done by the various other methods. <>= public String[] tokenize(String line) { StringTokenizer stk = new StringTokenizer(line,"() \t\n\r\f",true); Vector tokenvec = new Vector(); String[] tokens = null; String token = null; try { while(stk.hasMoreTokens()) { token = stk.nextToken(); Boolean keep=false; for(int i=0; i>= JButton jbutton = null; @ <