File chooser and other common dialogs.
File chooser and other common dialogs.
(choose-color & args)
Choose a color with a color chooser dialog. The optional first argument is the parent component for the dialog. The rest of the args is a list of key/value pairs:
:color The initial selected color (see seesaw.color/to-color)
:title The dialog's title
Returns the selected color or nil if canceled.
See: http://download.oracle.com/javase/6/docs/api/javax/swing/JColorChooser.html
Choose a color with a color chooser dialog. The optional first argument is the parent component for the dialog. The rest of the args is a list of key/value pairs: :color The initial selected color (see seesaw.color/to-color) :title The dialog's title Returns the selected color or nil if canceled. See: http://download.oracle.com/javase/6/docs/api/javax/swing/JColorChooser.html
(choose-file & args)
Choose a file to open or save. The arguments can take two forms. First, with an initial parent component which will act as the parent of the dialog.
(choose-file dialog-parent ... options ...)
If the first arg is omitted, the desktop is used as the parent of the dialog:
(choose-file ... options ...)
Options can be one of:
:type The dialog type: :open, :save, or a custom string placed on the Ok button. Defaults to :open. :dir The initial working directory. If omitted, the previous directory chosen is remembered and used. :multi? If true, multi-selection is enabled and a seq of files is returned. :selection-mode The file selection mode: :files-only, :dirs-only and :files-and-dirs. Defaults to :files-only :filters A seq of either:
a seq that contains a filter name and a seq of
extensions as strings for that filter;
a seq that contains a filter name and a function
to be used as accept function (see file-filter);
a FileFilter (see file-filter).
The filters appear in the dialog's filter selection in the same
order as in the seq.
:all-files? If true, a filter matching all file extensions and files without an extension will appear in the filter selection of the dialog additionally to the filters specified through :filters. The filter usually appears last in the selection. If this is not desired set this option to false and include an equivalent filter manually at the desired position as shown in the examples below. Defaults to true.
:remember-directory? Flag specifying whether to remember the directory for future file-input invocations in case of successful exit. Default: true. :success-fn Function which will be called with the JFileChooser and the File which has been selected by the user. Its result will be returned. Default: return selected File. In the case of MULTI-SELECT? being true, a seq of File instances will be passed instead of a single File. :cancel-fn Function which will be called with the JFileChooser on user abort of the dialog. Its result will be returned. Default: returns nil.
Examples:
; ask & return single file (choose-file)
; ask & return including a filter for image files and an "all files" ; filter appearing at the beginning (choose-file :all-files? false :filters [(file-filter "All files" (constantly true)) ["Images" ["png" "jpeg"]] ["Folders" #(.isDirectory %)]])
; ask & return absolute file path as string (choose-file :success-fn (fn [fc file] (.getAbsolutePath file)))
Returns result of SUCCESS-FN (default: either java.io.File or seq of java.io.File iff multi? set to true) in case of the user selecting a file, or result of CANCEL-FN otherwise.
See http://download.oracle.com/javase/6/docs/api/javax/swing/JFileChooser.html
Choose a file to open or save. The arguments can take two forms. First, with an initial parent component which will act as the parent of the dialog. (choose-file dialog-parent ... options ...) If the first arg is omitted, the desktop is used as the parent of the dialog: (choose-file ... options ...) Options can be one of: :type The dialog type: :open, :save, or a custom string placed on the Ok button. Defaults to :open. :dir The initial working directory. If omitted, the previous directory chosen is remembered and used. :multi? If true, multi-selection is enabled and a seq of files is returned. :selection-mode The file selection mode: :files-only, :dirs-only and :files-and-dirs. Defaults to :files-only :filters A seq of either: a seq that contains a filter name and a seq of extensions as strings for that filter; a seq that contains a filter name and a function to be used as accept function (see file-filter); a FileFilter (see file-filter). The filters appear in the dialog's filter selection in the same order as in the seq. :all-files? If true, a filter matching all file extensions and files without an extension will appear in the filter selection of the dialog additionally to the filters specified through :filters. The filter usually appears last in the selection. If this is not desired set this option to false and include an equivalent filter manually at the desired position as shown in the examples below. Defaults to true. :remember-directory? Flag specifying whether to remember the directory for future file-input invocations in case of successful exit. Default: true. :success-fn Function which will be called with the JFileChooser and the File which has been selected by the user. Its result will be returned. Default: return selected File. In the case of MULTI-SELECT? being true, a seq of File instances will be passed instead of a single File. :cancel-fn Function which will be called with the JFileChooser on user abort of the dialog. Its result will be returned. Default: returns nil. Examples: ; ask & return single file (choose-file) ; ask & return including a filter for image files and an "all files" ; filter appearing at the beginning (choose-file :all-files? false :filters [(file-filter "All files" (constantly true)) ["Images" ["png" "jpeg"]] ["Folders" #(.isDirectory %)]]) ; ask & return absolute file path as string (choose-file :success-fn (fn [fc file] (.getAbsolutePath file))) Returns result of SUCCESS-FN (default: either java.io.File or seq of java.io.File iff multi? set to true) in case of the user selecting a file, or result of CANCEL-FN otherwise. See http://download.oracle.com/javase/6/docs/api/javax/swing/JFileChooser.html
(file-filter description accept)
Create a FileFilter.
Arguments:
description - description of this filter, will show up in the filter-selection box when opening a file choosing dialog.
accept - a function taking a java.awt.File returning true if the file should be shown, false otherwise.
Create a FileFilter. Arguments: description - description of this filter, will show up in the filter-selection box when opening a file choosing dialog. accept - a function taking a java.awt.File returning true if the file should be shown, false otherwise.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close