 
 ;; collection files
 
-(defn create-default-path []
-  (str (System/getProperty "user.name") ".mmdb.txt"))
-
-(defn new-collection []
-  (File. (create-default-path)))
-
-(defn read-collection-list []
-  (read-value-from-prefs prefs "collection-files"))
+(defn read-collection-map []
+  (or (read-value-from-prefs prefs "collection-files")
+      (let [name (System/getProperty "user.name")]
+        {name (.getAbsolutePath (File. (str name ".mmdb.txt")))})))
+
+(defn save-collection-map [collection-map]
+  (write-value-to-prefs prefs "collection-files" collection-map))
 
 (defn get-current-data-and-settings []
   (let [table (@browser :table)


(defn start-browser []
  (load-mm)
  (reset! settings-window (create-settings-window))
  (reset! browser (create-browser))
  (reset! headings tags)
  (.setModel (:table @browser) (create-table-model tags))
  (update-all-columns (.getModel (get-in @settings-window [:columns :table])))
  (add-location "/Users/arthur/qqqq")
  (.show (@browser :frame))
  browser)

       (->> @settings-window :locations :table .getModel .getDataVector
            seq (map seq) flatten)
     :sorted-column
       (when-let [sort-key (->> table .getRowSorter .getSortKeys seq first)]
         {:order ({SortOrder/ASCENDING 1 SortOrder/DESCENDING -1}
                   (.getSortOrder sort-key))
          :model-column (.getColumnName model (.getColumn sort-key))})
     }))

(defn apply-data-and-settings [settings]
  (let [table (@browser :table)
        model (.getModel table)
        {:keys [browser-model-data
                browser-model-headings
                window-size display-columns
                locations sorted-column]} settings]
    (.setDataVector model
      (Vector. (map #(Vector. %) (:browser-model-data settings)))
      (Vector. browser-model-headings))
    ))

(defn get-current-collection-file []
   (->> @browser :collection-menu
               .getSelectedItem (get @collections)))

(defn save-current-data-and-settings []
    (with-open [pr (PrintWriter. (get-current-collection-file))]
      (write-json (get-current-data-and-settings) pr)))

(defn load-data-and-settings [name]
  (let [f (get @collections name)]
    (apply-data-and-settings (read-json (slurp f))))
    (.setSelectedItem (@browser :collection-menu) name))

(defn update-collection-menu []
  (let [menu (@browser :collection-menu)
        names (sort (keys @collections))]
    (.removeAllItems menu)
    (dorun (map #(.addItem menu %) names))
    (.addItem menu "New...")
    (.addItem menu "Load...")))

;; windows

