[snow-cvs] r52 - in trunk: . examples/swixml src/lisp/snow

Alessio Stalla astalla at common-lisp.net
Mon Feb 8 21:21:26 UTC 2010


Author: astalla
Date: Mon Feb  8 16:21:26 2010
New Revision: 52

Log:
changelog for 0.3
fixed non-propagation of *gui-backend* and *presentation-model* to GUI thread.
fixed helloworld/j example.


Added:
   trunk/examples/swixml/HelloWorld.java
   trunk/examples/swixml/helloworld_j.lisp
Modified:
   trunk/changelog
   trunk/src/lisp/snow/snow.lisp
   trunk/src/lisp/snow/swing.lisp

Modified: trunk/changelog
==============================================================================
--- trunk/changelog	(original)
+++ trunk/changelog	Mon Feb  8 16:21:26 2010
@@ -1,3 +1,28 @@
+Snow version 0.3 (..........)
+
+This is an alpha release, focused on refactoring and simplifying the core
+engine, providing better Java integration and cleaner API, and supporting
+more widgets and properties.
+
+Main improvements:
+- Refactoring and simplification of core Snow. It's no longer possible to
+  theoretically change the GUI backend at runtime, among other things.
+  This was impossible anyway because macros would have needed to be changed too
+  for different enough backends (e.g. SWT, because it requires a component to
+  be added to its container at creation time and not later, for example).
+  When SWT will be supported, it'll have to be enabled at read-time
+  with *features*. This makes Snow simpler and more efficient.
+- :id foo expands to (setf foo self) for all components if foo is a declared
+  lexical variable.
+- Better Java integration. The snow.Snow API has been made simpler and richer.
+  Introduced the concept of a "backing bean" for the GUI: if provided from
+  Java, this bean will have all the widget with an :id injected into the
+  corresponding property, if any, and event callbacks specified as strings
+  (as opposed to function designators) will be delegated to bean methods with
+  the correct signature.
+- A few more event listeners are now supported, including mouse events on
+  arbitrary components.
+	
 Snow version 0.2 (2009-11-28)
 
 This is an alpha release, focused on stabilizing the core engine, providing

Added: trunk/examples/swixml/HelloWorld.java
==============================================================================
--- (empty file)
+++ trunk/examples/swixml/HelloWorld.java	Mon Feb  8 16:21:26 2010
@@ -0,0 +1,54 @@
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+
+import snow.*;
+
+public class HelloWorld {
+    /** submit counter */
+    private int clicks;
+    
+    /** JTextField member gets instantiated through Swixml (look for id="tf" in xml descriptor) */
+    private JTextField tf;
+    
+    /** Jlabel to display number of button clicks */
+    private JLabel cnt;
+
+    /**
+     * Event handler.
+     * Appends a '#' to the textfields content and increments the number of
+     * clicks displayed by the label.
+     */   
+    public void submit(ActionEvent e) {
+	tf.setText(tf.getText() + '#');
+	cnt.setText(String.valueOf( ++clicks ));
+    }
+
+    /** Renders UI at construction */
+    private HelloWorld() throws Exception {
+	Snowlet s = Snow.getInterpretedSnowlet(getClass().getResource("helloworld_j.lisp"));
+	s.setBackingBean(this);
+	s.eval();
+    }
+
+    /** Makes the class bootable */
+    public static void main( String[] args ) throws Exception {
+	new HelloWorld();
+    }
+
+    public JTextField getTf() {
+	return tf;
+    }
+
+    public void setTf(JTextField tf) {
+	this.tf = tf;
+    }
+
+    public JLabel getCnt() {
+	return cnt;
+    }
+
+    public void setCnt(JLabel cnt) {
+	this.cnt = cnt;
+    }
+
+}

