JIGL
v1.6

jigl.gui
Class ImageCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--jigl.gui.ImageCanvas
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class ImageCanvas
extends Canvas

ImageCanvas is a class made to facilitate the displaying of a JIGL image. ImageCanvas also easily supports a highlight box when active and a mouse drawn selection box. These options can be turned on or off with the showSelectionBox() and showActiveBox() methods. The options are meant to be used with the MouseListener and MouseMotionListener methods,and can be used as in the example code (demonstrating the selecton box):

Supports JIGL images, Java images (.gif, .jpg, .jpeg),and PPM images (.ppm, .pgm, .pbm).

 //MouseListener method
 public void mousePressed(MouseEvent e)
 {
         if (e.getComponent() instanceof jigl.gui.ImageCanvas)
         {
                 jigl.gui.ImageCanvas canvas = (jigl.gui.ImageCanvas)e.getComponent();
                 canvas.clearSelectionBox();
                 canvas.setSelectionBoxAnchor(e.getX(),e.getY());
         }
 }
 
 //MouseMotionListener method
 public void mouseDragged(MouseEvent e)
 {
         if (e.getComponent() instanceof jigl.gui.ImageCanvas)
         {
                 jigl.gui.ImageCanvas canvas = (jigl.gui.ImageCanvas)e.getComponent();
                 canvas.setSelectionBoxExtent(e.getX(),e.getY());
         }
 }
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  Image image
          Java image
protected  Image jimage
          JIGL image
private  Color m_activeColor
           
private  boolean m_bIsActive
           
private  int m_boxlx
           
private  int m_boxly
           
private  int m_boxux
           
private  int m_boxuy
           
private  boolean m_bShowActive
           
private  boolean m_bShowSelectionBox
           
 
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
ImageCanvas()
          Creates an empty ImageCanvas
ImageCanvas(ColorImage image)
          Creates an ImageCanvas from a ColorImage
ImageCanvas(ComplexImage image)
          Creates an ImageCanvas from a ComplexImage
ImageCanvas(GrayImage image)
          Creates an ImageCanvas from a GrayImage
ImageCanvas(Image image)
          Creates an ImageCanvas from a JIGL Image
ImageCanvas(RealColorImage image)
          Creates an ImageCanvas from a RealColorImage
ImageCanvas(RealGrayImage image)
          Creates an ImageCanvas from a RealGrayImage
 
Method Summary
 void clearSelectionBox()
          Clears the selection box.
private  void drawActiveBox(Graphics g)
          Draw the active box.
private  void drawBox(Graphics g, int ux, int uy, int lx, int ly)
          Draw a rectangle.
 Image getImage()
          Returns the JIGL image
 Image getJavaImage()
          Returns the Java image
 Image getJavaImage(Image img)
          Takes a jigl image as input, converts it to a java image, and returns the java image.
 Rectangle getSelectionBox()
          Returns the selection box in a Rectangle object.
 int getSelectionBoxAnchorX()
          Returns the upper x (anchor) coordinate of the selection box.
 int getSelectionBoxAnchorY()
          Returns the upper y (anchor) coordinate of the selection box.
 int getSelectionBoxExtentX()
          Rturns the lower x (extent) coordinate of the selection box.
 int getSelectionBoxExtentY()
          Returns the lower y (extent) coordinate of the selection box.
 int imHeight()
          Returns the image height
 int imWidth()
          Returns the image width
 void paint(Graphics g)
          Overrides the paint method for smoother redraw
 void setActive(boolean active)
          Sets whether or not the image is active.
 void setActiveColor(Color color)
          Sets the color used to highlight the image when active (default is blue).
 void setImage(Image image)
          Sets the Java image to image and JIGL Image to null
 void setImage(Image image)
          Sets the JIGL Image and Java Image to image
 Graphics setOffScreen()
          Returns an instance of Graphics that, when modified, modifies the Java image
 Graphics setOffScreen(double xfactor, double yfactor)
          Returns an instance of Graphics that, when modified, modifies the Java image
 void setSelectionBoxAnchor(int ux, int uy)
          Sets the upper corner of the selection box (ux and uy).
 void setSelectionBoxExtent(int lx, int ly)
          Sets the lower corner of the selection box (lx and ly).
 void setVisible(boolean b)
          Overrides Component.setVisible(boolean)
 void showActiveBox(boolean b)
          Sets whether or not the image is highlighted with a border when activated.
 void showSelectionBox(boolean b)
          Sets whether or not selection box is displayed.
 void update(Graphics g)
          Repaints the ImageCanvas.
 
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, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, 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, 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

image

protected Image image
Java image


jimage

protected Image jimage
JIGL image


m_bShowSelectionBox

private boolean m_bShowSelectionBox

m_bShowActive

private boolean m_bShowActive

m_bIsActive

private boolean m_bIsActive

m_activeColor

private Color m_activeColor

m_boxlx

private int m_boxlx

m_boxly

private int m_boxly

m_boxux

private int m_boxux

m_boxuy

private int m_boxuy
Constructor Detail

ImageCanvas

public ImageCanvas()
Creates an empty ImageCanvas


ImageCanvas

public ImageCanvas(GrayImage image)
            throws BadImageException
Creates an ImageCanvas from a GrayImage

Parameters:
image - GrayImage
Throws:
BadImageException

ImageCanvas

public ImageCanvas(ColorImage image)
            throws BadImageException
