Embedding a file chooser in another panel

37 views
Skip to first unread message

James Elliott

unread,
Jun 1, 2017, 4:44:07 PM6/1/17
to seesaw-clj
I am building an interface where I want to let a user choose something from a JTree that is going to be saved into a file, so I want a composite window in which a JFileChooser is simply a component, rather to have it present its own freestanding window.

I was able to achieve that, but I had to directly reference some internals in seesaw.chooser, and copy out some of the code from seesaw.chooser/show-file-chooser. It would be nice to have a supported and cleaner way to achieve this. I haven’t added the tree creation code yet, but here is what I had to do to get the embedded file chooser working:

(defn show-cache-creation-dialog
  "Presents an interface in which the user can choose which playlist
  to cache and specify the destination file."
  [player slot]
  (let [root                  (seesaw/frame :title "Create Metadata Cache"
                                            :on-close :dispose)
        ^JFileChooser chooser (@#'chooser/configure-file-chooser (JFileChooser.)
                               {:all-files? false
                                :filters    [["BeatLinkTrigger metadata cache files" ["bltm"]]]})
        panel (mig/mig-panel :items [[(seesaw/label :text "Tree goes here, la la...") "wrap"]
                                     [chooser]])]
    (when-let [[file-filter _] (seq (.getChoosableFileFilters chooser))]
      (.setFileFilter chooser file-filter))
    (.setDialogType chooser JFileChooser/SAVE_DIALOG)
    (seesaw/listen chooser :action-performed
                   (fn [action]
                     (when (= (.getActionCommand action) JFileChooser/APPROVE_SELECTION)
                       (@#'chooser/remember-chooser-dir chooser)
                       (when-let [file (util/confirm-overwrite-file (.getSelectedFile chooser) "bltm" nil)]
                         (seesaw/invoke-later (create-metadata-cache player slot file nil)))) ; TODO: add playlist
                     (.dispose root)))
    (seesaw/config! root :content panel)
    (seesaw/pack! root)
    (.setLocationRelativeTo root nil)
    (seesaw/show! root)))

 

Does it seem worth adding something to seesaw/chooser to make this easier?

Cheers,

  -James
Reply all
Reply to author
Forward
0 new messages