changeset 41:2475c99fbb8c

Update graph bounds when moving vertex.
author Mikhail Kryshen <mikhail@kryshen.net>
date Sat, 10 Jul 2010 07:28:19 +0400
parents a96dfbfd6d4e
children d3e3c43df1cd
files src/kryshen/indyvon/graph.clj
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/kryshen/indyvon/graph.clj	Sat Jul 10 03:04:47 2010 +0400
+++ b/src/kryshen/indyvon/graph.clj	Sat Jul 10 07:28:19 2010 +0400
@@ -29,13 +29,13 @@
       (.getLeftBound v)
       (.getTopBound v))))
 
-(defn- draw-vertices! [^Graph graph x y]
-  (doseq [v (.vertices graph)]
+(defn- draw-vertices! [^GraphLayout layout x y]
+  (doseq [v (.vertices (.getGraph layout))]
     (draw-anchored! v :center :center (+ x (.getX v)) (+ y (.getY v)))))
 
 (defn- draw-movable-vertices!
-  [^Graph graph x y dragged fix-x fix-y]
-  (doseq [v (.vertices graph)]
+  [^GraphLayout layout x y dragged fix-x fix-y]
+  (doseq [v (.vertices (.getGraph layout))]
     (let [x (+ x (.getX v))
           y (+ y (.getY v))
           anchor (anchor v :center :center)
@@ -62,15 +62,16 @@
                (let [dx (- x @fix-x)
                      dy (- y @fix-y)]
                  (.layoutLocation v (+ vx dx) (+ vy dy))
+                 (.updateBounds layout)
                  (*update*)
                  (ref-set fix-x x)
                  (ref-set fix-y y)))))))))))
 
-(defn- draw-edges! [^Graph graph x y]
+(defn- draw-edges! [^GraphLayout layout x y]
   ;; TODO: extend Layer on Edge2D and draw like vertices.
   (.translate *graphics* x y)
   (let [path (Path2D$Double.)]
-  (doseq [^Edge2D e (.edges graph)]
+  (doseq [^Edge2D e (.edges (.getGraph layout))]
     (.getPath e path)
     (.draw *graphics* path)))
   (.translate *graphics* (- x) (- y)))
@@ -87,12 +88,11 @@
         (render! [layer]
            (let [bounds (.getBounds layout)
                  x (- (.getX bounds))
-                 y (- (.getY bounds))
-                 graph (.getGraph layout)]
-             (draw-edges! graph x y)
+                 y (- (.getY bounds))]
+             (draw-edges! layout x y)
              (if movable
-               (draw-movable-vertices! graph x y dragged fix-x fix-y)
-               (draw-vertices! graph x y))))
+               (draw-movable-vertices! layout x y dragged fix-x fix-y)
+               (draw-vertices! layout x y))))
         (size [layer]
            (let [bounds (.getBounds layout)]
              (Size. (.getWidth bounds) (.getHeight bounds))))