Record Class SynchronousJFXDirectoryChooser

java.lang.Object
java.lang.Record
net.mcreator.ui.component.filebrowser.SynchronousJFXDirectoryChooser

public record SynchronousJFXDirectoryChooser(javafx.stage.Stage parent, Supplier<javafx.stage.DirectoryChooser> DirectoryChooserFactory) extends Record
  • Constructor Summary

    Constructors
    Constructor
    Description
    SynchronousJFXDirectoryChooser(javafx.stage.Stage parent, Supplier<javafx.stage.DirectoryChooser> DirectoryChooserFactory)
    Constructs a new file chooser that will use the provided factory.
  • Method Summary

    Modifier and Type
    Method
    Description
    Supplier<javafx.stage.DirectoryChooser>
    Returns the value of the DirectoryChooserFactory record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    javafx.stage.Stage
    Returns the value of the parent 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
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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

      public <T> T showDialog(Function<javafx.stage.DirectoryChooser,T> method)
      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 method
      timeout - 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

      public File showDialog()
      Shows a DirectoryChooser using DirectoryChooser.showOpenDialog().
      Returns:
      the return value of DirectoryChooser.showOpenDialog()
      See Also:
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • parent

      public javafx.stage.Stage parent()
      Returns the value of the parent record component.
      Returns:
      the value of the parent record component
    • DirectoryChooserFactory

      public Supplier<javafx.stage.DirectoryChooser> DirectoryChooserFactory()
      Returns the value of the DirectoryChooserFactory record component.
      Returns:
      the value of the DirectoryChooserFactory record component