Package fr.esrf.tangoatk.widget.util
Class JImage
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
fr.esrf.tangoatk.widget.util.JImage
- All Implemented Interfaces:
KeyListener,MouseListener,MouseMotionListener,ImageObserver,MenuContainer,Serializable,EventListener
A class to handle an image viewer with seleclection , marker and axis capability.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected booleanprotected Colorprotected intprotected intprotected intstatic final intstatic final intstatic final intprotected intprotected booleanprotected booleanprotected Insetsprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected Vector<fr.esrf.tangoatk.widget.util.Marker>protected doubleprotected intstatic final intstatic final intstatic final intprotected intprotected Colorprotected booleanprotected booleanprotected BufferedImagestatic final intstatic final intstatic final intprotected intprotected intprotected intprotected JLAxisprotected intprotected intprotected intprotected intprotected intprotected intprotected JLAxisprotected intprotected intprotected intprotected intFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddCrossMarker(int x, int y, Color c) Adds a cross marker at the specified posintaddHorizontalLineMarker(int y, Color c) Adds a horizontal line markervoidintaddMovableMarker(int x, int y, int width, int height, Color c, int lineWidth) intaddRectangleMarker(int x, int y, int width, int height, Color c) Adds a rectangle markerintaddRectangleMarker(int x, int y, int width, int height, Color c, int lineWidth) Adds a rectangle markerintaddVerticalLineMarker(int x, Color c) Adds a vertical line markerprotected voidprotected RectanglevoidClears all markersvoidClears the current selection.protected voidprotected booleancornerMatch(int x, int y, int xc, int yc) protected intfindCorner(int x, int y) protected intfindMovableCorner(int x, int y) voidfireMarkerMoved(int markerId, fr.esrf.tangoatk.widget.util.Marker m) voidfireMarkerSelection(int markerId) intgetImage()Returns a handle to the image displayedReturns size of the image (does not include margin)Returns margin of the imageintgetMarkerPos(int id) Point[]Returns the current lines selected (MODE_CROSS).intReturns the selection modePoint[]Returns the current line/rectangle selected.Returns the current rectangle selected.intReturns the grid spacing (Pixel)intgetXAxis()intReturn origin of the image within the componentgetYAxis()Returns a handle of the Y axis.intReturn origin of the image within the componentbooleanReturns true if a selection existsbooleanbooleanReturns true only if the selection is enabled.booleanReturn true when snap to grid mode is enablevoidvoidvoidstatic voidprotected voidvoidvoidvoidvoidvoidvoidvoidvoidprotected voidprotected voidprotected voidvoidRemove the specified ROI Listenerprotected voidrepaintBoundingRect(Rectangle oldSel) voidsetCrossCursor(boolean enable) Enable or disable the cross cursor.voidSet the cross cursor color.voidsetHorizontalPosition(int horizontalPosition) Sets the horizontal selection arrow position (MODE_CROSS selection)voidSets the image to be displayedvoidSets the margin of the JImagevoidsetMarkerPos(int id, int x, int y, int nWidth, int nHeight) Sets the position of a markervoidsetMarkerScale(double s) Sets the scale factor for markersvoidsetSelection(int _x1, int _y1, int _x2, int _y2) Sets the current selection.voidsetSelectionColor(Color selectionColor) Sets the color of the selection areavoidsetSelectionEnabled(boolean b) Enable or disable the selection.voidsetSelectionMode(int m) Sets the selection modevoidsetSnapGrid(int b) Sets the grid spacing (Pixel)voidsetSnapToGrid(boolean b) Enables the grid mode.voidsetVerticalPosition(int verticalPosition) Sets the vertical selection arrow position (MODE_CROSS selection)Methods inherited from class javax.swing.JComponent
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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, 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, updateUIMethods inherited from class java.awt.Container
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, validateTreeMethods 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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
MODE_LINE
public static final int MODE_LINE- See Also:
-
MODE_RECT
public static final int MODE_RECT- See Also:
-
MODE_CROSS
public static final int MODE_CROSS- See Also:
-
VERTICAL_LEFT
public static final int VERTICAL_LEFT- See Also:
-
VERTICAL_CENTER
public static final int VERTICAL_CENTER- See Also:
-
VERTICAL_RIGHT
public static final int VERTICAL_RIGHT- See Also:
-
HORIZONTAL_TOP
public static final int HORIZONTAL_TOP- See Also:
-
HORIZONTAL_CENTER
public static final int HORIZONTAL_CENTER- See Also:
-
HORIZONTAL_BOTTOM
public static final int HORIZONTAL_BOTTOM- See Also:
-
MARKER_CROSS
protected static final int MARKER_CROSS- See Also:
-
MARKER_RECT
protected static final int MARKER_RECT- See Also:
-
MARKER_VLINE
protected static final int MARKER_VLINE- See Also:
-
MARKER_HLINE
protected static final int MARKER_HLINE- See Also:
-
MARKER_MOVABLE
protected static final int MARKER_MOVABLE- See Also:
-
theImage
-
margin
-
xOrg
protected int xOrg -
yOrg
protected int yOrg -
selectionEnabled
protected boolean selectionEnabled -
mode
protected int mode -
isDragging
protected boolean isDragging -
isDraggingMovable
protected boolean isDraggingMovable -
dragCorner
protected int dragCorner -
cornerWidth
protected int cornerWidth -
dragMovableMarkerCorner
protected int dragMovableMarkerCorner -
movableMarkerId
protected int movableMarkerId -
x1
protected int x1 -
y1
protected int y1 -
x2
protected int x2 -
y2
protected int y2 -
snapToGrid
protected boolean snapToGrid -
grid
protected int grid -
markers
-
markerScaleFactor
protected double markerScaleFactor -
xAxis
-
xAxisHeight
protected int xAxisHeight -
xAxisUpMargin
protected int xAxisUpMargin -
yAxis
-
yAxisWidth
protected int yAxisWidth -
yAxisRightMargin
protected int yAxisRightMargin -
crossCursor
protected boolean crossCursor -
cursorColor
-
xCursor
protected int xCursor -
yCursor
protected int yCursor -
selectionColor
-
horizontalPosition
protected int horizontalPosition -
verticalPosition
protected int verticalPosition
-
-
Constructor Details
-
JImage
public JImage()Construction
-
-
Method Details
-
setCrossCursor
public void setCrossCursor(boolean enable) Enable or disable the cross cursor.- Parameters:
enable- True to enable cross cursor, false otherwise.
-
setCursorColor
Set the cross cursor color.- Parameters:
c- Cursor color- See Also:
-
isCrossCursor
public boolean isCrossCursor()- Returns:
- true if cross curosr is enabled.
-
setSelectionEnabled
public void setSelectionEnabled(boolean b) Enable or disable the selection. When enabled, A region can be dragged and sized inside the image.- Parameters:
b- Selection mode- See Also:
-
isSelectionEnabled
public boolean isSelectionEnabled()Returns true only if the selection is enabled.- Returns:
- Selection mode
-
getSelectionRect
Returns the current rectangle selected.- Returns:
- null when no selection or a Rectangle
-
getSelectionPoint
Returns the current line/rectangle selected.- Returns:
- null when no selection or a 2 points array
-
getSelectionCrossPoint
Returns the current lines selected (MODE_CROSS).- Returns:
- null when no selection or a 4 points array
-
setSelectionMode
public void setSelectionMode(int m) Sets the selection mode- Parameters:
m- 0 for Line selection , 1 for Rectangle selection
-
getSelectionMode
public int getSelectionMode()Returns the selection mode- Returns:
- 0 for Line selection , 1 for Rectangle selection
-
hasSelection
public boolean hasSelection()Returns true if a selection exists- Returns:
- true is a selection is visible on the image
-
setSelection
public void setSelection(int _x1, int _y1, int _x2, int _y2) Sets the current selection.- Parameters:
_x1- Top left corner x coordinate_y1- Top left corner y coordinate_x2- Bottom right corner x coordinate_y2- Bottom right corner y coordinate
-
clearSelection
public void clearSelection()Clears the current selection. -
setMargin
Sets the margin of the JImage- Parameters:
i- Image margin
-
getMargin
Returns margin of the image- Returns:
- Image margin
-
getXOrigin
public int getXOrigin()Return origin of the image within the component- Returns:
- X origin in pixel
-
getYOrigin
public int getYOrigin()Return origin of the image within the component- Returns:
- Y origin in pixel
-
setImage
Sets the image to be displayed- Parameters:
i- Image
-
getXAxis
- Returns:
- a handle of the X axis.
-
getYAxis
Returns a handle of the Y axis.- Returns:
- Y axis
-
getImage
Returns a handle to the image displayed- Returns:
- Image handle
-
getImageSize
Returns size of the image (does not include margin)- Returns:
- Image size
-
isSnapToGrid
public boolean isSnapToGrid()Return true when snap to grid mode is enable- Returns:
- AlignToGrid state
- See Also:
-
setSnapToGrid
public void setSnapToGrid(boolean b) Enables the grid mode. All selection point are rounded to grid multiple.- Parameters:
b- Snap to grid- See Also:
-
getSnapGrid
public int getSnapGrid()Returns the grid spacing (Pixel)- Returns:
- Grid width in pixels
-
setSnapGrid
public void setSnapGrid(int b) Sets the grid spacing (Pixel)- Parameters:
b- Grid width in pixels
-
addCrossMarker
Adds a cross marker at the specified pos- Parameters:
x- X coordinatesy- Y coordinatesc- Marker Color- Returns:
- Marker id
-
addMovableMarker
-
addRectangleMarker
Adds a rectangle marker- Parameters:
x- X topleft corner coordinatey- Y topleft corner coordinatewidth- Rectangle widthheight- Rectangle hieghtc- Marker ColorlineWidth- lineWidth- Returns:
- Marker id
-
addRectangleMarker
Adds a rectangle marker- Parameters:
x- X topleft corner coordinatey- Y topleft corner coordinatewidth- Rectangle widthheight- Rectangle hieghtc- Marker Color- Returns:
- Marker id
-
addVerticalLineMarker
Adds a vertical line marker- Parameters:
x- Horizontal positionc- Marker color- Returns:
- Marker id
-
addHorizontalLineMarker
Adds a horizontal line marker- Parameters:
y- Vertical positionc- Marker color- Returns:
- Marker id
-
setMarkerPos
public void setMarkerPos(int id, int x, int y, int nWidth, int nHeight) Sets the position of a marker- Parameters:
id- Marker indexx- X coordinate (ignored when HORIZONTAL_LINE Marker)y- Y coordinate (ignored when VERTICAL_LINE Marker)nWidth- Rectangle width (ignored when CROSS Marker, LINE Marker)nHeight- Rectangle height (ignored when CROSS Marker, LINE Marker)
-
getMarkerPos
-
clearMarkers
public void clearMarkers()Clears all markers -
getMarkerNumber
public int getMarkerNumber()- Returns:
- The number of marker
-
setMarkerScale
public void setMarkerScale(double s) Sets the scale factor for markers- Parameters:
s- Scale factor
-
getHorizontalPosition
public int getHorizontalPosition()- Returns:
- the horizontal selection arrow position (MODE_CROSS selection)
-
setHorizontalPosition
public void setHorizontalPosition(int horizontalPosition) Sets the horizontal selection arrow position (MODE_CROSS selection)- Parameters:
horizontalPosition- Horizontal position
-
getVerticalPosition
public int getVerticalPosition()- Returns:
- the vertical selection arrow position (MODE_CROSS selection)
-
setVerticalPosition
public void setVerticalPosition(int verticalPosition) Sets the vertical selection arrow position (MODE_CROSS selection)- Parameters:
verticalPosition- Vertical position
-
getSelectionColor
- Returns:
- the color of the selection area.
-
setSelectionColor
Sets the color of the selection area- Parameters:
selectionColor- Selection color
-
addMarkerListener
-
removeMarkerListener
Remove the specified ROI Listener- Parameters:
l- ROI listener
-
paintCursor
-
paintSelection
-
measureAxis
protected void measureAxis() -
paintAxis
-
paint
- Overrides:
paintin classJComponent
-
getMinimumSize
- Overrides:
getMinimumSizein classJComponent
-
getPreferredSize
- Overrides:
getPreferredSizein classJComponent
-
cornerMatch
protected boolean cornerMatch(int x, int y, int xc, int yc) -
findCorner
protected int findCorner(int x, int y) -
findMovableCorner
protected int findMovableCorner(int x, int y) -
buildSelectionRect
-
repaintBoundingRect
-
clipSelection
protected void clipSelection() -
fireMarkerSelection
public void fireMarkerSelection(int markerId) -
fireMarkerMoved
public void fireMarkerMoved(int markerId, fr.esrf.tangoatk.widget.util.Marker m) -
alignSelection
protected void alignSelection() -
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener
-
keyPressed
- Specified by:
keyPressedin interfaceKeyListener
-
keyReleased
- Specified by:
keyReleasedin interfaceKeyListener
-
keyTyped
- Specified by:
keyTypedin interfaceKeyListener
-
main
-