(in-package :snow)

(defmodel my-model ()
  ((a :accessor aaa :initform (c-in "4"))
   (b :accessor bbb :initform (c? (concatenate 'string (aaa self) "2")))))

(defvar *object* (new "snow.example.SnowExample"))
(defvar *variable* (make-var "42"))
(defvar *cells-object* (make-instance 'my-model))

(let ((myframe
       (frame (:id frame-id :title "Sample JFrame" :visible-p t)
	 (tree :model (make-tree-model '(1 2 (c (a b)) 3)))
         (button :text "push me"
		 :on-action (lambda (event)
			      (princ "Thanks for pushing me! ")
			      (format t "My parent is ~A~%" frame-id)
			      (finish-output)))
	 (scroll (:layout "grow")
	   (list-widget :model (make-list-model '(1 2 (c (a b)) 3))
			:prototype-cell-value "abcdefghijklmnopq"))
	 (panel (:layout-manager :border :layout "wrap")
	   (button :text "borderlayout - center")
	   (button :text "borderlayout - east"
		   :layout (jfield "java.awt.BorderLayout" "EAST")))
	 (scroll ()
	   (panel ()
	     (label :binding (make-bean-binding *object* "property1"))
	     (label :binding (make-cells-binding (c? (aaa *cells-object*))))
	     (label :binding (make-cells-binding (c? (bbb *cells-object*))))
	     (label :binding (make-simple-binding *variable*))
	     (button :text "another one" :layout "wrap")
	     (text-field :binding (make-bean-binding *object* "property1")
			 :layout "growx")
	     (button :text "Test!"
		     :layout "wrap"
		     :on-action (lambda (event)
				  (setf (jproperty-value *object* "property1")
					"Test!")
				  (setf (var *variable*) "Test var")
				  (setf (aaa *cells-object*) "Test cell"))))))))
  (pack myframe))

(let ((fr (frame (:title "pippo" :visible-p t)
	    (panel (:layout "wrap")
	      (button :text "ciao" :enabled nil)
	      (button :text "mondo" :enabled 42
		      :on-action (lambda (event)
				   (print "Hello, world!")
				   (print event)))
	      (text-field :binding (make-bean-binding *object* "property1"))
	      (text-field :binding
			  (make-cells-binding (c? (aaa *cells-object*))
					      #'(lambda (x)
						  (setf (aaa *cells-object*) x))))
	      (text-field :binding (make-simple-binding *variable*)
			  :layout "wrap")
	      (label :text "haha")
	      (panel (:layout-manager :mig :layout "grow")
		(button :text "Test Location" :location #(30 30)))
	      (label :text "hihi")))))
  (let ((lbl1 (label :text "a label"))
	(lbl2 (label :text "another")))
    (add-child lbl1 fr "growx")
    (add-child lbl2 fr "wrap"))
  (pack fr))