Class NativeDirectoryChooser
java.lang.Object
edu.wisc.ssec.mcidasv.util.nativepathchooser.NativeDirectoryChooser
This class allows users to select a directory via the GUI.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNativeDirectoryChooser
(Supplier<javafx.stage.DirectoryChooser> directoryChooserFactory) Constructs a new directory chooser that will use the provided factory. -
Method Summary
Modifier and TypeMethodDescription<T> T
showDialog
(Function<javafx.stage.DirectoryChooser, T> method) Shows aDirectoryChooser
dialog by calling the provided method.<T> T
showDialog
(Function<javafx.stage.DirectoryChooser, T> method, long timeout, TimeUnit unit) Shows theDirectoryChooser
dialog by calling the provided method.Shows aDirectoryChooser
usingDirectoryChooser.showDialog(Window)
.
-
Field Details
-
directoryChooserFactory
-
-
Constructor Details
-
NativeDirectoryChooser
Constructs a new directory chooser that will use the provided factory. The factory is accessed from the JavaFX event thread, so it should either be immutable or at least its state shouldn't be changed randomly while one of the dialog-showing method calls is in progress. The factory should create and set up the chooser, for example, by setting extension filters. If there is no need to perform custom initialization of the chooser, DirectoryChooser::new could be passed as a factory. Alternatively, the method parameter supplied to theshowDialog(Function)
function can be used to provide custom initialization.- Parameters:
directoryChooserFactory
- Function used to construct new choosers.
-
-
Method Details
-
showDialog
Shows aDirectoryChooser
dialog by calling the provided method.Waits for one second for the dialog-showing task to start in the JavaFX event thread, then throws an IllegalStateException if it didn't start.
- Type Parameters:
T
- the return type of the method, usually File or List<File>- Parameters:
method
- a function calling one of the dialog-showing methods- Returns:
- whatever the method returns
- See Also:
-
showDialog
public <T> T showDialog(Function<javafx.stage.DirectoryChooser, T> method, long timeout, TimeUnit unit) Shows theDirectoryChooser
dialog by calling the provided method. The dialog is created by the factory supplied to the constructor, then it is shown by calling the provided method on it, then the result is returned.Everything happens in the right threads thanks to
SynchronousJFXCaller
. The task performed in the JavaFX thread consists of two steps: construct a chooser using the provided factory and invoke the provided method on it. Any exception thrown during these steps will be rethrown in the calling thread, which shouldn't normally happen unless the factory throws an unchecked exception.If the calling thread is interrupted during either the wait for the task to start or for its result, then null is returned and the Thread interrupted status is set.
- Type Parameters:
T
- return type (usually File or List<File>)- Parameters:
method
- a function that calls the desired FileChooser methodtimeout
- time to wait for Platform.runLater() to start the dialog-showing task (once started, it is allowed to run as long as needed)unit
- the time unit of the timeout argument- Returns:
- whatever the method returns
- Throws:
IllegalStateException
- if Platform.runLater() fails to start the dialog-showing task within the given timeout
-
showOpenDialog
Shows aDirectoryChooser
usingDirectoryChooser.showDialog(Window)
.- Returns:
- Return value of
DirectoryChooser.showOpenDialog()
. - See Also:
-