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- Author:
- Slav Boleslawski, Björn Darri Sigurðsson
-
Field Summary
Fields inherited from interface ComponentValueBuilder
COMPONENT_VALUE -
Method Summary
Modifier and TypeMethodDescriptionasync(boolean async) autoResize(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 falsenavigationCorner(ImagePane.NavigationCorner navigationCorner) nullable(boolean nullable) Default true.onException(Consumer<Exception> onException) Sets the handler for an exception thrown decoding image bytes, called on the event dispatch thread when decoding in the background, otherwise on the calling thread, afterImagePane.exception()is notified.orient(boolean orient) Whether an image set as bytes, a JPEG's, is displayed turned as its EXIF orientation says, as a camera records a photo taken with the camera turned, whichImageIOignores.overlay(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 ComponentBuilder
ancestorListener, background, border, build, build, clientProperty, componentListener, componentOrientation, enabled, enabled, focusable, focusable, focusCycleRoot, focusListener, font, font, foreground, get, hierarchyListener, keyEvent, keyListener, label, label, label, maximumHeight, maximumSize, maximumWidth, minimumHeight, minimumSize, minimumWidth, mouseListener, mouseMotionListener, mouseWheelListener, name, onBuild, onSetVisible, opaque, popupControl, popupControls, popupControls, popupMenu, preferredHeight, preferredSize, preferredWidth, propertyChangeListener, propertyChangeListener, scrollPane, toolTipText, toolTipText, transferFocusOnEnter, transferFocusOnEnter, transferHandler, visible, visibleMethods inherited from interface ComponentValueBuilder
buildValue, buildValue, changeConsumer, changeListener, consumer, link, link, listener, modified, modifiedIndicator, onBuildValue, valid, valid, validationIndicator, validator, value, warned, weakChangeConsumer, weakChangeListener, weakConsumer, weakListener, when, when, when, when
-
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
Example - Highlighting RegionsImagePane 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.coordinates().toPane(new Point2D.Double(x, 0)); Point2D.Double bottom = pane.coordinates().toPane( new Point2D.Double(x, image.getHeight())); g2d.drawLine((int) top.x, (int) top.y, (int) bottom.x, (int) bottom.y); } }) .build();The overlay is redrawn automatically whenever the pane repaints (e.g., when zooming, panning, or resizing).List<Rectangle> taggedRegions = taggedRegions(); 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.coordinates().toPane( new Point2D.Double(region.x, region.y)); Point2D.Double bottomRight = pane.coordinates().toPane( 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();- 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
-
orient
Whether an image set as bytes, a JPEG's, is displayed turned as its EXIF orientation says, as a camera records a photo taken with the camera turned, whichImageIOignores. For display only: the bytes, the component value, are left as they are. An image set as aBufferedImageis displayed as it is.- Parameters:
orient- true if an image set as bytes should be displayed as its EXIF orientation says- Returns:
- this builder
- See Also:
-
async
- Parameters:
async- true if image bytes set on the event dispatch thread should be decoded in the background- Returns:
- this builder
- See Also:
-
onException
Sets the handler for an exception thrown decoding image bytes, called on the event dispatch thread when decoding in the background, otherwise on the calling thread, afterImagePane.exception()is notified. By default the exception is rethrown, anIOExceptionwrapped in anUncheckedIOException, reaching the event dispatch thread's exception handler when decoding in the background.- Parameters:
onException- the exception handler- Returns:
- this builder
-
nullable
Default true.If false, the component value returns an empty byte array instead of null, when no image is present.
- Parameters:
nullable- if true null is used to indicate no image, if false an empty byte array is used- Returns:
- this builder
- See Also:
-