 (ns slide-explorer.display
-  (:import (javax.swing AbstractAction JComponent JFrame JLabel KeyStroke)
-           (java.awt Canvas Color Graphics Graphics2D RenderingHints Window)
+  (:import (javax.swing AbstractAction JComponent JFrame JPanel JLabel KeyStroke
+                        SwingUtilities)
+           (java.awt Color Graphics Graphics2D RenderingHints Window)
            (java.awt.event ComponentAdapter KeyAdapter KeyEvent MouseAdapter
                            WindowAdapter)
            (java.awt.image BufferedImage WritableRaster)

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



  (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 [panel reference]
  (add-watch reference "display"
    (fn [_ _ _ _]
      (.repaint panel))))

(defn main-panel [screen-state available-tiles]
  (doto
    (proxy [JPanel] []
      (paintComponent [^Graphics graphics]
                      (proxy-super paintComponent graphics)
                      (paint-screen graphics screen-state available-tiles)))
    (.setBackground Color/BLACK)
    ))
    
(defn main-frame []
  (doto (JFrame. "Slide Explorer II")
