 (defn- show-some-picture []
   (let [wnd (GWindow.)
 	scn (GScene. wnd)
-	frm (JFrame.)]
-;    (.setWorldExtent scn 0.0 0.0 100.0 100.0)
-    (.startInteraction wnd (move-interaction))
-    (.setLayout frm (BorderLayout.))
-    (-> frm .getContentPane (.add (.getCanvas wnd) BorderLayout/CENTER))
-    (.setSize frm 300 300)
+	frm (JFrame. "Main Frame")]
+    (doto scn
+      (.setWorldExtent 0.0 0.0 100.0 100.0)
+      (.shouldZoomOnResize false)
+      (.shouldWorldExtentFitViewport false))
     (let [x (add-node scn 100 100)
 	  y (add-node scn 50 50)
-	  z (add-node scn 75 23)]
-      (connect-nodes scn x y)
-      (connect-nodes scn x z)
-      (connect-nodes scn y z))
-    (.setVisible frm true)))
+	  z (add-node scn 0 0)]
+      (connect-nodes scn z y)
+      (connect-nodes scn y x))
+    (doto frm
+      (.setLayout (BorderLayout.))
+      (.. getContentPane (add (.getCanvas wnd) BorderLayout/CENTER))
+      (.pack)
+      (.setSize (Dimension. 500 500))
+      (.setVisible true))
+    (doto wnd
+      (.startInteraction (move-interaction)))
+    scn))


(defn height-of-lower-neighbors [node]
  (let [lowers (lower-neighbors node)]
    (if (not lowers)
      nil
      (reduce min (map (fn [conn] ((start-of-connection conn) 1)) lowers)))))

(defn height-of-upper-neighbors [node]
  (let [uppers (upper-neighbors node)]
    (if (not uppers)
      nil
      (reduce max (map (fn [node] ((end-of-connection node) 1)) uppers)))))

(defn move-node-by [node dx dy] ; race condition when move nodes too fast?
  (let [[x y] (position node)
	max-y (height-of-lower-neighbors node)
	min-y (height-of-upper-neighbors node)
	dy    (if max-y (min dy (- max-y y)) dy)
	dy    (if min-y (max dy (- min-y y)) dy)
	[new-x new-y] [(+ x dx) (+ y dy)]]
    (doseq [segment (.getSegments node)]
      (.translate segment dx dy))
    (doseq [c (upper-neighbors node)]
      (let [c (.getSegment c)
	    c1 (aget (.getX c) 0)
	    c2 (aget (.getY c) 0)
	    d1 (aget (.getX c) 1)
	    d2 (aget (.getY c) 1)]
	(.setGeometry c (+ c1 dx) (+ c2 dy) d1 d2)))
    (doseq [c (lower-neighbors node)]
      (let [c (.getSegment c)
	    c1 (aget (.getX c) 0)
	    c2 (aget (.getY c) 0)
	    d1 (aget (.getX c) 1)
	    d2 (aget (.getY c) 1)]
	(.setGeometry c c1 c2 (+ d1 dx) (+ d2 dy))))
    (dosync
     (alter (.getUserData node) assoc :position [new-x new-y]))
    [new-x new-y]))

(defn move-node-to [node x y]

				   (when (node? thing)
				     (reset! interaction-obj thing)))
	   GWindow/BUTTON1_DRAG  (when @interaction-obj
				   (let [[x y] (device-to-world scn x y)]
				     (move-node-to @interaction-obj x y)
				     (.refresh scn)))
	   GWindow/BUTTON1_UP    (reset! interaction-obj nil)
	   nil)))))

