Package anlavn.ui.filechooser
Class JnaFileChooser
java.lang.Object
anlavn.ui.filechooser.JnaFileChooser
JnaFileChooser is a wrapper around the native Windows file chooser and folder
browser that falls back to the Swing JFileChooser on platforms other than
Windows or if the user chooses a combination of features that are not
supported by the native dialogs (for example multiple selection of
directories).
Example: JnaFileChooser fc = new JnaFileChooser(); fc.setFilter("All Files",
"*"); fc.setFilter("Pictures", "jpg", "jpeg", "gif", "png", "bmp");
fc.setMultiSelectionEnabled(true);
fc.setMode(JnaFileChooser.Mode.FilesAndDirectories); if
(fc.showOpenDialog(parent)) { Files[] selected = fc.getSelectedFiles(); // do
something with selected }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
the availabe selection modes of the dialog -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptioncreates a new file chooser with multiselection disabled and mode set to allow file selection only.JnaFileChooser
(File currentDirectory) creates a new file chooser with the specified initial directoryJnaFileChooser
(String currentDirectoryPath) creates a new file chooser with the specified initial directory -
Method Summary
Modifier and TypeMethodDescriptionvoid
add a filter to the user-selectable list of file filtersgetMode()
File[]
boolean
void
setCurrentDirectory
(String currentDirectoryPath) void
setDefaultFileName
(String dfile) void
setMode
(JnaFileChooser.Mode mode) sets the selection modevoid
setMultiSelectionEnabled
(boolean enabled) sets whether to enable multiselectionvoid
setOpenButtonText
(String buttonText) set a open button namevoid
setSaveButtonText
(String buttonText) set a save button namevoid
set a title nameboolean
showOpenDialog
(Window parent) shows a dialog for opening filesboolean
showSaveDialog
(Window parent) shows a dialog for saving files
-
Field Details
-
selectedFiles
-
currentDirectory
-
filters
-
multiSelectionEnabled
protected boolean multiSelectionEnabled -
mode
-
defaultFile
-
dialogTitle
-
openButtonText
-
saveButtonText
-
-
Constructor Details
-
JnaFileChooser
public JnaFileChooser()creates a new file chooser with multiselection disabled and mode set to allow file selection only. -
JnaFileChooser
creates a new file chooser with the specified initial directory- Parameters:
currentDirectory
- the initial directory
-
JnaFileChooser
creates a new file chooser with the specified initial directory- Parameters:
currentDirectoryPath
- the initial directory
-
-
Method Details
-
showOpenDialog
shows a dialog for opening files- Parameters:
parent
- the parent window- Returns:
- true if the user clicked OK
-
showSaveDialog
shows a dialog for saving files- Parameters:
parent
- the parent window- Returns:
- true if the user clicked OK
-
addFilter
add a filter to the user-selectable list of file filters- Parameters:
name
- name of the filterfilter
- you must pass at least 1 argument, the arguments are the file extensions.
-
setMode
sets the selection mode- Parameters:
mode
- the selection mode
-
getMode
-
setCurrentDirectory
-
setMultiSelectionEnabled
public void setMultiSelectionEnabled(boolean enabled) sets whether to enable multiselection- Parameters:
enabled
- true to enable multiselection, false to disable it
-
isMultiSelectionEnabled
public boolean isMultiSelectionEnabled() -
setDefaultFileName
-
setTitle
set a title name- Parameters:
title
- of dialog
-
setOpenButtonText
set a open button name- Parameters:
buttonText
- button text
-
setSaveButtonText
set a save button name- Parameters:
buttonText
- button text
-
getSelectedFiles
-
getSelectedFile
-
getCurrentDirectory
-