Skip to content

Instantly share code, notes, and snippets.

@mtcomb
Created June 24, 2014 18:04
Show Gist options
  • Save mtcomb/93b45873336369d08fba to your computer and use it in GitHub Desktop.
Save mtcomb/93b45873336369d08fba to your computer and use it in GitHub Desktop.
; http://stackoverflow.com/questions/3651494/jfilechooser-with-confirmation-dialog
; in Clojure
(defn chooser []
(proxy [javax.swing.JFileChooser] []
(approveSelection []
(let [f (proxy-super getSelectedFile)]
(if (and (.exists f)
(= (.getDialogType this)
javax.swing.JFileChooser/SAVE_DIALOG))
(do
(let [result (javax.swing.JOptionPane/showConfirmDialog
this "The file exists, overwrite?" "Existing file"
javax.swing.JOptionPane/YES_NO_CANCEL_OPTION)]
(condp = result
javax.swing.JOptionPane/YES_OPTION (proxy-super approveSelection)
javax.swing.JOptionPane/NO_OPTION nil
javax.swing.JOptionPane/CLOSED_OPTION nil
javax.swing.JOptionPane/CANCEL_OPTION (.cancelSelection this)
nil)))
(proxy-super approveSelection))
))))
(.showOpenDialog (chooser) nil)
(.showSaveDialog (chooser) nil)
(let [c (chooser)]
(if (== (.showSaveDialog c nil) 0)
(.getSelectedFile c))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment