jsky.image.gui
Class ImageDisplay

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by jsky.image.gui.ImageDisplay
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.swing.event.ChangeListener, BasicImageReadableProcessor, BasicImageDisplay

public class ImageDisplay
extends javax.swing.JComponent
implements BasicImageDisplay, javax.swing.event.ChangeListener

Implements a JAI (Java Advanced Imaging) based image display window. Any JAI PlanarImage can be displayed. Grayscale images may be displayed with false colors, depending on the ImageProcessor options specified. Coordinate conversion is supported, although, since this class is not intended to be the main image class, world coordinates are only supported if setWCS() is called to set the world coordinates information.

Version:
$Revision: 1.2 $
Author:
Allan Brighton
See Also:
MainImageDisplay, ImageZoom, ImagePanner, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageDisplay()
          Construct an image display widget.
ImageDisplay(ImageProcessor imageProcessor, java.lang.String name)
          Construct an image display widget with the given name to display the output of the given image processor.
ImageDisplay(java.lang.String name)
          Construct an image display widget with the given name.
 
Method Summary
 void addImageGraphicsHandler(ImageGraphicsHandler igh)
          Register as an image graphics handler.
 void clear()
          Clear the image display, freeing up any resources currently used by the image so that they can be garbage collected.
 javax.swing.JComponent getCanvas()
          Return the image canvas component.
 CoordinateConverter getCoordinateConverter()
          Return the object used to convert coordinates.
 javax.media.jai.PlanarImage getDisplayImage()
          Return the image being displayed (after image processing).
 javax.media.jai.PlanarImage getImage()
          Return the source image (before processing).
 int getImageHeight()
          Return the height of the source image in pixels
 ImageProcessor getImageProcessor()
          Return the image processor object.
 int getImageWidth()
          Return the width of the source image in pixels
 javax.media.jai.Interpolation getInterpolation()
          Return the interpolation object used to scale the image
 java.awt.geom.Point2D.Double getOrigin()
          Return the origin of the displayed image in canvas coordinates.
 float getPixelValue(java.awt.geom.Point2D.Double p, int band)
          Return the value of the pixel in the given band at the given user coordinates
 float getScale()
          Return the current scale (zoom factor) for the image.
 java.awt.RenderingHints getScaleHints()
          Return the optional rendering hints used for the image scale operation
 java.awt.geom.Rectangle2D.Double getVisibleArea()
          Return a rectangle describing the visible area of the image (in user coordinates).
 WorldCoordinateConverter getWCS()
          Return the object used to convert between image and world coordinates, or null if none was set.
 boolean isAutoCenterImage()
          Return true if the image is automatically centered when it is smaller than the window.
 boolean isClear()
          Return true if the image has been cleared.
 boolean isImmediateMode()
          Return true if immediate mode is turned on.
 boolean isInitialized()
          Return true if this widget has been initialized and is displaying an image.
 boolean isPrescaled()
          Return true if the image has been prescaled
 boolean isWCS()
          Return true if the image supports world coordinates (has the necessary keywords in the header).
static void main(java.lang.String[] args)
          test main: usage: java ImageDisplay .
 void paintComponent(java.awt.Graphics g)
          Paint the image onto a Graphics object.
 void removeImageGraphicsHandler(ImageGraphicsHandler igh)
          Unregister as an image graphics handler.
 void scaleToFit()
          Set the scaling factor so that the image will fit in the current window.
protected  void scaleToFit(int width, int height)
          Set the scaling factor so that the image will fit in a window of the given size.
 void setAutoCenterImage(boolean b)
          Set to true (default) to automatically center the image, if it is smaller than the window.
 void setImage(javax.media.jai.PlanarImage im)
          Set the image to display.
 void setImageProcessor(ImageProcessor imageProcessor)
          Set the image processor to use to get the image to display.
 void setImmediateMode(boolean b)
          Set to true if scrolling and other operations should update the image immediately, otherwise only on button release.
 void setInterpolation(javax.media.jai.Interpolation i)
          Set the interpolation object used to scale the image (a subclass of Interpolation, such as InterpolationNearest (default), or InterpolationBilinear (better, but slower)).
 void setOrigin(java.awt.geom.Point2D.Double origin)
          Set the origin of the image to display in canvas coordinates.
 void setPrescaled(boolean b)
          Set to true if the image being displayed has been prescaled (such as for a pan window or thumbnail image).
 void setScale(float scale)
          Set the scale (zoom factor) for the image.
 void setScale(float actualScale, float apparentScale)
          Set the scale (zoom factor) for the image, but lie about it later when asked.
 void setScaleHints(java.awt.RenderingHints hints)
          Set the optional rendering hints for the image scale operation
 void setWCS(WorldCoordinateConverter wcs)
          Set the object used to convert between image and world coordinates.
 void stateChanged(javax.swing.event.ChangeEvent ce)
          Called for changes in the image processor settings
 void updateImage()
          called when the image has changed to update the display
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImageDisplay

