- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.jorigin.gui.JImagePanel
-
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
public class JImagePanel extends JPanel
Aswing componentthat enables to displayimages.
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 managesfeaturesthat enable to display interactive overlays on the panel.- Since:
- 1.0.4
- Version:
- "1.0.12" - b202004280800L
- 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
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
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 static intMODE_SELECTION_POINTThe selection with point mode.static StringMODE_SELECTION_PROPERTYThe image feature selection mode property name.static intMODE_SELECTION_RECTThe selection with rectangle mode.static intMODE_SELECTION_SHAPEThe selection with shape mode.static StringSCALE_PROPERTYThe 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(BufferedImage image)Create a new image panel that display the givenimage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddImageFeature(String layer, JImageFeature feature)Attach the givenimage featureto this panel within the specifiedlayer.protected voiddrawSelectionShape(Graphics2D g2d, Shape shape)Draw the given selectionshapeon the givengraphics context.voidfit()Fit the view in order to display the wholeimage.BufferedImagegetImage()Get theimagethat is displayed within the panel.Point2DgetImageCoordinate(int x, int y)Get the coordinate within the image referential of the point located at (x,y) on the panel component.List<JImageFeature>getImageFeatures(String layer)Get theimage featurescontained within the specifiedlayerattached to this panel.RenderingHintsgetRenderingHints()Get therendering hintsthat this panel use.doublegetScale()Get the current scale factor of the panel view.intgetSelectionMode()Get the selection mode used by the panel.StrokegetSelectionShapeStroke()Get thestrokeused when drawing selection shape.Point2DgetTranslation()Get the translation applied to the view as a2D point.Point2DgetViewCoordinate(float x, float y)Get the coordinate within the view referential of the point located at (x,y) on the image.booleanisAutoFit()Get if the panel fits the view when its resized.booleanisAutoRepaint()Get if the panel is using auto repaint.booleanisLayerDisplayed(String layer)Check if the givenlayeris displayed.booleanisRendering()Check if the panel is actually refreshing image and features.voidpaintComponent(Graphics g)booleanremoveImageFeature(String layer, JImageFeature feature)Remove the givenimage featurefrom the specifiedlayer.voidsetAutoFit(boolean autoFit)Set if the panel has to fit the view when its resized.voidsetAutoRepaint(boolean auto)Set if the panel has to do auto repaint.voidsetImage(BufferedImage image)Set theimageto display within the panel.voidsetImageFeatures(String layer, List<JImageFeature> features)Set theimage featuresto attach to this panel within the specifiedlayer.voidsetLayerDisplayed(String layer, boolean displayed)Set if the givenlayerhas to be displayed.voidsetRenderingHints(RenderingHints hints)Set therendering hintsthat this panel has to use.voidsetScale(double zoom)Set the scale factor to apply to the panel view.voidsetSelectionMode(int mode)Set the selection mode that the panel has to use.voidsetSelectionShapeStroke(Stroke stroke)Set thestroketo use when drawing selection shape.voidsetTranslation(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
-
-
-
-
Field Detail
-
MODE_SELECTION_PROPERTY
public static final String MODE_SELECTION_PROPERTY
The image feature selection mode property name. This name enable to identify the property when aproperty change eventis fired from this object.- See Also:
- Constant Field Values
-
SCALE_PROPERTY
public static final String SCALE_PROPERTY
The image feature scale property name. This name enable to identify the property when aproperty change eventis fired from this object.- See Also:
- Constant Field Values
-
MODE_SELECTION_POINT
public static final int MODE_SELECTION_POINT
The selection with point mode. This mode enable to select features on the image using a point.
-
MODE_SELECTION_RECT
public static final int MODE_SELECTION_RECT
The selection with rectangle mode. This mode enable to select features on the image using a rectangle.
-
MODE_SELECTION_SHAPE
public static final int MODE_SELECTION_SHAPE
The selection with shape mode. This mode enable to select features on the image using a custom shape.
-
-
Constructor Detail
-
JImagePanel
public JImagePanel()
Create a new image panel.
-
JImagePanel
public JImagePanel(BufferedImage image)
Create a new image panel that display the givenimage.- Parameters:
image- theimageto display.
-
-
Method Detail
-
paintComponent
public void paintComponent(Graphics g)
- Overrides:
paintComponentin classJComponent
-
drawSelectionShape
protected void drawSelectionShape(Graphics2D g2d, Shape shape)
Draw the given selectionshapeon the givengraphics context.- Parameters:
g2d- the the givengraphics context.shape- theshapeto draw.
-
isRendering
public boolean isRendering()
Check if the panel is actually refreshing image and features.- Returns:
trueif the panel is actually refreshing image and features andfalseotherwise.
-
getRenderingHints
public RenderingHints getRenderingHints()
Get therendering hintsthat this panel use. If this method returnnull, default rendering hints are used.- Returns:
- the
rendering hintsthat this panel use. - See Also:
setRenderingHints(RenderingHints)
-
setRenderingHints
public void setRenderingHints(RenderingHints hints)
Set therendering hintsthat this panel has to use. Ifhintsparameter is set tonull, then default rendering hints are used.- Parameters:
hints- therendering hintsthat this panel has to use.- See Also:
getRenderingHints()
-
getSelectionShapeStroke
public Stroke getSelectionShapeStroke()
Get thestrokeused when drawing selection shape.- Returns:
- the
strokeused when drawing selection shape. - See Also:
setSelectionShapeStroke(Stroke)
-
setSelectionShapeStroke
public void setSelectionShapeStroke(Stroke stroke)
Set thestroketo use when drawing selection shape.- Parameters:
stroke- thestroketo use.- See Also:
getSelectionShapeStroke()
-
getSelectionMode
public int getSelectionMode()
Get the selection mode used by the panel. This can be one of:MODE_SELECTION_POINTfor a point selection.MODE_SELECTION_RECTfor a rectangle based selection.MODE_SELECTION_SHAPEfor a custom shape based selection.
- Returns:
- the selection mode used by the panel.
- See Also:
setSelectionMode(int)
-
setSelectionMode
public void setSelectionMode(int mode)
Set the selection mode that the panel has to use. This can be one of:MODE_SELECTION_POINTfor a point selection.MODE_SELECTION_RECTfor a rectangle based selection.MODE_SELECTION_SHAPEfor a custom shape based selection.
- Parameters:
mode- the selection mode that the panel has to use.- See Also:
getSelectionMode()
-
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 tofalseand to callComponent.repaint()when all modifications are done.- Returns:
trueif the panel has to auto repaint andfalseotherwise.- 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 tofalseand to callComponent.repaint()when all modifications are done.- Parameters:
auto-trueif the panel has to auto repaint andfalseotherwise.- See Also:
isAutoRepaint()
-
isAutoFit
public boolean isAutoFit()
Get if the panel fits the view when its resized.- Returns:
trueif the panel fits the view when its resized andfalseotherwise.- 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-trueif the panel fits the view when its resized andfalseotherwise.- See Also:
isAutoFit(),fit()
-
getImage
public BufferedImage getImage()
Get theimagethat is displayed within the panel.- Returns:
- the
imagethat is displayed within the panel. - See Also:
setImage(BufferedImage)
-
setImage
public void setImage(BufferedImage image)
Set theimageto display within the panel.- Parameters:
image- theimageto 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 Point2D getTranslation()
Get the translation applied to the view as a2D point.- Returns:
- the translation applied to the view.
- See Also:
setTranslation(Point2D),getScale()
-
setTranslation
public void setTranslation(Point2D translation)
Set the translation to apply to the view.- Parameters:
translation- the translation to apply to the view as a2D point.- See Also:
getTranslation(),setScale(double)
-
fit
public void fit()
Fit the view in order to display the wholeimage. This method update the view transformation (scale, translation) in order to make the whole image visible.
-
isLayerDisplayed
public boolean isLayerDisplayed(String layer)
Check if the givenlayeris displayed. If this method returntrue, then the features that are within the layer are visible on the image panel.- Parameters:
layer- the layer to check.- Returns:
trueif the layer is displayed andfalseotherwise.- See Also:
setLayerDisplayed(String, boolean)
-
setLayerDisplayed
public void setLayerDisplayed(String layer, boolean displayed)
Set if the givenlayerhas to be displayed.- Parameters:
layer- the layer to check.displayed-trueif the layer has to be displayed andfalseotherwise.
-
getImageFeatures
public List<JImageFeature> getImageFeatures(String layer)
Get theimage featurescontained within the specifiedlayerattached to this panel.- Parameters:
layer- the layer of the features.- Returns:
- the image features attached to this panel and
nullif the layer is empty or does not exists. - See Also:
setImageFeatures(String, List)
-
setImageFeatures
public void setImageFeatures(String layer, List<JImageFeature> features)
Set theimage featuresto attach to this panel within the specifiedlayer. If thelayerdoes not exist, it is created. In this case, the layer will not be displayed until a call tosetLayerDisplayed(layer, true). If the layer exists, all previous existing features are deleted.- Parameters:
layer- the layer of the features.features- the image features attached to attach to this panel.- See Also:
getImageFeatures(String)
-
addImageFeature
public boolean addImageFeature(String layer, JImageFeature feature)
Attach the givenimage featureto this panel within the specifiedlayer. If thelayerdoes not exist, it is created. In this case, the layer will not be displayed until a call tosetLayerDisplayed(layer, true).- Parameters:
layer- the layer of the feature.feature- theimage featureto attach.- Returns:
trueif the feature is successfully attached andfalseotherwise.- See Also:
removeImageFeature(String, JImageFeature)
-
removeImageFeature
public boolean removeImageFeature(String layer, JImageFeature feature)
Remove the givenimage featurefrom the specifiedlayer.- Parameters:
layer- the layer of the feature.feature- theimage featureto remove.- Returns:
trueif the feature is successfully removed andfalseotherwise.- See Also:
addImageFeature(String, JImageFeature)
-
getImageCoordinate
public 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 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)
-
-