public static class DisplayUtilities.ImageComponent extends JComponent implements MouseListener, MouseMotionListener
When allowZooming is TRUE, clicking in the image will zoom in. CTRL-click in the image to zoom out.
Modifier and Type | Class and Description |
---|---|
static interface |
DisplayUtilities.ImageComponent.ImageComponentListener
Listener for zoom and pan events
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected BufferedImage |
image
The image being displayed
|
protected Image<?,?> |
originalImage
The original image being displayed.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ImageComponent()
Default constructor
|
ImageComponent(boolean autoResize)
Default constructor.
|
ImageComponent(boolean autoResize,
boolean autoPack)
Default constructor.
|
ImageComponent(BufferedImage image)
Construct with given image
|
ImageComponent(float initialScale,
boolean autoResize,
boolean autoPack)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addImageComponentListener(DisplayUtilities.ImageComponent.ImageComponentListener l)
Add the given listener to this image component.
|
int |
getCurrentDisplayedPixelColour()
Returns the current displayed pixel colour (as an RGB encoded int) from the
currently displayed image.
|
Point2d |
getCurrentMouseImagePosition()
Returns the current mouse position in the coordinates of the image and is
determined by the scaling factors and the position of the image within the
viewport.
|
Point2d |
getCurrentMousePosition()
Returns the current mouse position in pixels within the viewport.
|
Float[] |
getCurrentPixelColour()
Returns the current pixel colour at the point of the mouse.
|
BufferedImage |
getDisplayedImage()
Returns the currently displaying image.
|
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) |
void |
moveTo(double x,
double y)
Move the image to the given position (image coordinates)
|
void |
paint(Graphics gfx) |
void |
removeImageComponentListener(DisplayUtilities.ImageComponent.ImageComponentListener l)
Remove the given listener from this image component.
|
void |
setAllowPanning(boolean allowPan)
Set whether to allow panning.
|
void |
setAllowZoom(boolean allowZoom)
Set whether to allow zooming.
|
void |
setAutoFit(boolean tf)
Sets whether to automatically size the image to fit within the bounds of the
image component which is being sized externally.
|
void |
setAutoPack(boolean tf)
Sets whether the component is to attempt to pack a frame into which it is
added.
|
void |
setAutoResize(boolean tf)
Sets whether to automatically resize the component to fit image (at it's
given scale factor) within it.
|
void |
setImage(BufferedImage image)
Set the image to draw
|
void |
setKeepAspect(boolean tf)
Sets whether to keep the aspect ratio of the image constant when the image is
being autoFit into the component.
|
void |
setOriginalImage(Image<?,?> image)
If you want to be able to inspect the original image's pixel values (rather
than the generated BufferedImage) set the original image here.
|
void |
setScaleFactor(double sfx,
double sfy)
Set the scale factor to draw the image.
|
void |
setScaleFactorX(double sf)
Set the scale factor to draw the image in the x-direction.
|
void |
setScaleFactorY(double sf)
Set the scale factor to draw the image in the y-direction.
|
void |
setShowPixelColours(boolean showPixelColours)
Set whether to show pixel colours or not.
|
void |
setShowXYPosition(boolean showXYPosition)
Set whether to show the XY position of the mouse curson or not
|
void |
setTransparencyGrid(boolean drawGrid)
Set whether to allow drawing of the transparency grid.
|
protected void |
updatePixelColours()
Update the display of pixel colours
|
void |
zoom(double sf)
Set the scale factor to zoom to
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected BufferedImage image
protected Image<?,?> originalImage
public ImageComponent()
public ImageComponent(boolean autoResize)
autoResize
- automatically resize the component to the content sizepublic ImageComponent(BufferedImage image)
image
- the imagepublic ImageComponent(boolean autoResize, boolean autoPack)
autoResize
- automatically resize the component to the content sizeautoPack
- automatically pack the root component on resizepublic ImageComponent(float initialScale, boolean autoResize, boolean autoPack)
initialScale
- initial scale of the imageautoResize
- automatically resize the component to the content sizeautoPack
- automatically pack the root component on resizepublic void addImageComponentListener(DisplayUtilities.ImageComponent.ImageComponentListener l)
l
- The listener to addpublic void removeImageComponentListener(DisplayUtilities.ImageComponent.ImageComponentListener l)
l
- The listener to remove.public void setAllowZoom(boolean allowZoom)
allowZoom
- TRUE to allow zoomingpublic void setAllowPanning(boolean allowPan)
allowPan
- TRUE to allow panningpublic void setTransparencyGrid(boolean drawGrid)
drawGrid
- TRUE draws the gridpublic void setShowPixelColours(boolean showPixelColours)
showPixelColours
- TRUE to show pixel colourspublic void setShowXYPosition(boolean showXYPosition)
showXYPosition
- TRUE to show XY positionpublic void setImage(BufferedImage image)
image
- the imagepublic void moveTo(double x, double y)
x
- The x image coordinatey
- The y image coordinatepublic void zoom(double sf)
sf
- The scale factorpublic void setScaleFactorX(double sf)
sf
- The new scale factorpublic void setScaleFactorY(double sf)
sf
- The new scale factorpublic void setScaleFactor(double sfx, double sfy)
sfx
- The new x scale factorsfy
- The new y scale factorpublic void setOriginalImage(Image<?,?> image)
image
- The original image.public void paint(Graphics gfx)
paint
in class JComponent
JComponent.paint(java.awt.Graphics)
public void mouseClicked(MouseEvent e)
mouseClicked
in interface MouseListener
MouseListener.mouseClicked(java.awt.event.MouseEvent)
public void mousePressed(MouseEvent e)
mousePressed
in interface MouseListener
public void mouseReleased(MouseEvent e)
mouseReleased
in interface MouseListener
public void mouseEntered(MouseEvent e)
mouseEntered
in interface MouseListener
public void mouseExited(MouseEvent e)
mouseExited
in interface MouseListener
public void mouseDragged(MouseEvent e)
mouseDragged
in interface MouseMotionListener
public void mouseMoved(MouseEvent e)
mouseMoved
in interface MouseMotionListener
protected void updatePixelColours()
public void setAutoFit(boolean tf)
tf
- TRUE to auto fit the image.public void setKeepAspect(boolean tf)
tf
- TRUE to keep the aspect ratio constantpublic void setAutoResize(boolean tf)
tf
- TRUE to resize the component.public void setAutoPack(boolean tf)
tf
- TRUE to auto pack the parent frame.public Point2d getCurrentMousePosition()
public Point2d getCurrentMouseImagePosition()
public Float[] getCurrentPixelColour()
public int getCurrentDisplayedPixelColour()
public BufferedImage getDisplayedImage()