public ImageDisplay(ImageProcessor imageProcessor,
                    java.lang.String name)
Construct an image display widget with the given name to display the output of the given image processor.

Parameters:
imageProcessor - Object managing the image
name - name to associate with this instance

ImageDisplay

public ImageDisplay(java.lang.String name)
Construct an image display widget with the given name.

Parameters:
name - name to associate with this instance

ImageDisplay

public ImageDisplay()
Construct an image display widget.

Method Detail

setImageProcessor

public void setImageProcessor(ImageProcessor imageProcessor)
Set the image processor to use to get the image to display.

Specified by:
setImageProcessor in interface BasicImageDisplay

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent ce)
Called for changes in the image processor settings

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

getImageProcessor

public ImageProcessor getImageProcessor()
Return the image processor object.

Specified by:
getImageProcessor in interface BasicImageReadableProcessor
Specified by:
getImageProcessor in interface BasicImageDisplay
Returns:
The Object responsible for most image transformations that processes PlanarImages.
See Also:
PlanarImage

getImage

public javax.media.jai.PlanarImage getImage()
Return the source image (before processing).

Specified by:
getImage in interface BasicImageDisplay

getDisplayImage

public javax.media.jai.PlanarImage getDisplayImage()
Return the image being displayed (after image processing).

Specified by:
getDisplayImage in interface BasicImageDisplay

getCoordinateConverter

public CoordinateConverter getCoordinateConverter()
Return the object used to convert coordinates.

Specified by:
getCoordinateConverter in interface BasicImageDisplay

setImage

public void setImage(javax.media.jai.PlanarImage im)
Set the image to display.

Specified by:
setImage in interface BasicImageDisplay

getImageWidth

public int getImageWidth()
Return the width of the source image in pixels

Specified by:
getImageWidth in interface BasicImageDisplay

getImageHeight

public int getImageHeight()
Return the height of the source image in pixels

Specified by:
getImageHeight in interface BasicImageDisplay

clear

public void clear()
Clear the image display, freeing up any resources currently used by the image so that they can be garbage collected.


isClear

public boolean isClear()
Return true if the image has been cleared.


updateImage

public void updateImage()
called when the image has changed to update the display

Specified by:
updateImage in interface BasicImageDisplay

isWCS

public boolean isWCS()
Return true if the image supports world coordinates (has the necessary keywords in the header).

Specified by:
isWCS in interface BasicImageDisplay

getWCS

public WorldCoordinateConverter getWCS()
Return the object used to convert between image and world coordinates, or null if none was set.

Specified by:
getWCS in interface BasicImageDisplay

setWCS

public void setWCS(WorldCoordinateConverter wcs)
Set the object used to convert between image and world coordinates.

Specified by:
setWCS in interface BasicImageDisplay

setAutoCenterImage

public void setAutoCenterImage(boolean b)
Set to true (default) to automatically center the image, if it is smaller than the window.

Specified by:
setAutoCenterImage in interface BasicImageDisplay

isAutoCenterImage

public boolean isAutoCenterImage()
Return true if the image is automatically centered when it is smaller than the window.

Specified by:
isAutoCenterImage in interface BasicImageDisplay

paintComponent

public void paintComponent(java.awt.Graphics g)
Paint the image onto a Graphics object. The painting is performed tile-by-tile, and includes a grey region covering the unused portion of image tiles as well as the general background. At this point the image must be byte data.

Overrides:
paintComponent in class javax.swing.JComponent

addImageGraphicsHandler

public void addImageGraphicsHandler(ImageGraphicsHandler igh)
Register as an image graphics handler.

Specified by:
addImageGraphicsHandler in interface BasicImageDisplay

removeImageGraphicsHandler

