Class JImagePanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JImagePanel extends JPanel
A swing component that enables to display images.
This panel provides various operations on the view (zoom, moving, ...) and helper methods for correspondence between image space and display space.
This image panel also manages features that enable to display interactive overlays on the panel.
Since:
1.0.4
Version:
"1.0.14" - b202111241200L
Author:
Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
See Also:
  • Field Details

  • Constructor Details

    • JImagePanel

      public JImagePanel()
      Create a new image panel.
    • JImagePanel

      public JImagePanel(BufferedImage image)
      Create a new image panel that display the given image.
      Parameters:
      image - the image to display.
  • Method Details

    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • drawSelectionShape

      protected void drawSelectionShape(Graphics2D g2d, Shape shape)
      Draw the given selection shape on the given graphics context.
      Parameters:
      g2d - the the given graphics context.
      shape - the shape to draw.
    • isRendering

      public boolean isRendering()
      Check if the panel is actually refreshing image and features.
      Returns:
      true if the panel is actually refreshing image and features and false otherwise.
    • getRenderingHints

      public RenderingHints getRenderingHints()
      Get the rendering hints that this panel use. If this method return null, default rendering hints are used.
      Returns:
      the rendering hints that this panel use.
      See Also:
    • setRenderingHints

      public void setRenderingHints(RenderingHints hints)
      Set the rendering hints that this panel has to use. If hints parameter is set to null, then default rendering hints are used.
      Parameters:
      hints - the rendering hints that this panel has to use.
      See Also:
    • getSelectionShapeStroke

      public Stroke getSelectionShapeStroke()
      Get the stroke used when drawing selection shape.
      Returns:
      the stroke used when drawing selection shape.
      See Also:
    • setSelectionShapeStroke

      public void setSelectionShapeStroke(Stroke stroke)
      Set the stroke to use when drawing selection shape.
      Parameters:
      stroke - the stroke to use.
      See Also:
    • getSelectionMode

      public int getSelectionMode()
      Get the selection mode used by the panel. This can be one of:
      Returns:
      the selection mode used by the panel.
      See Also:
    • setSelectionMode

      public void setSelectionMode(int mode)
      Set the selection mode that the panel has to use. This can be one of:
      Parameters:
      mode - the selection mode that the panel has to use.
      See Also:
    • isAutoRepaint

      public boolean isAutoRepaint()
      Get if the panel is using auto repaint. If the auto repaint mode is activated, the panel will repaint every time a modification is made to the displayed object (image, features) or to the view (scale, translation, ...). This mode is not convenient if many modification has to be made before a display refresh. In this case, it is recommended to set the auto repaint to false and to call Component.repaint() when all modifications are done.
      Returns:
      true if the panel has to auto repaint and false otherwise.
      See Also:
    • setAutoRepaint

      public void setAutoRepaint(boolean auto)
      Set if the panel has to do auto repaint. If the auto repaint mode is activated, the panel will repaint every time a modification is made to the displayed object (image, features) or to the view (scale, translation, ...). This mode is not convenient if many modification has to be made before a display refresh. In this case, it is recommended to set the auto repaint to false and to call Component.repaint() when all modifications are done.
      Parameters:
      auto - true if the panel has to auto repaint and false otherwise.
      See Also:
    • isAutoFit

      public boolean isAutoFit()
      Get if the panel fits the view when its resized.
      Returns:
      true if the panel fits the view when its resized and false otherwise.
      See Also:
    • setAutoFit

      public void setAutoFit(boolean autoFit)
      Set if the panel has to fit the view when its resized.
      Parameters:
      autoFit - true if the panel fits the view when its resized and false otherwise.
      See Also:
    • getImage

      public BufferedImage getImage()
      Get the image that is displayed within the panel.
      Returns:
      the image that is displayed within the panel.
      See Also:
    • setImage

      public void setImage(BufferedImage image)
      Set the image to display within the panel.
      Parameters:
      image - the image to display within the panel.
      See Also:
    • getScale

      public double getScale()
      Get the current scale factor of the panel view.
      Returns:
      the current scale factor of the panel view.
      See Also:
    • setScale

      public void setScale(double zoom)
      Set the scale factor to apply to the panel view.
      Parameters:
      zoom - the current scale factor of the panel view.
      See Also:
    • getTranslation

      public Point2D getTranslation()
      Get the translation applied to the view as a 2D point.
      Returns:
      the translation applied to the view.
      See Also:
    • setTranslation

      public void setTranslation(Point2D translation)
      Set the translation to apply to the view.
      Parameters:
      translation - the translation to apply to the view as a 2D point.
      See Also:
    • fit

      public void fit()
      Fit the view in order to display the whole image. This method update the view transformation (scale, translation) in order to make the whole image visible.
    • isLayerDisplayed

      public boolean isLayerDisplayed(String layer)
      Check if the given layer is displayed. If this method return true, then the features that are within the layer are visible on the image panel.
      Parameters:
      layer - the layer to check.
      Returns:
      true if the layer is displayed and false otherwise.
      See Also:
    • setLayerDisplayed

      public void setLayerDisplayed(String layer, boolean displayed)
      Set if the given layer has to be displayed.
      Parameters:
      layer - the layer to check.
      displayed - true if the layer has to be displayed and false otherwise.
    • getImageFeatures

      public List<JImageFeature> getImageFeatures(String layer)
      Get the image features contained within the specified layer attached to this panel.
      Parameters:
      layer - the layer of the features.
      Returns:
      the image features attached to this panel and null if the layer is empty or does not exists.
      See Also:
    • setImageFeatures

      public void setImageFeatures(String layer, List<JImageFeature> features)
      Set the image features to attach to this panel within the specified layer. If the layer does not exist, it is created. In this case, the layer will not be displayed until a call to setLayerDisplayed(layer, true). If the layer exists, all previous existing features are deleted.
      Parameters:
      layer - the layer of the features.
      features - the image features attached to attach to this panel.
      See Also:
    • addImageFeature

      public boolean addImageFeature(String layer, JImageFeature feature)
      Attach the given image feature to this panel within the specified layer. If the layer does not exist, it is created. In this case, the layer will not be displayed until a call to setLayerDisplayed(layer, true).
      Parameters:
      layer - the layer of the feature.
      feature - the image feature to attach.
      Returns:
      true if the feature is successfully attached and false otherwise.
      See Also:
    • removeImageFeature

      public boolean removeImageFeature(String layer, JImageFeature feature)
      Remove the given image feature from the specified layer.
      Parameters:
      layer - the layer of the feature.
      feature - the image feature to remove.
      Returns:
      true if the feature is successfully removed and false otherwise.
      See Also:
    • getImageCoordinate

      public Point2D getImageCoordinate(int x, int y)
      Get the coordinate within the image referential of the point located at (x, y) on the panel component.
      Parameters:
      x - the x coordinate of the point on the panel component.
      y - the y coordinate of the point on the panel component.
      Returns:
      the coordinate within the image of the point located at (x, y) on the panel component.
      See Also:
    • getViewCoordinate

      public Point2D getViewCoordinate(float x, float y)
      Get the coordinate within the view referential of the point located at (x, y) on the image.
      Parameters:
      x - the x coordinate of the point on the image.
      y - the y coordinate of the point on the image.
      Returns:
      the coordinate within the view referential of the point located at (x, y) on the image.
      See Also: