Class JImage

All Implemented Interfaces:
KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener

public class JImage extends JComponent implements MouseMotionListener, MouseListener, KeyListener
A class to handle an image viewer with seleclection , marker and axis capability.
See Also:
  • 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

      protected BufferedImage theImage
    • margin

      protected Insets 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

      protected Vector<fr.esrf.tangoatk.widget.util.Marker> markers
    • markerScaleFactor

      protected double markerScaleFactor
    • xAxis

      protected JLAxis xAxis
    • xAxisHeight

      protected int xAxisHeight
    • xAxisUpMargin

      protected int xAxisUpMargin
    • yAxis

      protected JLAxis yAxis
    • yAxisWidth

      protected int yAxisWidth
    • yAxisRightMargin

      protected int yAxisRightMargin
    • crossCursor

      protected boolean crossCursor
    • cursorColor

      protected Color cursorColor
    • xCursor

      protected int xCursor
    • yCursor

      protected int yCursor
    • selectionColor

      protected Color 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

      public void setCursorColor(Color c)
      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

      public Rectangle getSelectionRect()
      Returns the current rectangle selected.
      Returns:
      null when no selection or a Rectangle
    • getSelectionPoint

      public Point[] getSelectionPoint()
      Returns the current line/rectangle selected.
      Returns:
      null when no selection or a 2 points array
    • getSelectionCrossPoint

      public Point[] 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

      public void setMargin(Insets i)
      Sets the margin of the JImage
      Parameters:
      i - Image margin
    • getMargin

      public Insets 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

      public void setImage(BufferedImage i)
      Sets the image to be displayed
      Parameters:
      i - Image
    • getXAxis

      public JLAxis getXAxis()
      Returns:
      a handle of the X axis.
    • getYAxis

      public JLAxis getYAxis()
      Returns a handle of the Y axis.
      Returns:
      Y axis
    • getImage

      public BufferedImage getImage()
      Returns a handle to the image displayed
      Returns:
      Image handle
    • getImageSize

      public Dimension 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

      public int addCrossMarker(int x, int y, Color c)
      Adds a cross marker at the specified pos
      Parameters:
      x - X coordinates
      y - Y coordinates
      c - Marker Color
      Returns:
      Marker id
    • addMovableMarker

      public int addMovableMarker(int x, int y, int width, int height, Color c, int lineWidth)
    • addRectangleMarker

      public int addRectangleMarker(int x, int y, int width, int height, Color c, int lineWidth)
      Adds a rectangle marker
      Parameters:
      x - X topleft corner coordinate
      y - Y topleft corner coordinate
      width - Rectangle width
      height - Rectangle hieght
      c - Marker Color
      lineWidth - lineWidth
      Returns:
      Marker id
    • addRectangleMarker

      public int addRectangleMarker(int x, int y, int width, int height, Color c)
      Adds a rectangle marker
      Parameters:
      x - X topleft corner coordinate
      y - Y topleft corner coordinate
      width - Rectangle width
      height - Rectangle hieght
      c - Marker Color
      Returns:
      Marker id
    • addVerticalLineMarker

      public int addVerticalLineMarker(int x, Color c)
      Adds a vertical line marker
      Parameters:
      x - Horizontal position
      c - Marker color
      Returns:
      Marker id
    • addHorizontalLineMarker

      public int addHorizontalLineMarker(int y, Color c)
      Adds a horizontal line marker
      Parameters:
      y - Vertical position
      c - 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 index
      x - 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

      public Point getMarkerPos(int id)
    • 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

      public Color getSelectionColor()
      Returns:
      the color of the selection area.
    • setSelectionColor

      public void setSelectionColor(Color selectionColor)
      Sets the color of the selection area
      Parameters:
      selectionColor - Selection color
    • addMarkerListener

      public void addMarkerListener(MarkerListener l)
    • removeMarkerListener

      public void removeMarkerListener(MarkerListener l)
      Remove the specified ROI Listener
      Parameters:
      l - ROI listener
    • paintCursor

      protected void paintCursor(Graphics g)
    • paintSelection

      protected void paintSelection(Graphics g)
    • measureAxis

      protected void measureAxis()
    • paintAxis

      protected void paintAxis(Graphics g)
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • 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

      protected Rectangle buildSelectionRect()
    • repaintBoundingRect

      protected void repaintBoundingRect(Rectangle oldSel)
    • 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

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • main

      public static void main(String[] args)