com.vistech.imageviewer
Class ImageCanvas2D

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.vistech.imageviewer.ImageCanvas
                          |
                          +--com.vistech.imageviewer.ImageCanvas2D
All Implemented Interfaces:
ImageDisplay, ImageManipulator, java.awt.image.ImageObserver, ImagePrint, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable
Direct Known Subclasses:
CompositeCanvas2D

public class ImageCanvas2D
extends ImageCanvas
implements ImageManipulator

Displays a manipulated image. This class doesn't perform image manipulation, but has several properties to hold the manipulation attributes. To manipulate an image, check out the AffineTransform attribute, concatenate it, and then check it in. Call the applyTransform() method to apply the resultinng transformation to the current image.

Version:
1.0 18 Nov 1999
Author:
Lawrence Rodrigues
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.awt.geom.AffineTransform atx
           
protected  java.awt.geom.AffineTransform dispModeAtx
           
protected  java.awt.geom.AffineTransform flipAtx
           
protected  int interpolationType
           
protected  int magCenterX
           
protected  int magCenterY
           
protected  double magFactor
           
protected  boolean magOn
           
protected  java.awt.Point panOffset
           
protected  boolean rotateOn
           
protected  double rotationAngle
           
protected  int rotationCenterX
           
protected  int rotationCenterY
           
protected  double shearFactor
           
protected  boolean shearOn
           
protected  double shearX
           
protected  double shearY
           
protected  java.awt.Point zoomOffset
           
 
Fields inherited from class com.vistech.imageviewer.ImageCanvas
bufferedImage, clipShape, dispGc, displayImage, displayMode, flipMode, height, imageHeight, imageType, imageWidth, invertOn, offScrGc, offScrImage, originalImageType, paintFlag, PRINT_SIZE_ACTUAL, PRINT_SIZE_PAGE, printLoc, printMode, printSize, width
 
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 com.vistech.imageviewer.ImageDisplay
TYPE_AWT_IMAGE, TYPE_BUFFERED_IMAGE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageCanvas2D()
           
 
Method Summary
 void applyTransform(java.awt.geom.AffineTransform atx)
          Applies a specified transformation to the current off screen image, and then displays it on the canvas.
protected  void applyTransform(java.awt.image.BufferedImage bi, java.awt.geom.AffineTransform atx)
          Applies a specified transformation to an input image, and then displays it on the canvas
static java.awt.geom.AffineTransform createFlipTransform(int mode, int imageWid, int imageHt)
          Creates a flip transform.
 boolean doDisplayModeAndFlip(int imageWidth, int imageHeight)
          Applies the current display mode and flip mode settings to the displayed image.
 int getInterpolationType()
           
 double getMagFactor()
          Gets the magFactor property.
 boolean getMagOn()
           
 java.awt.Point getPanOffset()
          Returns the panOffset property.
 double getRotationAngle()
          Gets the rotation angle property.
 double getShearFactor()
           
 double getShearFactorX()
           
 double getShearFactorY()
           
 java.awt.geom.AffineTransform getTransform()
          Gets the transform property.
protected  void init()
           
static void main(java.lang.String[] args)
           
 void reset()
          Paints the currently displayed image again with currently set display and flip modes
 void resetManipulation()
          Resets the manipulation attributes.
 void setInterpolationType(int interType)
          Sets the interpolationType property.
 void setMagFactor(double magFactor)
          Sets the magFactor property.
 void setMagOn(boolean onOff)
           
 void setPanOffset(java.awt.Point panOffset)
          Gets the panOffset property.
 void setRotationAngle(double rotationAngle)
          Sets the rotationAngle property.
 void setShearFactor(double shearFactor)
          Sets the shearFactor property.
 void setTransform(java.awt.geom.AffineTransform at)
          Sets the transform property.
 
Methods inherited from class com.vistech.imageviewer.ImageCanvas
addImageSentListener, clearImageCanvas, convertToAWTImage, convertToBufferedImage, createDisplayImage, doFlip, doFlip, draw, drawingDim, fireImageSentEvents, getAWTImage, getBufferedImage, getDisplayedImage, getDisplayedImageGC, getDisplayMode, getFlipMode, getImageSize, getImageType, getInvert, getOffScreenImage, getPreferredSize, getPrintLocation, getPrintSize, imageUpdate, invert, paintComponent, paintImage, print, printImage, redraw, removeImageSentListener, setAWTImage, setBufferedImage, setClip, setDisplayImage, setDisplayMode, setFlipMode, setImageType, setInvert, setOffScreenImage, setOffScrGc, setPrintLocation, setPrintSize
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vistech.imageviewer.ImageDisplay
addMouseListener, addMouseMotionListener, addPropertyChangeListener, addVetoableChangeListener, draw, getAWTImage, getBufferedImage, getDisplayedImage, getDisplayMode, getFlipMode, getImageSize, getImageType, getInvert, getOffScreenImage, paintImage, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removeVetoableChangeListener, setAWTImage, setBufferedImage, setClip, setCursor, setDisplayImage, setDisplayMode, setFlipMode, setImageType, setInvert, setOffScreenImage
 

Field Detail

atx

protected java.awt.geom.AffineTransform atx

dispModeAtx

protected java.awt.geom.AffineTransform dispModeAtx

flipAtx

