This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch visual-test in repository https://gitbox.apache.org/repos/asf/sis.git
commit e1cb9164c12aff921218308b183246b7c57638a2 Author: Martin Desruisseaux <[email protected]> AuthorDate: Wed Jun 29 15:11:24 2022 +0200 Show an image made of only a raster. --- src/main/java/org/apache/sis/swing/ImagePane.java | 29 +++++++++++++++++++++- .../java/org/apache/sis/swing/WindowCreator.java | 2 +- .../org/apache/sis/swing/internal/Resources.java | 2 +- .../java/org/apache/sis/swing/package-info.java | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/sis/swing/ImagePane.java b/src/main/java/org/apache/sis/swing/ImagePane.java index d20c248a04..afa0f47f23 100644 --- a/src/main/java/org/apache/sis/swing/ImagePane.java +++ b/src/main/java/org/apache/sis/swing/ImagePane.java @@ -20,7 +20,12 @@ import java.awt.BasicStroke; import java.awt.Paint; import java.awt.Color; import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.Raster; +import java.awt.image.ColorModel; +import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; +import java.awt.image.WritableRaster; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import javax.swing.JFrame; @@ -36,7 +41,7 @@ import org.apache.sis.referencing.operation.matrix.AffineTransforms2D; * Shows a {@link RenderedImage}, optionally with marks such as pixel grid or tile grid. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.3 * @since 1.1 * @module */ @@ -117,6 +122,28 @@ public class ImagePane extends ZoomPane { return pane; } + /** + * Show the given raster in a panel. + * The "grid to CRS" transform will be modified in-place. + * + * @param raster the raster to show. + * @param colors the color model to use. + * @param gridToCRS the transform from pixel coordinates to "real world" coordinates (modified by this method). + * @param title window title. + * @return the image pane which has been shown. + */ + public static ImagePane show(final Raster raster, final ColorModel colors, final AffineTransform gridToCRS, final String title) { + final Rectangle b = raster.getBounds(); + final WritableRaster wr; + if (raster instanceof WritableRaster) { + wr = ((WritableRaster) raster).createWritableChild(b.x, b.y, b.width, b.height, 0, 0, null); + } else { + wr = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null); + } + gridToCRS.translate(b.x, b.y); + return show(new BufferedImage(colors, wr, false, null), gridToCRS, title); + } + /** * Creates a new viewer for the given image. * diff --git a/src/main/java/org/apache/sis/swing/WindowCreator.java b/src/main/java/org/apache/sis/swing/WindowCreator.java index 16b5449515..d80adcf05e 100644 --- a/src/main/java/org/apache/sis/swing/WindowCreator.java +++ b/src/main/java/org/apache/sis/swing/WindowCreator.java @@ -36,7 +36,7 @@ import org.apache.sis.swing.internal.Resources; * window providing information about the selected CRS. * * <p>By default the new windows are instances of either {@link JDialog}, {@link JFrame} or - * {@link JInternalFrame} - the later case occurs if and only if this {@code WindowCreator} + * {@link JInternalFrame} - the latter case occurs if and only if this {@code WindowCreator} * has a {@link JDesktopPane} ancestor. However this class provides a * {@link #setWindowHandler(Handler)} method allowing users to plugin their own mechanism, * for example in order to integrate the widget in the NetBeans platform.</p> diff --git a/src/main/java/org/apache/sis/swing/internal/Resources.java b/src/main/java/org/apache/sis/swing/internal/Resources.java index 132c2f3b8c..c056c73ad4 100644 --- a/src/main/java/org/apache/sis/swing/internal/Resources.java +++ b/src/main/java/org/apache/sis/swing/internal/Resources.java @@ -154,7 +154,7 @@ public final class Resources extends IndexedResourceBundle { * Constructs a new resource bundle loading data from the given UTF file. * * @param resources the path of the binary file containing resources, or {@code null} if - * there is no resources. The resources may be a file or an entry in a JAR file. + * there are no resources. The resources may be a file or an entry in a JAR file. */ public Resources(final URL resources) { super(resources); diff --git a/src/main/java/org/apache/sis/swing/package-info.java b/src/main/java/org/apache/sis/swing/package-info.java index 98ed7c8623..3067584f35 100644 --- a/src/main/java/org/apache/sis/swing/package-info.java +++ b/src/main/java/org/apache/sis/swing/package-info.java @@ -20,7 +20,7 @@ * In the future, we could move this package to a {@code sis-swing} module if there is a use for it. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.3 * @since 1.1 */ package org.apache.sis.swing;
