Klasse FxUtil

java.lang.Object
com.dua3.utility.fx.FxUtil

public final class FxUtil extends Object
JavaFX utility class.
  • Felddetails

    • TRUE

      public static final ObservableBooleanValue TRUE
      A constant ObservableBooleanValue that always holds the value true. This variable is immutable and can be reliably used wherever a constant boolean value of true is required in an observable context.
    • FALSE

      public static final ObservableBooleanValue FALSE
      A static constant representing a boolean property with a fixed value of false. This property is immutable and can be used wherever an ObservableBooleanValue with a value of false is required.
  • Methodendetails

    • convert

      public static Color convert(com.dua3.utility.data.Color color)
      Convert Color to Color.
      Parameter:
      color - the color
      Gibt zurück:
      the JavaFX color
    • convert

      public static com.dua3.utility.data.Color convert(Color color)
      Convert to Color.
      Parameter:
      color - the JavaFX color
      Gibt zurück:
      the color
    • convert

      public static FillRule convert(com.dua3.utility.math.geometry.FillRule rule)
      Convert FillRule to JavaFX FillRule.
      Parameter:
      rule - the fill rule
      Gibt zurück:
      the JavaFX fill rule
    • convert

      public static com.dua3.utility.math.geometry.FillRule convert(FillRule rule)
      Convert FillRule to JavaFX FillRule.
      Parameter:
      rule - JavaFX the fill rule
      Gibt zurück:
      the fill rule
    • convert

      public static Affine convert(com.dua3.utility.math.geometry.AffineTransformation2f at)
      Convert AffineTransformation2f to JavaFX Affine.
      Parameter:
      at - the affine transformation
      Gibt zurück:
      the JavaFX affine transformation
    • convert

      public static com.dua3.utility.math.geometry.AffineTransformation2f convert(Affine a)
      Convert JavaFX Affine to AffineTransformation2f.
      Parameter:
      a - the JavaFX affine transformation
      Gibt zurück:
      the affine transformation
    • convert

      public static Path convert(com.dua3.utility.math.geometry.Path2f path)
      Converts a Path2f object to a Path object.
      Parameter:
      path - the Path2f object to convert
      Gibt zurück:
      the converted javafx.scene.shape.Path object
      Löst aus:
      IllegalArgumentException - if the path contains unsupported segment types
    • convert

      public static Rectangle convert(com.dua3.utility.math.geometry.Rectangle2f r)
      Convert a Rectangle2f object to a JavaFX Rectangle object.
      Parameter:
      r - the Rectangle2f object to convert
      Gibt zurück:
      the converted JavaFX Rectangle object
    • convert

      public static com.dua3.utility.math.geometry.Rectangle2f convert(Rectangle2D r)
      Convert a JavaFX Rectangle object to a Rectangle2f object.
      Parameter:
      r - the Rectangle object to convert
      Gibt zurück:
      the converted Rectangle2f object
    • convert

      public static com.dua3.utility.math.geometry.Rectangle2f convert(Bounds b)
      Convert a JavaFX Bounds object to a Rectangle2f object.
      Parameter:
      b - the Bounds object to convert
      Gibt zurück:
      the converted Rectangle2f object
    • getTextBounds

      public static Bounds getTextBounds(CharSequence s, com.dua3.utility.text.Font f)
      Returns the bounds of the given text string when rendered with the specified font.
      Parameter:
      s - the text string
      f - the font
      Gibt zurück:
      the bounds of the text string
    • getTextBounds

      public static Bounds getTextBounds(CharSequence s, Font f)
      Returns the bounds of the given text string when rendered with the specified font.
      Parameter:
      s - the text string
      f - the font
      Gibt zurück:
      the bounds of the text string
    • convert

      public static Font convert(com.dua3.utility.text.Font font)
      Convert Font to JavaFX Font.
      Parameter:
      font - the font
      Gibt zurück:
      the JavaFX Font
    • convert

      public static com.dua3.utility.text.Font convert(Font fxFont)
      Convert JavaFX Font to Font.
      Parameter:
      fxFont - the font
      Gibt zurück:
      the JavaFX Font
    • getTextWidth

      public static double getTextWidth(CharSequence s, com.dua3.utility.text.Font f)
      Returns the width of the given text string when rendered with the specified font.
      Parameter:
      s - the text string
      f - the font
      Gibt zurück:
      the width of the text string
    • getTextHeight

      public static double getTextHeight(CharSequence s, com.dua3.utility.text.Font f)
      Returns the height of the given text string when rendered with the specified font.
      Parameter:
      s - the text string
      f - the font
      Gibt zurück:
      the height of the text string
    • growToFit

      public static Dimension2D growToFit(Dimension2D a, Bounds b)
      Calculates the dimensions required for a given Dimension2D object to fit within the specified Bounds.
      Parameter:
      a - the original dimension
      b - the bounds to fit into
      Gibt zurück:
      a new Dimension2D object with the adjusted dimensions
    • matches

      public static boolean matches(FileChooser.ExtensionFilter filter, Path file)
      Test if file matches filter.
      Parameter:
      filter - the filter
      file - the file
      Gibt zurück:
      true if filename matches filter
    • matches

      public static boolean matches(FileChooser.ExtensionFilter filter, String filename)
      Test if filename matches filter.
      Parameter:
      filter - the filter
      filename - the filename
      Gibt zurück:
      true if filename matches filter
    • matches

      public static boolean matches(FileChooser.ExtensionFilter filter, File file)
      Test if filename matches filter.
      Parameter:
      filter - the filter
      file - the file
      Gibt zurück:
      true if file matches filter
    • matches

      public static boolean matches(FileChooser.ExtensionFilter filter, URI uri)
      Test if URI matches filter.
      Parameter:
      filter - the filter
      uri - the URI
      Gibt zurück:
      true if file matches filter
    • copyToClipboard

      public static void copyToClipboard(String s)
      Copy text to clipboard.
      Parameter:
      s - the text
    • copyToClipboard

      public static void copyToClipboard(com.dua3.utility.text.RichText text)
      Copy text to clipboard.
      Parameter:
      text - the text
    • copyToClipboard

      public static void copyToClipboard(com.dua3.utility.data.Image img)
      Copy image to clipboard.
      Parameter:
      img - the image
    • copyToClipboard

      public static void copyToClipboard(Image img)
      Copy image to clipboard.
      Parameter:
      img - the image
    • copyToClipboard

      public static void copyToClipboard(Path path)
      Copy file/folder to clipboard.
      Parameter:
      path - the path to the file/folder to copy to the clipboard
    • copyToClipboard

      public static void copyToClipboard(Collection<? extends Path> paths)
      Copy files/folders to clipboard.
      Parameter:
      paths - the list of paths to copy to the clipboard
    • getStringFromClipboard

      public static Optional<String> getStringFromClipboard()
      Retrieves a string from the system clipboard if available.
      Gibt zurück:
      an Optional containing the string from the clipboard if present, or an empty Optional otherwise
    • getImageFromClipboard

      public static Optional<com.dua3.utility.data.Image> getImageFromClipboard()
      Retrieves an image from the system clipboard if one is available.
      Gibt zurück:
      an Optional containing the image if the clipboard contains an image, or an empty Optional if no image is present in the clipboard.
    • getFilesFromClipboard

      public static Collection<Path> getFilesFromClipboard()
      Retrieves a collection of file paths from the system clipboard. If the clipboard contains files, their paths are returned as a collection. Otherwise, an empty collection is returned.
      Gibt zurück:
      A collection of file paths retrieved from the clipboard or an empty collection if no files are present on the clipboard.
    • dragEventHandler

      public static EventHandler<DragEvent> dragEventHandler(Function<? super List<Path>,? extends Collection<TransferMode>> modeGetter)
      Create an EventHandler<DragEvent> that accepts dragging files.
      Parameter:
      modeGetter - Function that determines the supported TransferModes. Should return an empty list if the drag is not accepted.
      Gibt zurück:
      event handler
    • dropEventHandler

      public static EventHandler<DragEvent> dropEventHandler(Consumer<? super List<Path>> processor)
      Create an EventHandler<DragEvent> that accepts paths.
      Parameter:
      processor - consumer that processes the drop event
      Gibt zurück:
      event handler
    • union

      public static Rectangle2D union(Rectangle2D r1, Rectangle2D r2)
      Create the union of two rectangles. The union here is defined as the rectangle r of minimum size that contains both rectangles r1 and r2.
      Parameter:
      r1 - first rectangle
      r2 - second rectangle
      Gibt zurück:
      minimal rectangle containing both r1 and r2
    • toObservableValue

      public static <T extends @Nullable Object> ObservableValue<T> toObservableValue(com.dua3.utility.concurrent.Value<T> value)
      Converts a Value object into an ObservableValue.
      Typparameter:
      T - the type of the value stored in the Value object
      Parameter:
      value - the Value object to be converted
      Gibt zurück:
      an ObservableValue object that reflects changes in the Value object
    • addMouseEventHandler

      public static void addMouseEventHandler(Node node, EventType<MouseEvent> eventType, EventHandler<? super MouseEvent> handler)
      Attaches a mouse event handler to a given node for a specific event type.

      If an event handler is already registered, the new handler is called first. If the event is not consumed by the# handler, the old handler is called too.

      Parameter:
      node - The node to attach the mouse event handler to.
      eventType - The type of the mouse event to handle.
      handler - The event handler to be called when the specified mouse event occurs.
    • map

      public static <A, B> ObservableList<B> map(ObservableList<A> list, Function<A,B> mapping)
      Maps each element of the given ObservableList using the provided mapping function.
      Typparameter:
      A - the type of elements in the original list
      B - the type of elements returned by the mapping function
      Parameter:
      list - the ObservableList to be mapped
      mapping - the mapping function to apply to each element of the list
      Gibt zurück:
      a new ObservableList containing the mapped elements
    • getDisplayScale

      public static com.dua3.utility.math.geometry.Scale2f getDisplayScale(Screen screen)
      Retrieves the display scale of a given Screen.
      Parameter:
      screen - the screen for which to retrieve the display scale
      Gibt zurück:
      the display scale of the screen, or the default scale if no GraphicsConfiguration is set for the component
    • getDisplayScale

      public static com.dua3.utility.math.geometry.Scale2f getDisplayScale(Window window)
      Returns the display scale of the given window. The display scale is a scaling factor that is applied to the window's content to adjust for high-resolution displays.
      Parameter:
      window - the window for which to retrieve the display scale
      Gibt zurück:
      the scale factor applied to the window's content
    • convertToJavaFxPath

      public static Path convertToJavaFxPath(com.dua3.utility.math.geometry.Path2f path)
      Converts a Path2f object to a JavaFX Path.
      Parameter:
      path - the Path2f object containing segments to be converted to a JavaFX Path
      Gibt zurück:
      a JavaFX Path object representing the equivalent structure of the input Path2f
      Löst aus:
      IllegalArgumentException - if an unsupported segment type or unsupported number of control points is encountered
    • getScreen

      public static Screen getScreen(Window window)
      Returns the Screen where the given Window is located.
      Parameter:
      window - the Window to get the Screen for
      Gibt zurück:
      the Screen where the window is located or the primary screen if the screen could not be determined
    • constant

      public static ObservableBooleanValue constant(boolean b)
      Returns an ObservableBooleanValue that represents the specified boolean constant.
      Parameter:
      b - the boolean value to be wrapped as an ObservableBooleanValue
      Gibt zurück:
      an ObservableBooleanValue representing the specified boolean
    • fontConverter

      public static com.dua3.utility.data.Converter<com.dua3.utility.text.Font,Font> fontConverter()
      Provides a converter between com.dua3.utility.text.Font and javafx.scene.text.Font.
      Gibt zurück:
      a Converter instance that can convert between com.dua3.utility.text.Font and javafx.scene.text.Font.
    • colorConverter

      public static com.dua3.utility.data.Converter<com.dua3.utility.data.Color,Color> colorConverter()
      Creates and returns a converter between com.dua3.utility.data.Color and javafx.scene.paint.Color.
      Gibt zurück:
      a bidirectional converter that facilitates conversion between com.dua3.utility.data.Color and javafx.scene.paint.Color.