Record Class SynchronousJFXFileChooser
-
Constructor Summary
ConstructorDescriptionSynchronousJFXFileChooser
(javafx.stage.Stage parent, Supplier<javafx.stage.FileChooser> fileChooserFactory) Constructs a new file chooser that will use the provided factory. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.Supplier
<javafx.stage.FileChooser> Returns the value of thefileChooserFactory
record component.final int
hashCode()
Returns a hash code value for this object.javafx.stage.Stage
parent()
Returns the value of theparent
record component.<T> T
showDialog
(Function<javafx.stage.FileChooser, T> method) Shows the FileChooser dialog by calling the provided method.<T> T
showDialog
(Function<javafx.stage.FileChooser, T> method, long timeout, TimeUnit unit) Shows the FileChooser dialog by calling the provided method.Shows a FileChooser using FileChooser.showOpenDialog().Shows a FileChooser using FileChooser.showOpenMultipleDialog().Shows a FileChooser using FileChooser.showSaveDialog().final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
SynchronousJFXFileChooser
public SynchronousJFXFileChooser(javafx.stage.Stage parent, Supplier<javafx.stage.FileChooser> fileChooserFactory) Constructs a new file 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, FileChooser::new could be passed as a factory.
Alternatively, the method parameter supplied to the showDialog() function can be used to provide custom initialization.
- Parameters:
fileChooserFactory
- the function used to construct new choosers
-
-
Method Details
-
showDialog
Shows the FileChooser 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
Shows the FileChooser 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 a FileChooser using FileChooser.showOpenDialog().- Returns:
- the return value of FileChooser.showOpenDialog()
- See Also:
-
showSaveDialog
Shows a FileChooser using FileChooser.showSaveDialog().- Returns:
- the return value of FileChooser.showSaveDialog()
- See Also:
-
showOpenMultipleDialog
Shows a FileChooser using FileChooser.showOpenMultipleDialog().- Returns:
- the return value of FileChooser.showOpenMultipleDialog()
- See Also:
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
parent
public javafx.stage.Stage parent()Returns the value of theparent
record component.- Returns:
- the value of the
parent
record component
-
fileChooserFactory
Returns the value of thefileChooserFactory
record component.- Returns:
- the value of the
fileChooserFactory
record component
-