public class NativeFileChooser extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.function.Supplier<javafx.stage.FileChooser> |
fileChooserFactory |
Constructor and Description |
---|
NativeFileChooser(java.util.function.Supplier<javafx.stage.FileChooser> fileChooserFactory)
Constructs a new file chooser that will use the provided factory.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
showDialog(java.util.function.Function<javafx.stage.FileChooser,T> method)
Shows the FileChooser dialog by calling the provided method.
|
<T> T |
showDialog(java.util.function.Function<javafx.stage.FileChooser,T> method,
long timeout,
java.util.concurrent.TimeUnit unit)
Shows the FileChooser dialog by calling the provided method.
|
java.io.File |
showOpenDialog()
Shows a FileChooser using FileChooser.showOpenDialog().
|
java.util.List<java.io.File> |
showOpenMultipleDialog()
Shows a FileChooser using FileChooser.showOpenMultipleDialog().
|
java.io.File |
showSaveDialog()
Shows a FileChooser using FileChooser.showSaveDialog().
|
private final java.util.function.Supplier<javafx.stage.FileChooser> fileChooserFactory
public NativeFileChooser(java.util.function.Supplier<javafx.stage.FileChooser> fileChooserFactory)
fileChooserFactory
- the function used to construct new chooserspublic <T> T showDialog(java.util.function.Function<javafx.stage.FileChooser,T> method)
T
- the return type of the method, usually File or List<File>method
- a function calling one of the dialog-showing methodsshowDialog(java.util.function.Function, long, java.util.concurrent.TimeUnit)
public <T> T showDialog(java.util.function.Function<javafx.stage.FileChooser,T> method, long timeout, java.util.concurrent.TimeUnit unit)
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.
T
- return type (usually File or List<File>)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 argumentjava.lang.IllegalStateException
- if Platform.runLater() fails to start
the dialog-showing task within the given timeoutpublic java.io.File showOpenDialog()
showDialog(java.util.function.Function, long, java.util.concurrent.TimeUnit)
public java.io.File showSaveDialog()
showDialog(java.util.function.Function, long, java.util.concurrent.TimeUnit)
public java.util.List<java.io.File> showOpenMultipleDialog()
showDialog(java.util.function.Function, long, java.util.concurrent.TimeUnit)