Class JImagePanel

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class JImagePanel
    extends javax.swing.JPanel
    A swing component that enables to display images.

    This panel provides various operations on the view (zoom, moving, ...) and helper methods for correspondence between image space and display space.

    This image panel also manages features that enable to display interactive overlays on the panel.

    Since:
    1.0.2
    Version:
    "1.0.8" - b201801141330L
    Author:
    Julien Seinturier - COMEX S.A. - contact@jorigin.org - https://github.com/jorigin/jeometry
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MODE_SELECTION_POINT
      The selection with point mode.
      static java.lang.String MODE_SELECTION_PROPERTY
      The image feature selection mode property name.
      static int MODE_SELECTION_RECT
      The selection with rectangle mode.
      static int MODE_SELECTION_SHAPE
      The selection with shape mode.
      static java.lang.String SCALE_PROPERTY
      The image feature scale property name.
      • Fields inherited from class javax.swing.JComponent

        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.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
      JImagePanel()
      Create a new image panel.
      JImagePanel​(java.awt.image.BufferedImage image)
      Create a new image panel that display the given image.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addImageFeature​(JImageFeature feature)
      Attach the given image feature to this panel.
      protected void drawSelectionShape​(java.awt.Graphics2D g2d, java.awt.Shape shape)
      Draw the given selection shape on the given graphics context.
      void fit()
      Fit the view in order to display the whole image.
      java.awt.image.BufferedImage getImage()
      Get the image that is displayed within the panel.
      java.awt.geom.Point2D getImageCoordinate​(int x, int y)
      Get the coordinate within the image referential of the point located at (x, y) on the panel component.
      java.util.List<JImageFeature> getImageFeatures()
      Get the image features attached to this panel.
      double getScale()
      Get the current scale factor of the panel view.
      int getSelectionMode()
      Get the selection mode used by the panel.
      java.awt.Stroke getSelectionShapeStroke()
      Get the stroke used when drawing selection shape.
      java.awt.geom.Point2D getTranslation()
      Get the translation applied to the view as a 2D point.
      java.awt.geom.Point2D getViewCoordinate​(float x, float y)
      Get the coordinate within the view referential of the point located at (x, y) on the image.
      boolean isAutoFit()
      Get if the panel fits the view when its resized.
      boolean isAutoRepaint()
      Get if the panel is using auto repaint.
      boolean isRendering()
      Check if the panel is actually refreshing image and features.
      void paintComponent​(java.awt.Graphics g)  
      boolean removeImageFeature​(JImageFeature feature)
      Remove the given image feature from this panel.
      void setAutoFit​(boolean autoFit)
      Set if the panel has to fit the view when its resized.
      void setAutoRepaint​(boolean auto)
      Set if the panel has to do auto repaint.
      void setImage​(java.awt.image.BufferedImage image)
      Set the image to display within the panel.
      void setImageFeatures​(java.util.List<JImageFeature> features)
      Set the image features to attach to this panel.
      void setScale​(double zoom)
      Set the scale factor to apply to the panel view.
      void setSelectionMode​(int mode)
      Set the selection mode that the panel has to use.
      void setSelectionShapeStroke​(java.awt.Stroke stroke)
      Set the stroke to use when drawing selection shape.
      void setTranslation​(java.awt.geom.Point2D translation)
      Set the translation to apply to the view.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
      • Methods 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, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MODE_SELECTION_PROPERTY

        public static final java.lang.String MODE_SELECTION_PROPERTY
        The image feature selection mode property name. This name enable to identify the property when a property change event is fired from this object.
        See Also:
        Constant Field Values
      • SCALE_PROPERTY

        public static final java.lang.String SCALE_PROPERTY
        The image feature scale property name. This name enable to identify the property when a property change event is fired from this object.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JImagePanel

        public JImagePanel()
        Create a new image panel.
      • JImagePanel

        public JImagePanel​(java.awt.image.BufferedImage image)
        Create a new image panel that display the given image.
        Parameters:
        image - the image to display.
    • Method Detail

      • paintComponent

        public void paintComponent​(java.awt.Graphics g)
        Overrides:
        paintComponent in class javax.swing.JComponent
      • drawSelectionShape

        protected void drawSelectionShape​(java.awt.Graphics2D g2d,
                                          java.awt.Shape shape)
        Draw the given selection shape on the given graphics context.
        Parameters:
        g2d - the the given graphics context.
        shape - the shape to draw.
      • isRendering

        public boolean isRendering()
        Check if the panel is actually refreshing image and features.
        Returns:
        true if the panel is actually refreshing image and features and false otherwise.
      • getSelectionShapeStroke

        public java.awt.Stroke getSelectionShapeStroke()
        Get the stroke used when drawing selection shape.
        Returns:
        the stroke used when drawing selection shape.
        See Also:
        setSelectionShapeStroke(Stroke)
      • setSelectionShapeStroke

        public void setSelectionShapeStroke​(java.awt.Stroke stroke)
        Set the stroke to use when drawing selection shape.
        Parameters:
        stroke - the stroke to use.
        See Also:
        getSelectionShapeStroke()
      • isAutoRepaint

        public boolean isAutoRepaint()
        Get if the panel is using auto repaint. If the auto repaint mode is activated, the panel will repaint every time a modification is made to the displayed object (image, features) or to the view (scale, translation, ...). This mode is not convenient if many modification has to be made before a display refresh. In this case, it is recommended to set the auto repaint to false and to call Component.repaint() when all modifications are done.
        Returns:
        true if the panel has to auto repaint and false otherwise.
        See Also:
        setAutoRepaint(boolean)
      • setAutoRepaint

        public void setAutoRepaint​(boolean auto)
        Set if the panel has to do auto repaint. If the auto repaint mode is activated, the panel will repaint every time a modification is made to the displayed object (image, features) or to the view (scale, translation, ...). This mode is not convenient if many modification has to be made before a display refresh. In this case, it is recommended to set the auto repaint to false and to call Component.repaint() when all modifications are done.
        Parameters:
        auto - true if the panel has to auto repaint and false otherwise.
        See Also:
        isAutoRepaint()
      • isAutoFit

        public boolean isAutoFit()
        Get if the panel fits the view when its resized.
        Returns:
        true if the panel fits the view when its resized and false otherwise.
        See Also:
        setAutoFit(boolean), fit()
      • setAutoFit

        public void setAutoFit​(boolean autoFit)
        Set if the panel has to fit the view when its resized.
        Parameters:
        autoFit - true if the panel fits the view when its resized and false otherwise.
        See Also:
        isAutoFit(), fit()
      • getImage

        public java.awt.image.BufferedImage getImage()
        Get the image that is displayed within the panel.
        Returns:
        the image that is displayed within the panel.
        See Also:
        setImage(BufferedImage)
      • setImage

        public void setImage​(java.awt.image.BufferedImage image)
        Set the image to display within the panel.
        Parameters:
        image - the image to display within the panel.
        See Also:
        getImage()
      • getScale

        public double getScale()
        Get the current scale factor of the panel view.
        Returns:
        the current scale factor of the panel view.
        See Also:
        setScale(double), getTranslation()
      • setScale

        public void setScale​(double zoom)
        Set the scale factor to apply to the panel view.
        Parameters:
        zoom - the current scale factor of the panel view.
        See Also:
        getScale(), setTranslation(Point2D)
      • getTranslation

        public java.awt.geom.Point2D getTranslation()
        Get the translation applied to the view as a 2D point.
        Returns:
        the translation applied to the view.
        See Also:
        setTranslation(Point2D), getScale()
      • setTranslation

        public void setTranslation​(java.awt.geom.Point2D translation)
        Set the translation to apply to the view.
        Parameters:
        translation - the translation to apply to the view as a 2D point.
        See Also:
        getTranslation(), setScale(double)
      • fit

        public void fit()
        Fit the view in order to display the whole image. This method update the view transformation (scale, translation) in order to make the whole image visible.
      • setImageFeatures

        public void setImageFeatures​(java.util.List<JImageFeature> features)
        Set the image features to attach to this panel.
        Parameters:
        features - the image features attached to attach to this panel.
        See Also:
        getImageFeatures()
      • getImageCoordinate

        public java.awt.geom.Point2D getImageCoordinate​(int x,
                                                        int y)
        Get the coordinate within the image referential of the point located at (x, y) on the panel component.
        Parameters:
        x - the x coordinate of the point on the panel component.
        y - the y coordinate of the point on the panel component.
        Returns:
        the coordinate within the image of the point located at (x, y) on the panel component.
        See Also:
        getViewCoordinate(float, float)
      • getViewCoordinate

        public java.awt.geom.Point2D getViewCoordinate​(float x,
                                                       float y)
        Get the coordinate within the view referential of the point located at (x, y) on the image.
        Parameters:
        x - the x coordinate of the point on the image.
        y - the y coordinate of the point on the image.
        Returns:
        the coordinate within the view referential of the point located at (x, y) on the image.
        See Also:
        getImageCoordinate(int, int)