Interface ImagePanel.Builder

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

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

    • image

      ImagePanel.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

      ImagePanel.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 ImagePanel for accessing coordinate conversion methods and panel state. Example - Drawing Grid Lines

       ImagePanel imagePanel = ImagePanel.builder()
           .image(image)
           .overlay((g2d, panel) -> {
               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 = panel.toPanelCoordinates(new Point2D.Double(x, 0));
                   Point2D.Double bottom = panel.toPanelCoordinates(
                       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();
      
       ImagePanel imagePanel = ImagePanel.builder()
           .image(image)
           .overlay((g2d, panel) -> {
               g2d.setColor(new Color(255, 0, 0, 128));
               for (Rectangle region : taggedRegions) {
                   // Convert image coordinates to panel coordinates
                   Point2D.Double topLeft = panel.toPanelCoordinates(
                       new Point2D.Double(region.x, region.y));
                   Point2D.Double bottomRight = panel.toPanelCoordinates(
                       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 panel repaints (e.g., when zooming, panning, or resizing).
      Parameters:
      overlay - the overlay painter, receives Graphics2D for drawing and ImagePanel for coordinate conversion
      Returns:
      this builder
    • zoomDevice

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

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

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