         [overtone.gui.control :only [synth-controller]]
         [seesaw core]
         [seesaw.color :only [color]]
-        [seesaw.graphics :only [style draw rounded-rect line]]
-        [seesaw.swingx :only [hyperlink]])
+        [seesaw.graphics :only [style update-style draw rounded-rect line]]
+        [seesaw.mig :only [mig-panel]])
   (:require [seesaw.bind :as bind]))
 
 (defn- make-initial-state [metro steps instruments init-vals]

      (let [x (* step dx)]
        (draw g (rounded-rect x 0 dx h) current-step-style)))
    (dotimes [r rows]
      (let [y (* r dy)]
        (draw g (line 0 y w y) grid-line-style)
        (dotimes [c cols]
          (let [x (* c dx)]
            (draw g (line x 0 x h) grid-line-style)
            (when (get-entry state r c)
              (draw g
                    (rounded-rect (+ x 2) (+ y 2) (- dx 3) (- dy 3) 3 3)
                    enabled-entry-style))))))))

(defn- on-grid-clicked [state e]
  (let [grid (to-widget e)
        x    (.getX e)
        y    (.getY e)
        rows (count (:rows state))
        cols (:steps state)
        c    (int (/ x (/ (width grid) cols)))
        r    (int (/ y (/ (height grid) rows)))
        new-state (toggle-entry state r c)]
    ; when they enable a cell, play the sample.
    (if (and (get-in new-state [:rows r :value c])
             (not (:playing? new-state)))
      ((get-in new-state [:rows r :inst])))
    (toggle-entry state r c)))

(defn- on-grid-drag [state e]
  (let [grid (to-widget e)
        x    (.getX e)
        y    (.getY e)
        rows (count (:rows state))
        cols (:steps state)
        c    (int (/ x (/ (width grid) cols)))
        r    (int (/ y (/ (height grid) rows)))]
    (set-entry state r c (not (.isShiftDown e)))))

(defn- step-grid [state-atom]
  (let [state @state-atom

                                        :separator
                                        controls-btn])
          grid         (step-grid state-atom)
          inst-panels  (map (partial inst-panel state-atom)
                            instruments)
          f (frame :title    "Sequencer"
                   :content  (border-panel
                               :border 5 :hgap 5 :vgap 5
                               :north control-pane
                               :west (grid-panel :columns 1
                                                 :items inst-panels)
                               :center grid)
                   :on-close :dispose)]

      (bind/bind bpm-spinner (bind/b-do [v] (metro :bpm v)))
      (bind/bind state-atom (bind/b-do [v] (repaint! grid)))