protected java.awt.geom.AffineTransform flipAtx

panOffset

protected java.awt.Point panOffset

magOn

protected boolean magOn

magFactor

protected double magFactor

magCenterX

protected int magCenterX

magCenterY

protected int magCenterY

zoomOffset

protected java.awt.Point zoomOffset

rotationAngle

protected double rotationAngle

rotateOn

protected boolean rotateOn

rotationCenterX

protected int rotationCenterX

rotationCenterY

protected int rotationCenterY

shearOn

protected boolean shearOn

shearFactor

protected double shearFactor

shearX

protected double shearX

shearY

protected double shearY

interpolationType

protected int interpolationType
Constructor Detail

ImageCanvas2D

public ImageCanvas2D()
Method Detail

init

protected void init()
Overrides:
init in class ImageCanvas

setMagFactor

public void setMagFactor(double magFactor)
Description copied from interface: ImageManipulator
Sets the magFactor property.
Specified by:
setMagFactor in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
magFactor - the magnification factor.

getMagFactor

public double getMagFactor()
Description copied from interface: ImageManipulator
Gets the magFactor property.
Specified by:
getMagFactor in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Returns:
the magFactor.

setShearFactor

public void setShearFactor(double shearFactor)
Description copied from interface: ImageManipulator
Sets the shearFactor property.
Specified by:
setShearFactor in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
shearFactor - the shearFactor property.

getShearFactor

public double getShearFactor()
Specified by:
getShearFactor in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Returns:
the shearFactor.

getShearFactorX

public double getShearFactorX()

getShearFactorY

public double getShearFactorY()

setRotationAngle

public void setRotationAngle(double rotationAngle)
Description copied from interface: ImageManipulator
Sets the rotationAngle property.
Specified by:
setRotationAngle in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
rotationAngle - the rotation angle

getRotationAngle

public double getRotationAngle()
Description copied from interface: ImageManipulator
Gets the rotation angle property.
Specified by:
getRotationAngle in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Returns:
the rotation angle.

setPanOffset

public void setPanOffset(java.awt.Point panOffset)
Description copied from interface: ImageManipulator
Gets the panOffset property.
Specified by:
setPanOffset in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
panOffset - the offset by which the currently displayed image is moved from the previous position.

getPanOffset

public java.awt.Point getPanOffset()
Description copied from interface: ImageManipulator
Returns the panOffset property.
Specified by:
getPanOffset in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Returns:
the panOffset.

setInterpolationType

public void setInterpolationType(int interType)
Description copied from interface: ImageManipulator
Sets the interpolationType property.
Specified by:
setInterpolationType in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
the - interpolation type

getInterpolationType

public int getInterpolationType()
Specified by:
getInterpolationType in interface ImageManipulator

getTransform

public java.awt.geom.AffineTransform getTransform()
Description copied from interface: ImageManipulator
Gets the transform property.
Specified by:
getTransform in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Returns:
the current transform object.

setTransform

public void setTransform(java.awt.geom.AffineTransform at)
Description copied from interface: ImageManipulator
Sets the transform property.
Specified by:
setTransform in interface ImageManipulator
Following copied from interface: com.vistech.imageviewer.ImageManipulator
Parameters:
the - transform.

setMagOn

public void setMagOn(boolean onOff)

getMagOn

public boolean getMagOn()

doDisplayModeAndFlip

public boolean doDisplayModeAndFlip(int imageWidth,
                                    int imageHeight)
Applies the current display mode and flip mode settings to the displayed image. The display mode and flip mode settings are applied by using the affine transformation. First computes an affine transformation for current display mode setting. It then creates a BufferedImage object size of which is compted using this transformation, and draws the current image on this BufferedImage. This method then calls the createFlipTransform() method to create an affine transformtion for the current flip mode setting. It then applies the flips transforamtion to the BufferedImage object, and then displays it.
Overrides:
doDisplayModeAndFlip in class ImageCanvas
Parameters:
imWid - the image width.
imHt - the image height.

createFlipTransform

public static java.awt.geom.AffineTransform createFlipTransform(int mode,
                                                                int imageWid,
                                                                int imageHt)
Creates a flip transform. It first creates a reflection and then translates to the current quadrant.
Parameters:
mode - the specified flip mode.
imageWid - the width of the BufferedImage.
imageHt - the height of the BufferedImage.
Returns:
the flip transformation encapsulated in the AffineTransform object.

applyTransform

protected void applyTransform(java.awt.image.BufferedImage bi,
                              java.awt.geom.AffineTransform atx)
Applies a specified transformation to an input image, and then displays it on the canvas
Parameters:
bi - the buffered image to which the transformation is applied.
atx - the transformation to be applied.

applyTransform

public void applyTransform(java.awt.geom.AffineTransform atx)
Applies a specified transformation to the current off screen image, and then displays it on the canvas.
Specified by:
applyTransform in interface ImageManipulator
Parameters:
atx - the transformation to be applied.

reset

public void reset()
Description copied from class: ImageCanvas
Paints the currently displayed image again with currently set display and flip modes
Overrides:
reset in class ImageCanvas

resetManipulation

public void resetManipulation()
Resets the manipulation attributes. Applies the default attributes to display the current image.
Specified by:
resetManipulation in interface ImageManipulator

main

public static void main(java.lang.String[] args)