 	   nil)))))
 
 
+;;; draw nodes with coordinates and connections on a scene
+
+(defn draw-nodes-with-connections [scn node-coordinate-map node-connections]
+  (let [node-map (apply hash-map
+			(flatten (map (fn [[node [x y]]]
+					[node
+					 (add-node scn x y (str node))])
+				      node-coordinate-map)))]
+    (doseq [[node-1 node-2] node-connections]
+      (connect-nodes scn (node-map node-1) (node-map node-2)))
+    node-map))
+
+
 ;;; some testing
 
 (defn- show-some-picture []

			      (.setBackgroundColor (Color. 23 11 84)))
			    style))

(defn add-node [scn x y]
  (let [segment (GSegment.)
	object (proxy [GObject] []
		 (draw []
		   (let [[x y] (position this)]
		     (.setGeometryXy segment (Geometry/createCircle (double x) (double y) 10.0)))))
	style (GStyle.)]
    (doto segment
      (.setStyle *default-node-style*))
    (doto object
      (.addSegment segment)
      (.setUserData (ref {:type :node,
			  :position [x y]}))
      (.setName (str [x y])))
    (doto scn
      (.add object))
    object))

(def *default-line-style* (let [style (GStyle.)]
			    (doto style
			      (.setLineWidth 3.0))
			    style))

(defn connect-nodes [scn x y]
  (let [line (GSegment.)
	c       (proxy [GObject] []
		  (draw []
		    (let [[x1 y1] (position (lower-node this))
			  [x2 y2] (position (upper-node this))]
		      (.setGeometry line (double x1) (double y1) (double x2) (double y2)))))]
    (doto scn
      (.add c))
    (doto line
      (.setStyle *default-line-style*))
    (doto c
      (.addSegment line)
      (.toBack)
      (.setUserData (ref {:type :connection,
			  :lower x,
			  :upper y}))
      (.setName (str (.getName x) " -> " (.getName y))))
    (dosync
     (alter (.getUserData x) update-in [:upper] conj c)
     (alter (.getUserData y) update-in [:lower] conj c))))


;;; move nodes around

    (doto scn
      (.setWorldExtent 0.0 0.0 100.0 100.0)
      (.shouldZoomOnResize false)
      (.shouldWorldExtentFitViewport false)
      (draw-nodes-with-connections {:x [100 100], :y [50 50], :z [0 0]}
				   [[:z :y], [:y :x]]))
    (doto frm
      (.setLayout (BorderLayout.))
      (.. getContentPane (add (.getCanvas wnd) BorderLayout/CENTER))
