java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jorigin.swing.JImagePanel
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
A
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
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.4
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested 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 TypeFieldDescriptionstatic final intThe selection with point mode.static final StringThe image feature selection mode property name.static final intThe selection with rectangle mode.static final intThe selection with shape mode.static final StringThe 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_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
ConstructorsConstructorDescriptionCreate a new image panel.JImagePanel(BufferedImage image) Create a new image panel that display the givenimage. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddImageFeature(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.getImage()Get theimagethat is displayed within the panel.getImageCoordinate(int x, int y) Get the coordinate within the image referential of the point located at (x,y) on the panel component.getImageFeatures(String layer) Get theimage featurescontained within the specifiedlayerattached to this panel.Get therendering hintsthat this panel use.doublegetScale()Get the current scale factor of the panel view.intGet the selection mode used by the panel.Get thestrokeused when drawing selection shape.Get the translation applied to the view as a2D point.getViewCoordinate(float x, float y) Get the coordinate within the view referential of the point located at (x,y) on the image.booleanGet if the panel fits the view when its resized.booleanGet if the panel is using auto repaint.booleanisLayerDisplayed(String layer) Check if the givenlayeris displayed.booleanCheck if the panel is actually refreshing image and features.voidbooleanremoveImageFeature(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, updateUIMethods 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, updateMethods 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, 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_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:
-
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:
-
MODE_SELECTION_POINT
public static final int MODE_SELECTION_POINTThe selection with point mode. This mode enable to select features on the image using a point.- See Also:
-
MODE_SELECTION_RECT
public static final int MODE_SELECTION_RECTThe selection with rectangle mode. This mode enable to select features on the image using a rectangle.- See Also:
-
MODE_SELECTION_SHAPE
public static final int MODE_SELECTION_SHAPEThe selection with shape mode. This mode enable to select features on the image using a custom shape.- See Also:
-
-
Constructor Details
-
Method Details
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
drawSelectionShape
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
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
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:
-
getSelectionShapeStroke
Get thestrokeused when drawing selection shape.- Returns:
- the
strokeused when drawing selection shape. - See Also:
-
setSelectionShapeStroke
Set thestroketo use when drawing selection shape.- Parameters:
stroke- thestroketo use.- See Also:
-
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
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:
-
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
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:
-
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
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:
-
getImage
Get theimagethat is displayed within the panel.- Returns:
- the
imagethat is displayed within the panel. - See Also:
-
setImage
Set theimageto display within the panel.- Parameters:
image- theimageto display within the panel.- See Also:
-
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
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:
-
getTranslation
Get the translation applied to the view as a2D point.- Returns:
- the translation applied to the view.
- See Also:
-
setTranslation
Set the translation to apply to the view.- Parameters:
translation- the translation to apply to the view as a2D point.- See Also:
-
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
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
Set if the givenlayerhas to be displayed.- Parameters:
layer- the layer to check.displayed-trueif the layer has to be displayed andfalseotherwise.
-
getImageFeatures
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
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:
-
addImageFeature
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
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:
-
getImageCoordinate
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
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:
-