Creates an ImageCanvas from a ColorImage

Parameters:
image - ColorImage
Throws:
BadImageException

ImageCanvas

public ImageCanvas(RealGrayImage image)
            throws BadImageException
Creates an ImageCanvas from a RealGrayImage

Parameters:
image - RealGrayImage
Throws:
BadImageException

ImageCanvas

public ImageCanvas(RealColorImage image)
            throws BadImageException
Creates an ImageCanvas from a RealColorImage

Parameters:
image - RealColorImage
Throws:
BadImageException

ImageCanvas

public ImageCanvas(ComplexImage image)
            throws BadImageException
Creates an ImageCanvas from a ComplexImage

Parameters:
image - ComplexImage
Throws:
BadImageException

ImageCanvas

public ImageCanvas(Image image)
            throws BadImageException
Creates an ImageCanvas from a JIGL Image

Parameters:
image - JIGL Image
Throws:
BadImageException
Method Detail

setImage

public void setImage(Image image)
Sets the Java image to image and JIGL Image to null

Parameters:
image - java.awt.Image
See Also:
Image

setImage

public void setImage(Image image)
              throws BadImageException
Sets the JIGL Image and Java Image to image

Parameters:
image - JIGL Image
Throws:
BadImageException

getImage

public Image getImage()
Returns the JIGL image

Returns:
JIGL Image

getJavaImage

public Image getJavaImage()
Returns the Java image

Returns:
java.awt.Image
See Also:
Image

setOffScreen

public Graphics setOffScreen()
Returns an instance of Graphics that, when modified, modifies the Java image

Returns:
Graphics that is tied to the java.awt.Image
See Also:
Image

setOffScreen

public Graphics setOffScreen(double xfactor,
                             double yfactor)
Returns an instance of Graphics that, when modified, modifies the Java image

Parameters:
xfactor - Zoom of x axis
yfactor - Zoom of y axis
Returns:
Graphics tied to the java.awt.Image
See Also:
Image

setVisible

public void setVisible(boolean b)
Overrides Component.setVisible(boolean)

Overrides:
setVisible in class Component
Parameters:
b - flag. true == visible.

imHeight

public int imHeight()
Returns the image height

Returns:
image height

imWidth

public int imWidth()
Returns the image width

Returns:
image width

getJavaImage

public Image getJavaImage(Image img)
                   throws BadImageException
Takes a jigl image as input, converts it to a java image, and returns the java image.

Parameters:
img - The JIGL image.
Returns:
java.awt.Image
Throws:
BadImageException
See Also:
Image

update

public void update(Graphics g)
Repaints the ImageCanvas. Also draws the selection box and active border if those options are enabled.

Overrides:
update in class Canvas
Parameters:
g - Graphics

drawActiveBox

private void drawActiveBox(Graphics g)
Draw the active box.


drawBox

private void drawBox(Graphics g,
                     int ux,
                     int uy,
                     int lx,
                     int ly)
Draw a rectangle.


paint

public void paint(Graphics g)
Overrides the paint method for smoother redraw

Overrides:
paint in class Canvas
Parameters:
g - Graphics object

setSelectionBoxAnchor

public void setSelectionBoxAnchor(int ux,
                                  int uy)
Sets the upper corner of the selection box (ux and uy). Must be followed by setSelectionBoxExtent for a box to actually be drawn.

Parameters:
ux - Upper x coordinate of box
uy - Upper y coordinate of box

setSelectionBoxExtent

public void setSelectionBoxExtent(int lx,
                                  int ly)
Sets the lower corner of the selection box (lx and ly). The selection box anchor must have been set previously for this to draw a box.

Parameters:
lx - Lower x coordinate of box
ly - Lower y coordinate of box

showSelectionBox

public void showSelectionBox(boolean b)
Sets whether or not selection box is displayed.

Parameters:
b - true = box is displayed, false = box is not displayed.

clearSelectionBox

public void clearSelectionBox()
Clears the selection box.


getSelectionBox

public Rectangle getSelectionBox()
Returns the selection box in a Rectangle object. Returns null if no selection box is set.

Returns:
Current selection box

getSelectionBoxAnchorX

public int getSelectionBoxAnchorX()
Returns the upper x (anchor) coordinate of the selection box.

Returns:
x anchor coordinate of the selection box.

getSelectionBoxAnchorY

public int getSelectionBoxAnchorY()
Returns the upper y (anchor) coordinate of the selection box.

Returns:
y anchor coordinate of the selection box.

getSelectionBoxExtentX

public int getSelectionBoxExtentX()
Rturns the lower x (extent) coordinate of the selection box.

Returns:
x extent coordinate of the selection box.

getSelectionBoxExtentY

public int getSelectionBoxExtentY()
Returns the lower y (extent) coordinate of the selection box.

Returns:
y extent coordinate of the selection box.

setActive

public void setActive(boolean active)
Sets whether or not the image is active. If showActiveBox is set to true, the image will have a highlight border when active.

Parameters:
active - true = the image is active, false = the image is not active.

showActiveBox

public void showActiveBox(boolean b)
Sets whether or not the image is highlighted with a border when activated.

Parameters:
b - true = show border when active, false = don't show border

setActiveColor

public void setActiveColor(Color color)
Sets the color used to highlight the image when active (default is blue).

Parameters:
color - Color object.

JIGL
v1.6

Submit a bug or feature
Revised in May 2002 by Weiming Liu