         (.drawImage g image
                     x y nil)))))
 
-(defn paint-screen [canvas screen-state available-tiles]
-  (let [g (.getGraphics canvas)
-        original-transform (.getTransform g)]
-    (doto g
+(defn paint-screen [graphics screen-state available-tiles]
+  (let [original-transform (.getTransform graphics)]
+    (doto graphics
       (.translate (+ (:x @screen-state) (/ (:width @screen-state) 2))
                   (+ (:y @screen-state) (/ (:height @screen-state) 2)))
       (.rotate @angle)

  (bind-window-key window "ADD" #(swap! zoom-atom update-in [:zoom] inc))
  (bind-window-key window "SUBTRACT" #(swap! zoom-atom update-in [:zoom] dec)))
  
(defn display-follow [canvas reference]
  (add-watch reference "display"
    (fn [_ _ _ _]
      (.repaint canvas))))

(defn main-canvas [screen-state available-tiles]
  (doto
    (proxy [Canvas] []
      (paint [^Graphics g] (paint-screen this screen-state available-tiles)))
    (.setBackground Color/BLACK)))
    
(defn main-frame []
  (doto (JFrame. "Slide Explorer II")

(defn show []
  (let [screen-state (atom (sorted-map :x 0 :y 0 :z 0 :zoom 0))
        available-tiles (agent {})
        panel (main-panel screen-state available-tiles)
        frame (main-frame)]
    (def at available-tiles)
    (def ss screen-state)
    (def f frame)
    (def pnl panel)
    (.add (.getContentPane frame) panel)
    (setup-fullscreen frame)
    (handle-drags panel screen-state)
    (handle-wheel panel screen-state)
    (handle-resize panel screen-state)
    (handle-zoom frame screen-state)
    (display-follow panel screen-state)
    (display-follow panel available-tiles)
    (display-follow panel angle)
    frame))


