Module is.codion.swing.common.ui
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-
Field Summary
Fields inherited from interface is.codion.swing.common.ui.component.builder.ComponentValueBuilder
COMPONENT_VALUE -
Method Summary
Modifier and TypeMethodDescriptionautoResize(boolean autoResize) Sets whether the image should automatically re-fit to the pane when the pane is resized.image(BufferedImage image) Clears any value set viaComponentValueBuilder.value(Object).image(BufferedImage image, String format) Clears any image set viaimage(BufferedImage).Clears any image set viaimage(BufferedImage).movable(boolean movable) Default falsenavigable(boolean navigable) Default falseoverlay(BiConsumer<Graphics2D, ImagePane> overlay) Sets the overlay painter that will be called after the image is painted but before the navigation image.zoomDevice(ImagePane.ZoomDevice zoomDevice) Methods inherited from interface is.codion.swing.common.ui.component.builder.ComponentBuilder
ancestorListener, background, border, build, build, clientProperty, componentListener, componentOrientation, enabled, enabled, focusable, focusable, focusCycleRoot, focusListener, font, font, foreground, get, hierarchyListener, keyEvent, keyListener, label, label, maximumHeight, maximumSize, maximumWidth, minimumHeight, minimumSize, minimumWidth, mouseListener, mouseMotionListener, mouseWheelListener, name, onBuild, onSetVisible, opaque, popupMenu, popupMenuControl, popupMenuControls, preferredHeight, preferredSize, preferredWidth, propertyChangeListener, propertyChangeListener, scrollPane, toolTipText, toolTipText, transferFocusOnEnter, transferFocusOnEnter, transferHandler, visible, visibleMethods inherited from interface is.codion.swing.common.ui.component.builder.ComponentValueBuilder
buildValue, buildValue, consumer, link, link, listener, modifiedIndicator, modifiedIndicatorFactory, onBuildValue, validator, validIndicator, validIndicator, validIndicatorFactory, value
-
Method Details
-
image
Clears any image set viaimage(BufferedImage).- Parameters:
imagePath- the path to the image to initially display- Returns:
- this builder
- Throws:
IOException
-
image
Clears any value set viaComponentValueBuilder.value(Object).- Parameters:
image- the image to initially display- Returns:
- this builder
-
image
Clears any image set viaimage(BufferedImage).- Parameters:
image- the image to initially displayformat- the format name- Returns:
- this builder
- Throws:
IllegalArgumentException- in case no image writer was found for the given formatIOException
-
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 RegionsList<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
- Parameters:
zoomDevice- the initial zoom device- Returns:
- this builder
- See Also:
-
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
Default false- Parameters:
movable- true if the image should be movable within the pane- Returns:
- this builder
-