Added: trunk/examples/swixml/helloworld_j.lisp
==============================================================================
--- (empty file)
+++ trunk/examples/swixml/helloworld_j.lisp	Mon Feb  8 16:21:26 2010
@@ -0,0 +1,45 @@
+(in-package :snow-user)
+(in-readtable snow:syntax)
+
+(with-gui ()
+  (frame (:size #C(640 280) :title "Hello Snow World" :on-close :exit)
+    (panel (:layout "grow, wrap")
+      (label :text "Hello World!" :font (font "Georgia" 12 :bold)
+	     :foreground :blue) ;;labelfor="tf"
+      (text-field :id tf :text "Snow");;columns="20"
+      (button :text "Click Here" :on-action "submit"))
+    (panel (:layout "dock south")
+      (label :text "Clicks:" :font (font "Georgia" 36 :bold))
+      (label :id cnt :font (font "Georgia" 36 :bold)))
+    (show self)))
+
+#||
+The original example used the SwiXml idiom of coding a Java class to handle
+the events; an instance of this class gets injected the components with an
+ID into its JavaBean properties.
+The Snow version does not rely on a Java class; instead it handles events in
+Lisp and uses data binding to update the GUI. It is of course possible to
+handle the events in Java, but Snow does not currently support automatic
+injection of widgets into the properties of a Java object.
+||#
+
+#|| Original example:
+
+<?xml version="1.0" encoding="UTF-8"?>
+<frame size="640,280" title="Hello SWIXML World" defaultCloseOperation="JFrame.EXIT_ON_CLOSE">
+
+  <panel constraints="BorderLayout.CENTER">
+    <label labelfor="tf" font="Georgia-BOLD-12" foreground="blue" text="Hello World!"/>
+    <textfield id="tf" columns="20" Text="Swixml"/>
+    <button text="Click Here" action="submit"/>
+  </panel>
+
+  <panel constraints="BorderLayout.SOUTH">
+    <label font="Georgia-BOLD-36" text="Clicks:"/>
+
+    <label font="Georgia-BOLD-36" id="cnt"/>
+  </panel>
+
+</frame>
+
+||#

Modified: trunk/src/lisp/snow/snow.lisp
==============================================================================
--- trunk/src/lisp/snow/snow.lisp	(original)
+++ trunk/src/lisp/snow/snow.lisp	Mon Feb  8 16:21:26 2010
@@ -35,7 +35,8 @@
 
 (defmacro with-snow-dynamic-environment (&body body)
   (with-unique-names (package-var terminal-io-var
-		      standard-input-var standard-output-var error-output-var)
+		      standard-input-var standard-output-var error-output-var
+		      backing-bean-var presentation-model-var)
     `(if *dynamic-environment*
 	 (with-dynamic-environment (*dynamic-environment*)
 	   , at body)
@@ -43,14 +44,18 @@
 	       (,terminal-io-var *terminal-io*)
 	       (,standard-input-var *standard-input*)
 	       (,standard-output-var *standard-output*)
-	       (,error-output-var *error-output*)) ;;Etc...
+	       (,error-output-var *error-output*)
+	       (,backing-bean-var *backing-bean*)
+	       (,presentation-model-var *presentation-model*)) ;;Etc...
        (dynamic-wind
 	(let ((*package* ,package-var)
 	      (*debugger-hook* *graphical-debugger-hook*)
 	      (*terminal-io* ,terminal-io-var)
 	      (*standard-input* ,standard-input-var)
 	      (*standard-output* ,standard-output-var)
-	      (*error-output* ,error-output-var))
+	      (*error-output* ,error-output-var)
+	      (*backing-bean* ,backing-bean-var)
+	      (*presentation-model* ,presentation-model-var))
 	  (proceed
 	   (let ((*dynamic-environment* (capture-dynamic-environment)))
 	     (with-dynamic-environment (*dynamic-environment*)

Modified: trunk/src/lisp/snow/swing.lisp
==============================================================================
--- trunk/src/lisp/snow/swing.lisp	(original)
+++ trunk/src/lisp/snow/swing.lisp	Mon Feb  8 16:21:26 2010
@@ -56,7 +56,7 @@
        (error "No backing bean specified while action listener is a jmethod: ~A~%" obj))
      (make-action-listener
       (let ((bb *backing-bean*))
-	#'(lambda (evt) (jcall obj bb evt)))))
+	#'(lambda () (jcall obj bb *event*)))))
     (t obj))) ;This allows to use a native Java action listener
 
 (defun make-layout-manager (widget layout &rest args)




More information about the snow-cvs mailing list