Module is.codion.swing.common.ui
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-
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 panel when the panel 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, ImagePanel> overlay) Sets the overlay painter that will be called after the image is painted but before the navigation image.zoomDevice(ImagePanel.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 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 RegionsList<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
- Parameters:
zoomDevice- the initial zoom device- Returns:
- this builder
- See Also:
-
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
Default false- Parameters:
movable- true if the image should be movable within the panel- Returns:
- this builder
-