Class EmbeddedImage

java.lang.Object
jfx.incubator.scene.control.richtext.model.EmbeddedImage

public final class EmbeddedImage extends Object
An attribute which allows an image to be embedded into the RichTextModel.
Since:
27
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Sentinel value which can be passed to either targetWidth or targetHeight to indicate that the rendered image dimension should be computed according to the image intrinsic aspect ratio.
    static final double
    Sentinel value which can be passed to targetWidth to indicate that the rendered image width should not exceed the view's wrapped text width.
    static final double
    Sentinel value which can be passed to targetWidth to indicate that the rendered image width should always fit the view's wrapped text width.
  • Method Summary

    Modifier and Type
    Method
    Description
    copy(double targetWidth, double targetHeight, boolean keepAspectRatio)
    Creates a copy of this EmbeddedImage with the specified target width, height, and aspect ratio.
    Creates the Node to be inserted into RichTextArea.
    double
    Returns the original image height.
    double
    Returns the target image height specification: positive when specifying the final height, or AUTO to determine the value from isKeepAspectRatio() and getHeight().
    double
    Returns the target image width specification: positive when specifying the final width, or AUTO to determine the value from isKeepAspectRatio() and getWidth(), or FIT_WIDTH to ensure the image does not exceed the viewport width, or FIT_WIDTH_ALWAYS to always fit the viewport width.
    double
    Returns the original image width.
    boolean
    Indicates whether the aspect ratio of this image is preserved when scaling to fit the image within the document.
    of(byte[] bytes, double width, double height, double targetWidth, double targetHeight, boolean keepAspectRatio)
    Creates a new EmbeddedImage instance while making a defensive copy of the bytes array.
  • Field Details

    • AUTO

      public static final double AUTO
      Sentinel value which can be passed to either targetWidth or targetHeight to indicate that the rendered image dimension should be computed according to the image intrinsic aspect ratio.
      See Also:
    • FIT_WIDTH

      public static final double FIT_WIDTH
      Sentinel value which can be passed to targetWidth to indicate that the rendered image width should not exceed the view's wrapped text width.
      See Also:
    • FIT_WIDTH_ALWAYS

      public static final double FIT_WIDTH_ALWAYS
      Sentinel value which can be passed to targetWidth to indicate that the rendered image width should always fit the view's wrapped text width.
      See Also:
  • Method Details

    • of

      public static EmbeddedImage of(byte[] bytes, double width, double height, double targetWidth, double targetHeight, boolean keepAspectRatio)
      Creates a new EmbeddedImage instance while making a defensive copy of the bytes array.

      Any negative value passed to either targetWidth or targetHeight, other than a declared sentinel value, causes the image to be rendered as if AUTO had been passed.

      Parameters:
      bytes - the image source
      width - the original image width
      height - the original image height
      targetWidth - the target image width, or FIT_WIDTH, FIT_WIDTH_ALWAYS, or AUTO
      targetHeight - the target image height, or AUTO
      keepAspectRatio - whether to preserve the image aspect ratio
      Returns:
      the new instance
    • getWidth

      public double getWidth()
      Returns the original image width.
      Returns:
      the image width
    • getHeight

      public double getHeight()
      Returns the original image height.
      Returns:
      the image height
    • getTargetWidth

      public double getTargetWidth()
      Returns the target image width specification: positive when specifying the final width, or AUTO to determine the value from isKeepAspectRatio() and getWidth(), or FIT_WIDTH to ensure the image does not exceed the viewport width, or FIT_WIDTH_ALWAYS to always fit the viewport width.
      Returns:
      the image target width
    • getTargetHeight

      public double getTargetHeight()
      Returns the target image height specification: positive when specifying the final height, or AUTO to determine the value from isKeepAspectRatio() and getHeight().
      Returns:
      the image target height
    • isKeepAspectRatio

      public boolean isKeepAspectRatio()
      Indicates whether the aspect ratio of this image is preserved when scaling to fit the image within the document.
      Returns:
      true if the aspect ratio is preserved
    • copy

      public EmbeddedImage copy(double targetWidth, double targetHeight, boolean keepAspectRatio)
      Creates a copy of this EmbeddedImage with the specified target width, height, and aspect ratio.
      Parameters:
      targetWidth - the new target width
      targetHeight - the new target height
      keepAspectRatio - whether to keep the aspect ratio
      Returns:
      the new instance
    • createNode

      public Node createNode()
      Creates the Node to be inserted into RichTextArea.
      Returns:
      the node instance