commit c3cff89897bb2d5b6bf277f905a7b33a70aef31e
parent d7c77a34fc8fea0dbc617485cc903bee7ef62303
Author: tomas <tomas@logand.com>
Date:   Sat, 31 Oct 2009 12:44:22 +0100
load kind of works + eof
Diffstat:
8 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/java.wl b/java.wl
@@ -415,12 +415,11 @@
       (finally (*Out 'close)
          (run P 1 '(*Out)) ) ) ) # TODO
 
-(de load @
+(de load @ # finally?
    (while (args)
       (in (next)
-         (finally ()
-            (while (read)
-               (eval @ 1) ) ) ) ) )
+         (until (eof)
+            (eval (eval (read) 1) 1) ) ) ) )
 
 (de recur recurse (run (cdr recurse)))
 
diff --git a/swing2.l b/swing2.l
@@ -1,8 +1,6 @@
 # http://www.java2s.com/Code/Java/Language-Basics/InvokemethodthroughJavaReflectionAPI.htm
 
-(import javax.swing JFrame JButton JLabel)
-(import java.awt Container BorderLayout)
-(import java.awt.event ActionListener)
+(load "swing.l")
 
 (setq F (jnew JFrame "Command Test"))
 (setq B1 (jnew JButton "Tick"))
diff --git a/swing3.l b/swing3.l
@@ -1,5 +1,4 @@
-(import javax.swing JFrame)
-(import javax.swing JLabel)
+(load "swing.l")
 
 (setq F (jnew JFrame "HelloWorldSwing"))
 (setq L (jnew JLabel "Hello World"))
diff --git a/swing4.l b/swing4.l
@@ -1,6 +1,4 @@
-(import javax.swing JFrame JLabel JTextField JButton)
-(import java.awt.event ActionListener)
-(import java.awt Container BorderLayout)
+(load "swing.l")
 
 (setq W (jnew JFrame "Celsius Converter"))
 (setq L (jnew JTextField))
diff --git a/swing5.l b/swing5.l
@@ -1,6 +1,4 @@
-(import javax.swing JFrame JLabel JTextField JButton)
-(import java.awt.event ActionListener)
-(import java.awt GridLayout)
+(load "swing.l")
 
 (setq W (jnew JFrame "Celsius Converter"))
 (setq L (jnew JTextField))
diff --git a/swing6.l b/swing6.l
@@ -1,8 +1,13 @@
 # http://life.csu.edu.au/java-tut/uiswing/learn/example-1dot4/LunarPhases.java
 # http://life.csu.edu.au/java-tut/uiswing/learn/example-1dot4/images/image0.jpg
 
-(import javax.swing JFrame JPanel JLabel JComboBox BoxLayout BorderFactory ImageIcon)
-(import java.awt.event ActionListener)
+(load "swing.l")
+
+(println "@@@@@@@@@@@" I)
+(setq I ## TODO bug here?
+   #(fmap '((X) (cons X X)) '(0 1 2 3 4 5 6 7))
+   'fmap)
+(println "@@@@@@@@@@@" I)
 
 (setq I
    (fmap '((X) (cons X (jnew ImageIcon (pack "image" X ".jpg")))) '(0 1 2 3 4 5 6 7)) )
diff --git a/swing7.l b/swing7.l
@@ -0,0 +1,15 @@
+# http://stackoverflow.com/questions/233171/what-is-the-best-way-to-do-gui-in-clojure/1505404#1505404
+
+(load "swing.l")
+
+(setq F (jnew JFrame "Hello Swing")
+      D (jnew DefaultTableModel)
+      A (jnew JTable D)
+      S (jnew JScrollPane A) )
+
+(D 'setNumRows 30)
+(D 'setColumnCount 5)
+((F 'getContentPane) 'add S)
+(F 'setDefaultCloseOperation (jfield JFrame 'EXIT_ON_CLOSE))
+(F 'pack)
+(F 'setVisible true)
diff --git a/wl.java b/wl.java
@@ -1279,8 +1279,10 @@ class wl implements Runnable {
             return Z;
         }});
         fn("read", new Fn() {public Any fn(Any E) { // TODO
-            return read1(true);
+            Any Z = read1(true);
+            return Z == null ? NIL : Z;
         }});
+        fn("eof", new Fn() {public Any fn(Any E) {return eof() ? T : NIL;}});
     }
 
     class Exc extends RuntimeException {
@@ -1374,8 +1376,9 @@ class wl implements Runnable {
             while(null != (Z = read1(true))) eval(Z);
         } catch(FileNotFoundException e) {
             err(F, "File not found");
+        } finally {
+            In.val(I);
         }
-        In.val(I);
     }
 
     public static void main(String args[]) {