jj2000.disp
Class ImgScrollPane.ImageScrollDisplay

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--jj2000.disp.ImgScrollPane.ImageScrollDisplay
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Enclosing class:
ImgScrollPane

private class ImgScrollPane.ImageScrollDisplay
extends java.awt.Canvas

This class implements the component that displays the currently viewable image portion inside the ImgScrollPane. It handles the necessary erasing, zooming and panning.

NOTE: extending 'Canvas' instead of 'Component' solves the flickering problem of lightweight components which are in heavyweight containers.


Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  java.awt.Dimension dim
          The preferred size for this component
(package private)  int dimFlags
          The image dimension flags, as in ImageObserver.
(package private)  boolean erase
          If the current graphics context should be erased prior to drawing the image.
(package private)  java.awt.Image img
          The image to be displayed
(package private)  java.awt.Dimension imgDim
          The image dimensions, without any scaling.
(package private)  java.awt.Point lastUpdateOffset
          The last offset used in update().
 
Fields inherited from class java.awt.Canvas
 
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
private ImgScrollPane.ImageScrollDisplay()
           
 
Method Summary
(package private)  boolean calcDim()
          Calculates the image display dimensions according to the zoom and image size.
 java.awt.Dimension getMaximumSize()
          Returns the maximum size for this component, which is infinite.
 java.awt.Dimension getMinimumSize()
          Returns the minimum size for this component, which is (0,0).
 java.awt.Dimension getPreferredSize()
          Returns the preferred size for this component, which is the image display size, if known, the previous image display size, if any, or the size specified at the constructor.
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int w, int h)
          Monitors the image rendering for dimensions and calls the superclass' 'imageUpdate()' method.
 void paint(java.awt.Graphics g)
          Paints the image, if any, on the graphics context by calling update().
(package private)  void setImage(java.awt.Image img)
          Sets the image to display in this component.
 void update(java.awt.Graphics g)
          Updates the component by drawing the relevant part of the image that fits within the Graphics clipping area of 'g'.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

img

java.awt.Image img
The image to be displayed


dim

java.awt.Dimension dim
The preferred size for this component


erase

boolean erase
If the current graphics context should be erased prior to drawing the image. Set when the image and/or zoom factor is changed.


imgDim

java.awt.Dimension imgDim
The image dimensions, without any scaling. Set as soon as they are known.


dimFlags

int dimFlags
The image dimension flags, as in ImageObserver. The ImageObserver.WIDTH and ImageObserver.HEIGHT flags are set whenever the dimension is stored in imgDim. They are reset whenever the image changes.


lastUpdateOffset

java.awt.Point lastUpdateOffset
The last offset used in update().

Constructor Detail

ImgScrollPane.ImageScrollDisplay

private ImgScrollPane.ImageScrollDisplay()
Method Detail

setImage

void setImage(java.awt.Image img)
Sets the image to display in this component. If the image is not ready for display it will be prepared in the current thread. The current zoom factor applies.

If the image is not ready for display (i.e. it has not been rendered at its natural size) it will be rendered in the current thread, if not being already rendered in another one. This means that the current thread can block until the image is ready.

If the image is rendered incrementally (it depends on the underlying 'ImageProducer') it will be displayed in that way if the incremental display is set for the Component class. See the 'imageUpdate()' method of the 'Component' class.

If the image is the same as the current one nothing is done.

Parameters:
img - The image to display.
See Also:
Component.imageUpdate(java.awt.Image, int, int, int, int, int)

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size for this component, which is (0,0).

Overrides:
getMinimumSize in class java.awt.Component
Returns:
The minimum size

getMaximumSize

public java.awt.Dimension getMaximumSize()
Returns the maximum size for this component, which is infinite.

Overrides:
getMaximumSize in class java.awt.Component
Returns:
The maximum size

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size for this component, which is the image display size, if known, the previous image display size, if any, or the size specified at the constructor.

Overrides:
getPreferredSize in class java.awt.Component
Returns:
The preferred size for this component.

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int infoflags,
                           int x,
                           int y,
                           int w,
                           int h)
Monitors the image rendering for dimensions and calls the superclass' 'imageUpdate()' method. If the display size of the image is not yet known and the image dimensions are obtained, then the scrollbars' values are set. If 'img' is not the current image to display nothing is done and 'false' is returned indicating that nothing more is necessary for it.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component
See Also:
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int), Component.imageUpdate(java.awt.Image, int, int, int, int, int)

paint

public void paint(java.awt.Graphics g)
Paints the image, if any, on the graphics context by calling update().

Overrides:
paint in class java.awt.Canvas
Parameters:
g - The graphics context to paint on.

update

public void update(java.awt.Graphics g)
Updates the component by drawing the relevant part of the image that fits within the Graphics clipping area of 'g'. If the image is not already being prepared for rendering or is not already rendered this method does not start it. This is to avoid blocking the AWT threads for rendering the image. The image rendering is started by the 'setImage()' method.

Overrides:
update in class java.awt.Canvas
Parameters:
g - The graphics context where to draw
See Also:
setImage(java.awt.Image)

calcDim

boolean calcDim()
Calculates the image display dimensions according to the zoom and image size. The dimensions are stored in 'dim'.

Returns:
True if the dimensions could be calculated, false if not (i.e. not enough info is available).