public final class ImageViewer extends Object
resize strategy property. It can also provide a popup menu
containing generally useful viewing controls and functions; this default popup can be disabled by passing
defaultPopupMenu = null to the constructor.
The Swing component that can be added to the GUI is obtained by calling
getComponent().
ImageViewer supports status bars: arbitrary
components that can be added to the viewer and are displayed below the image.
Overlays can also be added to the viewer; for details, see
the the documentation of the Overlay class.
| Constructor and Description |
|---|
ImageViewer()
Creates a new image viewer.
|
ImageViewer(BufferedImage image)
Creates a new image viewer displaying the specified image.
|
ImageViewer(BufferedImage image,
boolean defaultPopupMenu)
Creates a new image viewer displaying the specified image.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addImageMouseClickListener(ImageMouseClickListener l)
Adds the specified image mouse listener to this viewer.
|
void |
addImageMouseMotionListener(ImageMouseMotionListener l)
Adds the specified image mouse motion listener to this viewer.
|
void |
addMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from
the image component of this image viewer.
|
void |
addMouseMotionListener(MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse events from
the image component of this image viewer.
|
void |
addOverlay(Overlay overlay)
Adds an overlay to layer 1.
|
void |
addOverlay(Overlay overlay,
int layer)
Adds an overlay as the specified layer.
|
void |
addPropertyChangeListener(PropertyChangeListener l)
Adds a
PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener(String name,
PropertyChangeListener l)
Adds a
PropertyChangeListener for a specific property. |
JComponent |
getComponent()
Returns the image viewer component that can be displayed.
|
BufferedImage |
getImage()
Returns the currently displayed image.
|
AffineTransform |
getImageTransform()
Returns the transformation that is applied to the image.
|
Object |
getInterpolationType()
Returns the current interpolation type.
|
ResizeStrategy |
getResizeStrategy()
Returns the current resize strategy.
|
StatusBar |
getStatusBar()
Returns the status bar currently associated with this viewer.
|
double |
getZoomFactor()
Returns the zoom factor used when resize strategy is CUSTOM_ZOOM.
|
boolean |
isPixelatedZoom()
Returns the current pixelated zoom setting.
|
boolean |
isStatusBarVisible()
Returns whether the status bar is set to be visible.
|
Point |
pointToPixel(Point p,
boolean clipToImage)
Returns the image pixel corresponding to the given point.
|
void |
removeImageMouseClickListener(ImageMouseClickListener l)
Removes the specified image mouse listener so that it no longer receives
mouse click events from the image component of this image viewer.
|
void |
removeImageMouseMotionListener(ImageMouseMotionListener l)
Removes the specified image mouse motion listener so that it no longer receives
mouse motion events from the image component of this image viewer.
|
void |
removeMouseListener(MouseListener l)
Removes the specified mouse listener so that it no longer receives
mouse motion events from the image component of this image viewer.
|
void |
removeMouseMotionListener(MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer receives
mouse motion events from the image component of this image viewer.
|
void |
removeOverlay(Overlay overlay)
Removes an overlay from the image viewer.
|
void |
removePropertyChangeListener(PropertyChangeListener l)
Remove a
PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener(String name,
PropertyChangeListener l)
Remove a
PropertyChangeListener from the listener list. |
void |
setImage(BufferedImage image)
Sets the image displayed by the viewer.
|
void |
setInterpolationType(Object type)
Sets the interpolation type to use when resizing images.
|
void |
setPixelatedZoom(boolean pixelatedZoom)
Sets whether the image should be resized with nearest neighbor interpolation when it is expanded.
|
void |
setResizeStrategy(ResizeStrategy resizeStrategy)
Sets the resize strategy this viewer should use.
|
void |
setStatusBar(StatusBar statusBar)
Sets the status bar component for this image viewer.
|
void |
setStatusBarVisible(boolean statusBarVisible)
Sets whether the status bar is visible.
|
void |
setZoomFactor(double newZoomFactor)
Sets the zoom factor to use when the resize strategy is CUSTOM_ZOOM.
|
public ImageViewer()
public ImageViewer(BufferedImage image)
image - the image to display; if null then no image is displayedpublic ImageViewer(BufferedImage image, boolean defaultPopupMenu)
image - the image to display; if null then no image is displayeddefaultPopupMenu - if true, then a default popup menu will be created and registered for the viewersetImage(BufferedImage)public void setStatusBar(StatusBar statusBar)
statusBar is
null this method removes any existing status bar.statusBar - the new status bar component to setIllegalArgumentException - if the status bar has already been added to a
different image viewerpublic StatusBar getStatusBar()
null if the viewer has no status barpublic void setStatusBarVisible(boolean statusBarVisible)
statusBarVisible - true, if the status bar should be visible; false otherwisepublic boolean isStatusBarVisible()
public JComponent getComponent()
public void setImage(BufferedImage image)
image - the new image to display; if null then no image is displayedpublic BufferedImage getImage()
null if no image is displayedpublic void setResizeStrategy(ResizeStrategy resizeStrategy)
ResizeStrategy.SHRINK_TO_FIT.resizeStrategy - the new resize strategypublic ResizeStrategy getResizeStrategy()
ResizeStrategy.SHRINK_TO_FIT.public void setPixelatedZoom(boolean pixelatedZoom)
false.pixelatedZoom - the new value of the pixelatedZoom propertypublic boolean isPixelatedZoom()
false.public Object getInterpolationType()
RenderingHints.VALUE_INTERPOLATION_BICUBIC.setInterpolationType(Object)public void setInterpolationType(Object type)
RenderingHints.KEY_INTERPOLATION
for details. The default value is RenderingHints.VALUE_INTERPOLATION_BICUBIC.
The allowed values are:
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR
RenderingHints.VALUE_INTERPOLATION_BILINEAR
RenderingHints.VALUE_INTERPOLATION_BICUBIC (default)
Note: when the pixelatedZoom property is set to true and the image is enlarged, then the nearest
neighbor method is used regardless of this setting.
type - the interpolation type to use when resizing imagesIllegalArgumentException - if the parameter is not one of the allowed valuespublic double getZoomFactor()
public void setZoomFactor(double newZoomFactor)
Note that calling this function does not change the current resize strategy.
newZoomFactor - the new zoom factor for the CUSTOM_ZOOM strategyIllegalArgumentException - if newZoomFactor is not a positive numberpublic AffineTransform getImageTransform()
The AffineTransform
instance returned by this method should not be modified.
IllegalStateException - if there is no image set or if the size of the viewer is 0 (for example because
it is not in a visible component)public void addOverlay(Overlay overlay, int layer)
overlay - the overlay to addlayer - the layer to add the overlay to; higher layers are on top of lower layers;
the image resides in layer 0public void addOverlay(Overlay overlay)
overlay - the overlay to addpublic void removeOverlay(Overlay overlay)
overlay - the overlay to removeIllegalArgumentException - if the overlay is not in the image viewerpublic void addMouseListener(MouseListener l)
l
is null, no exception is thrown and no action is performed.l - the mouse listenerpublic void removeMouseListener(MouseListener l)
l is null, no exception is thrown and no action is
performed.l - the mouse motion listenerpublic void addMouseMotionListener(MouseMotionListener l)
l
is null, no exception is thrown and no action is performed.l - the mouse listenerpublic void removeMouseMotionListener(MouseMotionListener l)
l is null, no exception is thrown and no action is
performed.l - the mouse motion listenerpublic void addImageMouseMotionListener(ImageMouseMotionListener l)
l
is null, no exception is thrown and no action is performed.l - the image mouse motion listenerpublic void removeImageMouseMotionListener(ImageMouseMotionListener l)
l is null, no exception is thrown and no action is
performed.l - the mouse motion listenerpublic void addImageMouseClickListener(ImageMouseClickListener l)
l
is null, no exception is thrown and no action is performed.l - the image mouse motion listenerpublic void removeImageMouseClickListener(ImageMouseClickListener l)
l is null, no exception is thrown and no action is
performed.l - the mouse motion listenerpublic void addPropertyChangeListener(PropertyChangeListener l)
PropertyChangeListener to the listener list.
The same listener object may be added more than once, and will be
called as many times as it is added. If the listener is null,
no exception is thrown and no action is taken.l - the listener to be addedpublic void removePropertyChangeListener(PropertyChangeListener l)
PropertyChangeListener from the listener list.
This removes a listener that was registered for all properties.
If the listener was added more than once, it will be notified
one less time after being removed. If the listener is null,
or was never added, no exception is thrown and no action is taken.l - the listener to removepublic void addPropertyChangeListener(String name, PropertyChangeListener l)
PropertyChangeListener for a specific property. The listener
will be invoked only when a call on firePropertyChange names that specific property.
The same listener object may be added more than once. For each property,
the listener will be invoked the number of times it was added for that property.
If the property name or the listener is null, no exception is thrown and no action is taken.name - the name of the property to listen onl - the listener to addpublic void removePropertyChangeListener(String name, PropertyChangeListener l)
PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered for all properties.
If the listener was added more than once,
it will be notified one less time after being removed. If the listener is null,
or was never added, no exception is thrown and no action is taken.name - the name of the property that was listened onl - the listener to removepublic Point pointToPixel(Point p, boolean clipToImage)
clipToImage
parameter is false, then the function will return an appropriately positioned
pixel on an infinite plane, even if the point is outside the image bounds. If
clipToImage is true then the function will return null
for such positions, and any non-null return value will be a valid image pixel.p - a point in component coordinate systemclipToImage - whether the function should return null for positions outside
the image boundsIllegalStateException - if there is no image set or if the size of the viewer is 0 (for example because
it is not in a visible component)Copyright © 2012. All Rights Reserved.