Class ImagePanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ImagePanel extends JPanel
Creates a panel that displays an Image. Users may pan the image as desired and zoom the image according to specific zoom levels.
See Also:
  • Field Details

    • ZOOM_LEVELS

      public static final float[] ZOOM_LEVELS
    • ZOOM_FACTOR_INDEX_DEFAULT

      protected static final int ZOOM_FACTOR_INDEX_DEFAULT
    • zoomLevelIndex

      protected int zoomLevelIndex
    • DEFAULT_ZOOM_FACTOR

      public static final float DEFAULT_ZOOM_FACTOR
      See Also:
    • IMAGE_PROPERTY

      public static final String IMAGE_PROPERTY
      Property name that indicates the image displayed by this panel has changed
      See Also:
    • ZOOM_PROPERTY

      public static final String ZOOM_PROPERTY
      Property name that indicates the zoom level of the image has changed
      See Also:
    • DEFAULT_ZOOM_PROPERTY

      public static final String DEFAULT_ZOOM_PROPERTY
      Property name that indicates the default zoom level of the image has changed
      See Also:
    • TRANSLATION_PROPERTY

      public static final String TRANSLATION_PROPERTY
      Property name that indicates the image has been translated
      See Also:
  • Constructor Details

    • ImagePanel

      public ImagePanel()
      Create an empty NavigableImagePanel
    • ImagePanel

      public ImagePanel(Image image)
      Create an NavigableImagePanel with the specified image
      Parameters:
      image - the image
  • Method Details

    • setImage

      public void setImage(Image image)
      Set the image this panel should display
      Parameters:
      image - the new image to display
    • getImage

      public Image getImage()
      Get the currently-displayed image
      Returns:
      the current image
    • setImageBackgroundColor

      public void setImageBackgroundColor(Color color)
      Set the background color of the panel. If the specified color is null, the default color for panel backgrounds is used.
      Parameters:
      color - the new background color
    • getImageBackgroundColor

      public Color getImageBackgroundColor()
      Get the current background color of this panel
      Returns:
      the background color
    • setText

      @Deprecated(since="10.2", forRemoval=true) public void setText(String text)
      Deprecated, for removal: This API element is subject to removal in a future version.
      unused
      Unused
      Parameters:
      text - unused
    • getText

      @Deprecated(since="10.2", forRemoval=true) public String getText()
      Deprecated, for removal: This API element is subject to removal in a future version.
      unused
      Unused
      Returns:
      unused
    • getZoomFactor

      public float getZoomFactor()
      Get the current zoom factor the image is being drawn to
      Returns:
      the image magnification factor
    • setZoomFactor

      public void setZoomFactor(float zoom)
      Set the magnification factor of the image. The zoom parameter is aligned to the nearest pre-configured magnification factor, rounding down for zoom factors less than 1.0, and up for factors greater than 1.0. Zoom factors outside the pre-configured range are limited to the nearest range extent.
      Parameters:
      zoom - the zoom
    • getDefaultZoomFactor

      public float getDefaultZoomFactor()
      Get the default zoom factory
      Returns:
      the zoom factor
    • setDefaultZoomFactor

      public void setDefaultZoomFactor(float zoom)
      Set the default zoom level, adhering to the same set of constrains as setZoomFactor(float)
      Parameters:
      zoom - the zoom
      See Also:
    • resetZoom

      public void resetZoom()
    • canZoomIn

      public boolean canZoomIn()
      Determine if the image can zoom in further based on current magnification levels
      Returns:
      True if magnification steps are available, false otherwise
    • zoomIn

      public void zoomIn()
      Enlarge the image about the image center
    • zoomIn

      public void zoomIn(Point center)
      Enlarge the image about the given point
      Parameters:
      center - location to enlarge the image around
    • canZoomOut

      public boolean canZoomOut()
      Determine if the image can zoom out further based on current magnification levels
      Returns:
      True if (de-)magnification steps are available, false otherwise
    • zoomOut

      public void zoomOut()
      Shrink the image about the image center
    • zoomOut

      public void zoomOut(Point center)
      Shrink the image about the given point
      Parameters:
      center - location to shrink the image around
    • isImageZoomEnabled

      public boolean isImageZoomEnabled()
    • setImageZoomEnabled

      public void setImageZoomEnabled(boolean enabled)
    • resetImageTranslation

      public void resetImageTranslation()
      Move the image back to the center. Zoom factor is unmodified.
    • isTranslated

      public boolean isTranslated()
      Determine if the image has been moved from its original location
      Returns:
      True if the image has moved, false otherwise
    • getTranslation

      public Point getTranslation()
      Get the X-Y distance the image has moved
      Returns:
      the X-Y distances the image has moved
    • isImageTranslationEnabled

      public boolean isImageTranslationEnabled()
    • setImageTranslationEnabled

      public void setImageTranslationEnabled(boolean enabled)