Module ij
Package ij.gui

# Class ImageCanvas

java.lang.Object
java.awt.Component
java.awt.Canvas
ij.gui.ImageCanvas

All Implemented Interfaces:
  `MouseListener`, `MouseMotionListener`, `ImageObserver`, `MenuContainer`, `Serializable`, `Cloneable`, `EventListener`, `Accessible`

Direct Known Subclasses:
  `PlotCanvas`

public class ImageCanvas extends Canvas implements MouseListener, MouseMotionListener, Cloneable
This is a Canvas used to display images in a Window.

See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class java.awt.Canvas

`Canvas.AccessibleAWTCanvas`

## Nested classes/interfaces inherited from class java.awt.Component

`Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static Cursor`
`crosshairCursor`
`protected static Cursor`
`defaultCursor`
`protected int`
`dstHeight`
`protected int`
`dstWidth`
`protected int`
`flags`
`protected static Cursor`
`handCursor`
`protected ImageJ`
`ij`
`protected int`
`imageHeight`
`protected boolean`
`imageUpdated`
`protected int`
`imageWidth`
`protected ImagePlus`
`imp`
`protected int`
`lastZoomSX`
Screen coordinates where the last zoom operation was done (initialized to impossible value)
`protected int`
`lastZoomSY`
`protected double`
`magnification`
`protected static final int`
`MAX_MOUSEMOVE_ZOOM`
If the mouse moves less than this in screen pixels, successive zoom operations are on the same image pixel
`protected static Cursor`
`moveCursor`
`protected Rectangle`
`srcRect`
`static boolean`
`usePointer`
`protected int`
`xMouse`
`protected int`
`xMouseStart`
`protected int`
`xSrcStart`
`protected int`
`yMouse`
`protected int`
`yMouseStart`
`protected int`
`ySrcStart`
`protected int`
`zoomTargetOX`
Image (=offscreen) coordinates where the cursor was moved to for zooming
`protected int`
`zoomTargetOY`

### Fields inherited from class java.awt.Component

