Interface ImagePane.ImageValue

All Superinterfaces:
Observable<BufferedImage>, Observer<BufferedImage>, Sensor, Value<BufferedImage>
Enclosing class:
ImagePane

public static interface ImagePane.ImageValue extends Value<BufferedImage>

Controls the image displayed in an ImagePane.

Image bytes set on the event dispatch thread, where the pane's byte[] ComponentValue always sets them, are decoded in the background, unless ImagePane.async() is disabled, this value holding null until their image is set, see set(byte[]).

Author:
Slav Boleslawski, Björn Darri Sigurðsson
  • Method Details

    • set

      void set(byte @Nullable [] imageBytes)

      Sets the image bytes, the pane's byte[] ComponentValue, displayed turned as their EXIF orientation says where enabled, see ImagePane.Builder.orient(boolean).

      Set on the event dispatch thread, the bytes are decoded in the background, unless ImagePane.async() is disabled. The bytes are then the component value at once, while this value is cleared, null until the image is decoded, and notifies on the event dispatch thread when it is set. So code following this call, zooming or translating coordinates, finds no image: it belongs in a callback, see set(byte[], Consumer), or a listener on this value. Bytes set while a decode is under way supersede it, as does an image set directly, the latest winning, a superseded decode aborted and its image discarded.

      Set elsewhere, or with ImagePane.async() disabled, the bytes are decoded on the calling thread. The pane's byte[] ComponentValue sets them on the event dispatch thread, whichever thread it is set from, so they are decoded in the background whenever set via the component value, or the builder.

      Null or empty bytes clear the image, one set directly included. Bytes no image reader can read result in no image. An exception decoding them clears the image and is passed to the exception handler, see ImagePane.Builder.onException(Consumer), which by default rethrows it, from this method when decoding on the calling thread.

      Parameters:
      imageBytes - the image bytes
    • set

      void set(byte @Nullable [] imageBytes, Consumer<BufferedImage> onImage)

      Sets the image bytes, see set(byte[]), calling onImage with their image once it is set: on the event dispatch thread when decoded in the background, before this method returns when decoded on the calling thread, so code acting on the image works the same either way. Called once this value and ImagePane.decoding() have notified. Where the bytes equal those already set, it is called with their image, once set, there being nothing to decode again.

      Not called where no image results, from empty bytes or bytes no image reader can read, where decoding fails, the exception handler's to handle, or where superseded before their image is set, by other bytes or an image set directly.

      Parameters:
      imageBytes - the image bytes
      onImage - called with the image once it is set
    • set

      void set(String imagePath) throws IOException
      Reads the image bytes from the given file, on the calling thread, and sets them, see set(byte[]). A file on a slow share is best read in the background, its bytes then set on the event dispatch thread.
      Parameters:
      imagePath - the path from which to load the image
      Throws:
      IOException - in case reading the file failed
    • set

      void set(String imagePath, Consumer<BufferedImage> onImage) throws IOException
      Reads the image bytes from the given file, on the calling thread, and sets them, see set(byte[], Consumer).
      Parameters:
      imagePath - the path from which to load the image
      onImage - called with the image once it is set
      Throws:
      IOException - in case reading the file failed
    • set

      void set(BufferedImage image, String format) throws IOException
      Parameters:
      image - the image
      format - the format
      Throws:
      IOException - in case of an exception
      IllegalArgumentException - in case no writer was found for the given format