JIGL
v1.6

jigl.gui
Class JImageCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--jigl.gui.JImageCanvas
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class JImageCanvas
extends JPanel

JImageCanvas is a SWING compatible class made to facilitate the displaying of a JIGL image. JImageCanvas 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.JImageCanvas)
         {
                 jigl.gui.JImageCanvas canvas = (jigl.gui.JImageCanvas)e.getComponent();
                 canvas.clearSelectionBox();
                 canvas.setSelectionBoxAnchor(e.getX(),e.getY());
         }
 }
 
 //MouseMotionListener method
 public void mouseDragged(MouseEvent e)
 {
         if (e.getComponent() instanceof jigl.gui.JImageCanvas)
         {
                 jigl.gui.JImageCanvas canvas = (jigl.gui.JImageCanvas)e.getComponent();
                 canvas.setSelectionBoxExtent(e.getX(),e.getY());
         }
 }
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
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 javax.swing.JPanel
 
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.Container
 
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
JImageCanvas()
          Creates an empty JImageCanvas.
JImageCanvas(BinaryImage image)
          Creates a JImageCanvas from a GrayImage.
JImageCanvas(ColorImage image)
          Creates a JImageCanvas from a ColorImage.
JImageCanvas(ComplexImage image)
          Creates a JImageCanvas from a ComplexImage.
JImageCanvas(GrayImage image)
          Creates a JImageCanvas from a GrayImage.
JImageCanvas(Image image)
          Creates a JImageCanvas from a JIGL Image.
JImageCanvas(RealColorImage image)
          Creates a JImageCanvas from a RealColorImage.
JImageCanvas(RealGrayImage image)
          Creates a JImageCanvas from a RealGrayImage.
 
Method Summary
 void clearSelectionBox()
          Clears the selection box.
private  void drawActiveBox(Graphics g)
           
private  void drawBox(Graphics g, int ux, int uy, int lx, int ly)
           
 int getHeight()
          Overridden to reflect image size.
 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.
 Dimension getPreferredSize()
          Overridden to reflect image size.
 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()
          Returns the lower x (extent) coordinate of the selection box.
 int getSelectionBoxExtentY()
          Returns the lower y (extent) coordinate of the selection box.
 Dimension getSize()
          Overridden to reflect image size.
 Dimension getSize(Dimension rv)
          Overridden to reflect image size.
 int getWidth()
          Overridden to reflect image size.
 int imHeight()
          Returns the image height.
 int imWidth()
          Returns the image width.
 void paint(Graphics g)
          Overrides the paint method for smoother redraw.
 void paintComponent(Graphics g)
          Overrides the paintComponent 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 JImageCanvas.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

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

JImageCanvas

public JImageCanvas()
Creates an empty JImageCanvas.


JImageCanvas

public JImageCanvas(BinaryImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a GrayImage.

Parameters:
image - GrayImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(GrayImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a GrayImage.

Parameters:
image - GrayImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(ColorImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a ColorImage.

Parameters:
image - ColorImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(RealGrayImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a RealGrayImage.

Parameters:
image - RealGrayImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(RealColorImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a RealColorImage.

Parameters:
image - RealColorImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(ComplexImage image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a ComplexImage.

Parameters:
image - ComplexImage
Throws:
ImageNotSupportedException - if the image type is not supported

JImageCanvas

public JImageCanvas(Image image)
             throws ImageNotSupportedException
Creates a JImageCanvas from a JIGL Image.

Parameters:
image - jigl.image.Image
Throws:
ImageNotSupportedException - if the image type is not supported
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 ImageNotSupportedException
Sets the JIGL Image and Java Image to image.

Parameters:
image - jigl.image.Image
Throws:
ImageNotSupportedException - if the image type is not supported

getImage

public Image getImage()
Returns the JIGL image.

Returns:
jigl.image.Image for this JImageCanvas

getJavaImage

public Image getJavaImage()
Returns the Java image.

Returns:
java.awt.Image for this JImageCanvas

setOffScreen

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

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

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

setVisible

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

Overrides:
setVisible in class JComponent
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

getSize

public Dimension getSize()
Overridden to reflect image size.

Overrides:
getSize in class Component
Returns:
Dimension of the image

getSize

public Dimension getSize(Dimension rv)
Overridden to reflect image size.

Overrides:
getSize in class JComponent
Parameters:
rv - Dimension object
Returns:
Dimension of the image

getWidth

public int getWidth()
Overridden to reflect image size.

Overrides:
getWidth in class JComponent
Returns:
image width

getHeight

public int getHeight()
Overridden to reflect image size.

Overrides:
getHeight in class JComponent
Returns:
image height

getPreferredSize

public Dimension getPreferredSize()
Overridden to reflect image size.

Overrides:
getPreferredSize in class JComponent
Returns:
Dimension of image

getJavaImage

public Image getJavaImage(Image img)
                   throws ImageNotSupportedException
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:
ImageNotSupportedException - if the image type is not supported
See Also:
Image

update

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

Overrides:
update in class JComponent
Parameters:
g - Graphics

paint

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

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

paintComponent

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

Overrides:
paintComponent in class JComponent
Parameters:
g - Graphics object

drawActiveBox

private void drawActiveBox(Graphics g)

drawBox

private void drawBox(Graphics g,
                     int ux,
                     int uy,
                     int lx,
                     int ly)

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:
cCrrent 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()
Returns 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