`accessibleContext, 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

Constructors
Constructor
Description
`ImageCanvas(ImagePlus imp)`

## Method Summary

Modifier and Type
Method
Description
`protected Dimension`
`canEnlarge(int newWidth, int newHeight)`
Returns the size to which the window can be enlarged, or null if it can't be enlarged.
`boolean`
`cursorOverImage()`
Returns 'true' if the cursor is over this image.
`void`
`disablePopupMenu(boolean status)`
Disable/enable popup menu.
`void`
`fitToWindow()`
`Point`
`getCursorLoc()`
Returns the current cursor location in image coordinates.
`boolean`
`getCustomRoi()`
`Vector`
`getDisplayList()`
Deprecated.
replaced by ImagePlus.getOverlay()
`static double`
`getHigherZoomLevel(double currentMag)`
`ImagePlus`
`getImage()`
Returns the ImagePlus object that is associated with this ImageCanvas.
`static double`
`getLowerZoomLevel(double currentMag)`
`double`
`getMagnification()`
`int`
`getModifiers()`
Returns the mouse event modifiers.
`Overlay`
`getOverlay()`
Use ImagePlus.getOverlay().
`boolean`
`getPaintPending()`
`Dimension`
`getPreferredSize()`
`boolean`
`getScaleToFit()`
`static Color`
`getShowAllColor()`
Obsolete
`Overlay`
`getShowAllList()`
`boolean`
`getShowAllROIs()`
Obsolete
`int`
`getSliceNumber(String label)`
`Rectangle`
`getSrcRect()`
`protected void`
`handlePopupMenu(MouseEvent e)`
`protected void`
`handleRoiMouseDown(MouseEvent e)`
`boolean`
`hideZoomIndicator(boolean hide)`
`void`
`mouseClicked(MouseEvent e)`
`void`
`mouseDragged(MouseEvent e)`
`void`
`mouseEntered(MouseEvent e)`
`void`
`mouseExited(MouseEvent e)`
`void`
`mouseMoved(MouseEvent e)`
`void`
`mousePressed(MouseEvent e)`
`void`
`mouseReleased(MouseEvent e)`
`int`
`offScreenX(int sx)`
Converts a screen x-coordinate to an offscreen x-coordinate (nearest pixel center).
`int`
`offScreenX2(int sx)`
Converts a screen x-coordinate to an offscreen x-coordinate (Roi coordinate of nearest pixel border).
`double`
`offScreenXD(int sx)`
Converts a screen x-coordinate to a floating-point offscreen x-coordinate.
`int`
`offScreenY(int sy)`
Converts a screen y-coordinate to an offscreen y-coordinate (nearest pixel center).
`int`
`offScreenY2(int sy)`
Converts a screen y-coordinate to an offscreen y-coordinate (Roi coordinate of nearest pixel border).
`double`
`offScreenYD(int sy)`
Converts a screen y-coordinate to a floating-point offscreen y-coordinate.
`void`
`paint(Graphics g)`
`void`
`repaintOverlay()`
`void`
`resetDoubleBuffer()`
`boolean`
`roiManagerSelect(Roi roi, boolean delete)`
`int`
`screenX(int ox)`
Converts an offscreen x-coordinate to a screen x-coordinate.
`int`
`screenXD(double ox)`
Converts a floating-point offscreen x-coordinate to a screen x-coordinate.
`int`
`screenY(int oy)`
Converts an offscreen y-coordinate to a screen y-coordinate.
`int`
`screenYD(double oy)`
Converts a floating-point offscreen x-coordinate to a screen x-coordinate.
`protected void`
`scroll(int sx, int sy)`
`void`
`setCursor(int sx, int sy, int ox, int oy)`
Sets the cursor based on the current tool and cursor location.
`static void`
`setCursor(Cursor cursor, int type)`
Experimental
`void`
`setCustomRoi(boolean customRoi)`
Allows plugins (e.g., Orthogonal_Views) to create a custom ROI using a display list.
`void`
`setDisplayList(Roi roi, Color color)`
Deprecated.
replaced by ImagePlus.setOverlay(Roi, Color, int, Color)
`void`
`setDisplayList(Shape shape, Color color, BasicStroke stroke)`
Deprecated.
replaced by ImagePlus.setOverlay(Shape, Color, BasicStroke)
`void`
`setDisplayList(Vector list)`
Deprecated.
replaced by ImagePlus.setOverlay(ij.gui.Overlay)
`void`
`setDrawingColor(int ox, int oy, boolean setBackground)`
Sets the foreground drawing color (or background color if 'setBackground' is true) to the color of the pixel at (ox,oy).
`void`
`setDrawingSize(int width, int height)`
Obsolete; replaced by setSize()
`void`
`setImageUpdated()`
ImagePlus.updateAndDraw calls this method to force the paint() method to update the image from the ImageProcessor.
`static void`
`setLongClickDelay(int delay)`
Sets the context menu long click delay in milliseconds (default is 1000).
`void`
`setMagnification(double magnification)`
`void`
`setOverlay(Overlay overlay)`
Use ImagePlus.setOverlay(ij.gui.Overlay).
`void`
`setPaintPending(boolean state)`
`void`
`setScaleToFit(boolean scaleToFit)`
`static void`
`setShowAllColor(Color c)`
Obsolete
`void`
`setShowAllList(Overlay showAllList)`
`void`
`setShowAllROIs(boolean showAllROIs)`
Obsolete
`void`
`setShowCursorStatus(boolean status)`
Called by IJ.showStatus() to prevent status bar text from being overwritten until the cursor moves at least 12 pixels.
`void`
`setSize(int width, int height)`
`void`
`setSourceRect(Rectangle r)`
Sets the region of the image (in pixels) to be displayed.
`protected void`
`setupScroll(int ox, int oy)`
`void`
`unzoom()`
Implements the Image/Zoom/Original Scale command.
`void`
`update(Graphics g)`
`void`
`zoom100Percent()`
Implements the Image/Zoom/View 100% command.
`void`
`zoomIn(int sx, int sy)`
Zooms in by making the window bigger.
`void`
`zoomOut(int sx, int sy)`
Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y).

### 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMousePosition, getMouseWheelListeners, getName, getParent, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, 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 Details

### defaultCursor

protected static Cursor defaultCursor

### handCursor

protected static Cursor handCursor

### moveCursor

protected static Cursor moveCursor

### crosshairCursor

protected static Cursor crosshairCursor

### usePointer

public static boolean usePointer

### imp

protected ImagePlus imp

### imageUpdated

protected boolean imageUpdated

### srcRect

protected Rectangle srcRect

### imageWidth

protected int imageWidth

### imageHeight

protected int imageHeight

### xMouse

protected int xMouse

### yMouse

protected int yMouse

### MAX_MOUSEMOVE_ZOOM

protected static final int MAX_MOUSEMOVE_ZOOM
If the mouse moves less than this in screen pixels, successive zoom operations are on the same image pixel

See Also:
  - Constant Field Values

### lastZoomSX

protected int lastZoomSX
Screen coordinates where the last zoom operation was done (initialized to impossible value)

### lastZoomSY

protected int lastZoomSY

### zoomTargetOX

protected int zoomTargetOX
Image (=offscreen) coordinates where the cursor was moved to for zooming

### zoomTargetOY

protected int zoomTargetOY

### ij

protected ImageJ ij

### magnification

protected double magnification

### dstWidth

protected int dstWidth

### dstHeight

protected int dstHeight

### xMouseStart

protected int xMouseStart

### yMouseStart

protected int yMouseStart

### xSrcStart

protected int xSrcStart

### ySrcStart

protected int ySrcStart

### flags

protected int flags

## Constructor Details

### ImageCanvas

public ImageCanvas(ImagePlus imp)

## Method Details

### setSourceRect

public void setSourceRect(Rectangle r)
Sets the region of the image (in pixels) to be displayed.

### getSrcRect

public Rectangle getSrcRect()

### setDrawingSize

public void setDrawingSize(int width, int height)
Obsolete; replaced by setSize()

### setSize

public void setSize(int width, int height)

Overrides:
  `setSize` in class `Component`

### setImageUpdated

public void setImageUpdated()
ImagePlus.updateAndDraw calls this method to force the paint() method to update the image from the ImageProcessor.

### setPaintPending

public void setPaintPending(boolean state)

### getPaintPending

public boolean getPaintPending()

### update

public void update(Graphics g)

Overrides:
  `update` in class `Canvas`

### paint

public void paint(Graphics g)

Overrides:
  `paint` in class `Canvas`

### getSliceNumber

public int getSliceNumber(String label)

### resetDoubleBuffer

public void resetDoubleBuffer()

### getPreferredSize

public Dimension getPreferredSize()

Overrides:
  `getPreferredSize` in class `Component`

### getCursorLoc

public Point getCursorLoc()
Returns the current cursor location in image coordinates.

### cursorOverImage

public boolean cursorOverImage()
Returns 'true' if the cursor is over this image.

### getModifiers

public int getModifiers()
Returns the mouse event modifiers.

### getImage

public ImagePlus getImage()
Returns the ImagePlus object that is associated with this ImageCanvas.

### setCursor

public void setCursor(int sx, int sy, int ox, int oy)
Sets the cursor based on the current tool and cursor location.

### offScreenX

public int offScreenX(int sx)
Converts a screen x-coordinate to an offscreen x-coordinate (nearest pixel center).

### offScreenY

public int offScreenY(int sy)
Converts a screen y-coordinate to an offscreen y-coordinate (nearest pixel center).

### offScreenX2

public int offScreenX2(int sx)
Converts a screen x-coordinate to an offscreen x-coordinate (Roi coordinate of nearest pixel border).

### offScreenY2

public int offScreenY2(int sy)
Converts a screen y-coordinate to an offscreen y-coordinate (Roi coordinate of nearest pixel border).

### offScreenXD

public double offScreenXD(int sx)
Converts a screen x-coordinate to a floating-point offscreen x-coordinate.

### offScreenYD

public double offScreenYD(int sy)
Converts a screen y-coordinate to a floating-point offscreen y-coordinate.

### screenX

public int screenX(int ox)
Converts an offscreen x-coordinate to a screen x-coordinate.

### screenY

public int screenY(int oy)
Converts an offscreen y-coordinate to a screen y-coordinate.

### screenXD

public int screenXD(double ox)
Converts a floating-point offscreen x-coordinate to a screen x-coordinate.

### screenYD

public int screenYD(double oy)
Converts a floating-point offscreen x-coordinate to a screen x-coordinate.

### getMagnification

public double getMagnification()

### setMagnification

public void setMagnification(double magnification)

### fitToWindow

public void fitToWindow()

### getLowerZoomLevel

public static double getLowerZoomLevel(double currentMag)

### getHigherZoomLevel

public static double getHigherZoomLevel(double currentMag)

### zoomIn

public void zoomIn(int sx, int sy)
Zooms in by making the window bigger. If it can't be made bigger, then makes the source rectangle (srcRect) smaller and centers it on the position in the image where the cursor was when zooming has started. Note that sx and sy are screen coordinates.

### canEnlarge

protected Dimension canEnlarge(int newWidth, int newHeight)
Returns the size to which the window can be enlarged, or null if it can't be enlarged. `newWidth, newHeight` is the size needed for showing the full image at the magnification needed

### zoomOut

public void zoomOut(int sx, int sy)
Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y). If we can't make it larger, then make the window smaller. Note that sx and sy are screen coordinates.

### unzoom

public void unzoom()
Implements the Image/Zoom/Original Scale command.

### zoom100Percent

public void zoom100Percent()
Implements the Image/Zoom/View 100% command.

### scroll

protected void scroll(int sx, int sy)

### setDrawingColor

public void setDrawingColor(int ox, int oy, boolean setBackground)
Sets the foreground drawing color (or background color if 'setBackground' is true) to the color of the pixel at (ox,oy).

### mousePressed

public void mousePressed(MouseEvent e)

Specified by:
  `mousePressed` in interface `MouseListener`

### setupScroll

protected void setupScroll(int ox, int oy)

### handlePopupMenu

protected void handlePopupMenu(MouseEvent e)

### mouseExited

public void mouseExited(MouseEvent e)

Specified by:
  `mouseExited` in interface `MouseListener`

### mouseDragged

public void mouseDragged(MouseEvent e)

Specified by:
  `mouseDragged` in interface `MouseMotionListener`

### handleRoiMouseDown

protected void handleRoiMouseDown(MouseEvent e)

### disablePopupMenu

public void disablePopupMenu(boolean status)
Disable/enable popup menu.

### setShowAllList

public void setShowAllList(Overlay showAllList)

### getShowAllList

public Overlay getShowAllList()

### setShowAllROIs

public void setShowAllROIs(boolean showAllROIs)
Obsolete

### getShowAllROIs

public boolean getShowAllROIs()
Obsolete

### getShowAllColor

public static Color getShowAllColor()
Obsolete

### setShowAllColor

public static void setShowAllColor(Color c)
Obsolete

### setCursor

public static void setCursor(Cursor cursor, int type)
Experimental

### setOverlay

public void setOverlay(Overlay overlay)
Use ImagePlus.setOverlay(ij.gui.Overlay).

### getOverlay

public Overlay getOverlay()
Use ImagePlus.getOverlay().

### setDisplayList

public void setDisplayList(Vector list)
Deprecated.
replaced by ImagePlus.setOverlay(ij.gui.Overlay)

### setDisplayList

public void setDisplayList(Shape shape, Color color, BasicStroke stroke)
Deprecated.
replaced by ImagePlus.setOverlay(Shape, Color, BasicStroke)

### setDisplayList

public void setDisplayList(Roi roi, Color color)
Deprecated.
replaced by ImagePlus.setOverlay(Roi, Color, int, Color)

### getDisplayList

public Vector getDisplayList()
Deprecated.
replaced by ImagePlus.getOverlay()

### setCustomRoi

public void setCustomRoi(boolean customRoi)
Allows plugins (e.g., Orthogonal_Views) to create a custom ROI using a display list.

### getCustomRoi

public boolean getCustomRoi()

### setShowCursorStatus

public void setShowCursorStatus(boolean status)
Called by IJ.showStatus() to prevent status bar text from being overwritten until the cursor moves at least 12 pixels.

### mouseReleased

public void mouseReleased(MouseEvent e)

Specified by:
  `mouseReleased` in interface `MouseListener`

### roiManagerSelect

public boolean roiManagerSelect(Roi roi, boolean delete)

### mouseMoved

public void mouseMoved(MouseEvent e)

Specified by:
  `mouseMoved` in interface `MouseMotionListener`

### mouseEntered

public void mouseEntered(MouseEvent e)

Specified by:
  `mouseEntered` in interface `MouseListener`

### mouseClicked

public void mouseClicked(MouseEvent e)

Specified by:
  `mouseClicked` in interface `MouseListener`

### setScaleToFit

public void setScaleToFit(boolean scaleToFit)

### getScaleToFit

public boolean getScaleToFit()

### hideZoomIndicator

public boolean hideZoomIndicator(boolean hide)

### repaintOverlay

public void repaintOverlay()

### setLongClickDelay

public static void setLongClickDelay(int delay)
Sets the context menu long click delay in milliseconds (default is 1000). Set to 0 to disable long click triggering.