Interface ImagePane.Builder

All Superinterfaces:
ComponentBuilder<ImagePane,ImagePane.Builder>, ComponentValueBuilder<ImagePane,byte[],ImagePane.Builder>, Supplier<ImagePane>
Enclosing class:
ImagePane

public static interface ImagePane.Builder extends ComponentValueBuilder<ImagePane,byte[],ImagePane.Builder>
Builds an ImagePane
  • Method Details

    • image

      ImagePane.Builder image(String imagePath) throws IOException
      Clears any image set via image(BufferedImage).
      Parameters:
      imagePath - the path to the image to initially display
      Returns:
      this builder
      Throws:
      IOException
    • image

      Clears any value set via ComponentValueBuilder.value(Object).
      Parameters:
      image - the image to initially display
      Returns:
      this builder
    • image

      ImagePane.Builder image(BufferedImage image, String format) throws IOException
      Clears any image set via image(BufferedImage).
      Parameters:
      image - the image to initially display
      format - the format name
      Returns:
      this builder
      Throws:
      IllegalArgumentException - in case no image writer was found for the given format
      IOException
    • overlay

      Sets the overlay painter that will be called after the image is painted but before the navigation image. This allows custom graphics to be drawn on top of the image, such as annotations, grids, highlights, or selection markers.

      The overlay painter receives the Graphics2D context for drawing and the ImagePane for accessing coordinate conversion methods and pane state. Example - Drawing Grid Lines

       ImagePane imagePane = ImagePane.builder()
           .image(image)
           .overlay((g2d, pane) -> {
               g2d.setColor(new Color(255, 255, 255, 100));
               // Draw grid lines every 100 image pixels
               for (int x = 0; x < image.getWidth(); x += 100) {
                   Point2D.Double top = pane.toPaneCoordinates(new Point2D.Double(x, 0));
                   Point2D.Double bottom = pane.toPaneCoordinates(
                       new Point2D.Double(x, image.getHeight()));
                   g2d.drawLine((int) top.x, (int) top.y, (int) bottom.x, (int) bottom.y);
               }
           })
           .build();
       
      Example - Highlighting Regions
       List<Rectangle> taggedRegions = getTaggedRegions();
      
       ImagePane imagePane = ImagePane.builder()
           .image(image)
           .overlay((g2d, pane) -> {
               g2d.setColor(new Color(255, 0, 0, 128));
               for (Rectangle region : taggedRegions) {
                   // Convert image coordinates to pane coordinates
                   Point2D.Double topLeft = pane.toPaneCoordinates(
                       new Point2D.Double(region.x, region.y));
                   Point2D.Double bottomRight = pane.toPaneCoordinates(
                       new Point2D.Double(region.x + region.width, region.y + region.height));
      
                   int width = (int) (bottomRight.x - topLeft.x);
                   int height = (int) (bottomRight.y - topLeft.y);
                   g2d.fillRect((int) topLeft.x, (int) topLeft.y, width, height);
               }
           })
           .build();
       
      The overlay is redrawn automatically whenever the pane repaints (e.g., when zooming, panning, or resizing).
      Parameters:
      overlay - the overlay painter, receives Graphics2D for drawing and ImagePane for coordinate conversion
      Returns:
      this builder
    • zoomDevice

      ImagePane.Builder zoomDevice(ImagePane.ZoomDevice zoomDevice)
      Parameters:
      zoomDevice - the initial zoom device
      Returns:
      this builder
      See Also:
    • autoResize

      ImagePane.Builder autoResize(boolean autoResize)
      Sets whether the image should automatically re-fit to the pane when the pane is resized. When enabled, the image resets to fit the pane dimensions on every resize event, regardless of the current zoom level.
      Parameters:
      autoResize - true to enable auto-resize
      Returns:
      this builder
      See Also:
    • movable

      ImagePane.Builder movable(boolean movable)
      Default false
      Parameters:
      movable - true if the image should be movable within the pane
      Returns:
      this builder