Record Class SynchronousJFXDirectoryChooser
-
Constructor Summary
ConstructorDescriptionSynchronousJFXDirectoryChooser
(javafx.stage.Stage parent, Supplier<javafx.stage.DirectoryChooser> DirectoryChooserFactory) Constructs a new file chooser that will use the provided factory. -
Method Summary
Modifier and TypeMethodDescriptionSupplier
<javafx.stage.DirectoryChooser> Returns the value of theDirectoryChooserFactory
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.javafx.stage.Stage
parent()
Returns the value of theparent
record component.Shows a DirectoryChooser using DirectoryChooser.showOpenDialog().<T> T
showDialog
(Function<javafx.stage.DirectoryChooser, T> method) Shows the DirectoryChooser dialog by calling the provided method.<T> T
showDialog
(Function<javafx.stage.DirectoryChooser, T> method, long timeout, TimeUnit unit) Shows the DirectoryChooser dialog by calling the provided method.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
SynchronousJFXDirectoryChooser
public SynchronousJFXDirectoryChooser(javafx.stage.Stage parent, Supplier<javafx.stage.DirectoryChooser> DirectoryChooserFactory) 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, DirectoryChooser::new could be passed as a factory.
Alternatively, the method parameter supplied to the showDialog() function can be used to provide custom initialization.
- Parameters:
DirectoryChooserFactory
- the function used to construct new choosers
-
-
Method Details
-
showDialog
Shows the DirectoryChooser 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 the DirectoryChooser 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 DirectoryChooser 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
-
showDialog
Shows a DirectoryChooser using DirectoryChooser.showOpenDialog().- Returns:
- the return value of DirectoryChooser.showOpenDialog()
- 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
-
DirectoryChooserFactory
Returns the value of theDirectoryChooserFactory
record component.- Returns:
- the value of the
DirectoryChooserFactory
record component
-