public void removeImageGraphicsHandler(ImageGraphicsHandler igh)
Unregister as an image graphics handler.

Specified by:
removeImageGraphicsHandler in interface BasicImageDisplay

setOrigin

public void setOrigin(java.awt.geom.Point2D.Double origin)
Set the origin of the image to display in canvas coordinates.

Specified by:
setOrigin in interface BasicImageDisplay

getOrigin

public java.awt.geom.Point2D.Double getOrigin()
Return the origin of the displayed image in canvas coordinates.

Specified by:
getOrigin in interface BasicImageDisplay

getCanvas

public javax.swing.JComponent getCanvas()
Return the image canvas component.

Specified by:
getCanvas in interface BasicImageDisplay

setScale

public void setScale(float scale)
Set the scale (zoom factor) for the image. This also adjusts the origin so that the center of the image remains about the same.

Specified by:
setScale in interface BasicImageDisplay

setScale

public void setScale(float actualScale,
                     float apparentScale)
Set the scale (zoom factor) for the image, but lie about it later when asked. This method is needed when working with images that have been prescaled by the image reader, so that the correct coordinates can still be displayed.

Parameters:
actualScale - this is the scale value that is actually applied to the image data
apparentScale - this is the scale value that will be reported by getScale()

getScale

public float getScale()
Return the current scale (zoom factor) for the image.

Specified by:
getScale in interface BasicImageDisplay

setInterpolation

public void setInterpolation(javax.media.jai.Interpolation i)
Set the interpolation object used to scale the image (a subclass of Interpolation, such as InterpolationNearest (default), or InterpolationBilinear (better, but slower)).

Specified by:
setInterpolation in interface BasicImageDisplay

getInterpolation

public javax.media.jai.Interpolation getInterpolation()
Return the interpolation object used to scale the image

Specified by:
getInterpolation in interface BasicImageDisplay

getPixelValue

public float getPixelValue(java.awt.geom.Point2D.Double p,
                           int band)
Return the value of the pixel in the given band at the given user coordinates

Specified by:
getPixelValue in interface BasicImageDisplay

setPrescaled

public void setPrescaled(boolean b)
Set to true if the image being displayed has been prescaled (such as for a pan window or thumbnail image). If true, the scale value will only be used to calculate coordinate transformations, but the image will not actually be scaled.

Specified by:
setPrescaled in interface BasicImageDisplay

isPrescaled

public boolean isPrescaled()
Return true if the image has been prescaled

Specified by:
isPrescaled in interface BasicImageDisplay

setScaleHints

public void setScaleHints(java.awt.RenderingHints hints)
Set the optional rendering hints for the image scale operation

Specified by:
setScaleHints in interface BasicImageDisplay

getScaleHints

public java.awt.RenderingHints getScaleHints()
Return the optional rendering hints used for the image scale operation

Specified by:
getScaleHints in interface BasicImageDisplay

scaleToFit

protected void scaleToFit(int width,
                          int height)
Set the scaling factor so that the image will fit in a window of the given size.

Note that only integer scaling factors are used, for example 2, 1, 1/2, 1/3, etc., for performance reasons.


scaleToFit

public void scaleToFit()
Set the scaling factor so that the image will fit in the current window.

Note that only integer scaling factors are used, for example 2, 1, 1/2, 1/3, etc., for performance reasons.

Specified by:
scaleToFit in interface BasicImageDisplay

getVisibleArea

public java.awt.geom.Rectangle2D.Double getVisibleArea()
Return a rectangle describing the visible area of the image (in user coordinates).

Specified by:
getVisibleArea in interface BasicImageReadableProcessor
Specified by:
getVisibleArea in interface BasicImageDisplay
Returns:
User Coordinates of retangle. Note, this may be a a SuperRectangle if the PlanarImage is non-rectangular.

isInitialized

public boolean isInitialized()
Return true if this widget has been initialized and is displaying an image.

Specified by:
isInitialized in interface BasicImageDisplay

setImmediateMode

public void setImmediateMode(boolean b)
Set to true if scrolling and other operations should update the image immediately, otherwise only on button release.

Specified by:
setImmediateMode in interface BasicImageDisplay

isImmediateMode

public boolean isImmediateMode()
Return true if immediate mode is turned on.

Specified by:
isImmediateMode in interface BasicImageDisplay

main

public static void main(java.lang.String[] args)
test main: usage: java ImageDisplay .