Class ImagePanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ImagePanel extends JComponent
Displays images on a panel.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland.
See Also:
  • Field Details

    • IGNORE_PIXEL_ASPECT

      public static final int IGNORE_PIXEL_ASPECT
      Pixel aspect policy: Ignore pixel aspect.
      See Also:
    • ROUNDED_PIXEL_ASPECT

      public static final int ROUNDED_PIXEL_ASPECT
      Pixel aspect policy: Preserves only extreme pixel aspects, where one dimension is a multiple of the other dimension.
      See Also:
    • EXACT_PIXEL_ASPECT

      public static final int EXACT_PIXEL_ASPECT
      Pixel aspect policy: Preserve the exact pixel aspect.
      See Also:
    • ANAMORPH_PIXEL_ASPECT

      public static final int ANAMORPH_PIXEL_ASPECT
      Pixel aspect policy: Use Anamoprh 16:9 pixel aspect (=16/9*4/5=1.4222).
      See Also:
    • SCALE_TO_IMAGE_SIZE

      public static final int SCALE_TO_IMAGE_SIZE
      Image scaling policy: Scale as defined by #setAspectRatio and the image aspect.
      See Also:
    • SCALE_TO_VIEW_SIZE

      public static final int SCALE_TO_VIEW_SIZE
      Image scaling policy: Scale to panel size.
      See Also:
    • SCALE_TO_IMAGE_ASPECT

      public static final int SCALE_TO_IMAGE_ASPECT
      Image scaling policy: Scale to panel but keep the image aspect.
      See Also:
  • Constructor Details

    • ImagePanel

      public ImagePanel()
  • Method Details

    • paintComponent

      public void paintComponent(Graphics gr)
      Overrides:
      paintComponent in class JComponent
    • setPixelAspectPolicy

      public void setPixelAspectPolicy(int policy)
      Sets the pixel aspect policy.
      Parameters:
      policy - PixelAspectPolicy must be one of IGNORE_PIXEL_ASPECT, ROUNDED_PIXEL_ASPECT, EXACT_PIXEL_ASPECT.
      Throws:
      IllegalArgumentException - When passing invalid policy.
    • getPixelAspectPolicy

      public int getPixelAspectPolicy()
      Returns the pixel aspect policy.
    • setImageScalePolicy

      public void setImageScalePolicy(int policy)
      Sets the image scale policy.
    • getImageScalePolicy

      public int getImageScalePolicy()
      Returns the image scale policy.
    • getPixelAspectX

      public double getPixelAspectX()
      Gets the horizontal pixel aspect of the image according to the pixel aspect policy that is in affect.
      Returns:
      Horizontal pixel aspect.
    • getPixelAspectY

      public double getPixelAspectY()
      Gets the vertical pixel aspect of the image according to the pixel aspect policy that is in effect.
      Returns:
      Vertical pixel aspect.
    • getPreferredImageSize

      public Dimension getPreferredImageSize()
      Gets the preferred image size.
      Returns:
      Image dimension after applying the pixel aspect policy.
    • getScaledImageSize

      public Dimension getScaledImageSize()
      Gets the scaled and pixel aspect corrected image size.
      Returns:
      Image dimension after scaling and applying the pixel aspect policy.
    • setImage

      public void setImage(Image image)
      Sets the image and displays it in this image panel.
    • getImage

      public Image getImage()
      Gets the image that is displayed in this image panel.
      Returns:
      image.
    • setTexture

      public void setTexture(BufferedImage newValue)
      Sets the texture for the backdrop paint.
    • getTexture

      public BufferedImage getTexture()
      Gets the backdrop paint.
    • setScaleFactor

      public void setScaleFactor(double scaleFactor)
      Sets the scale factor. The scale factor scales images shown in this image panel.
      Parameters:
      scaleFactor - The scale factor.
    • getScaleFactor

      public double getScaleFactor()
      Gets the scale factor.
      Returns:
      Scale factor.
    • setRenderingHints

      public void setRenderingHints(RenderingHints newValue)
      Sets the rendering hints.
      Parameters:
      newValue - The new rendering hints.
    • getRenderingHints

      public RenderingHints getRenderingHints()
      Gets the rendering hints.
      Returns:
      Rendering Hints.
    • setAspectRatio

      public void setAspectRatio(double ratioX, double ratioY)
      Sets the aspect ratio. The aspect ratio distorts images shown in this image panel.
      Parameters:
      ratioX - Horizontal scale factor.
      ratioY - Vertical scale factor.
    • setAspectRatio0

      protected void setAspectRatio0(double ratioX, double ratioY)
    • getAspectRatioX

      public double getAspectRatioX()
      Gets the horizontal scale factor that is used to scale images shown in this image panel.
      Returns:
      Horizontal scale factor.
    • getAspectRatioY

      public double getAspectRatioY()
      Gets the vertical scale factor that is used to scale images shown in this image panel.
      Returns:
      Vertical scale factor.
    • getPreferredSize

      public Dimension getPreferredSize()
      Gets the preferred size of this image panel. The preferred size depends on the image size, the scale factor and the pixel aspect policy.
      Overrides:
      getPreferredSize in class JComponent
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Adds a listener who is interested in changes of this object.
      Overrides:
      addPropertyChangeListener in class Container
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Removes a previously registered listener.
      Overrides:
      removePropertyChangeListener in class Component
    • setMessage

      public void setMessage(String message)
    • imageUpdate

      public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
      XXX Netscape gets very slow when painting all SOMEBITS of an image.
      Specified by:
      imageUpdate in interface ImageObserver
      Overrides:
      imageUpdate in class Component