Class ImageDisplay
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.openstreetmap.josm.gui.layer.geoimage.ImageDisplay
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,ImageryFilterSettings.FilterChangeListener,PreferenceChangedListener,Destroyable
public class ImageDisplay
extends JComponent
implements Destroyable, PreferenceChangedListener, ImageryFilterSettings.FilterChangeListener
GUI component to display an image (photograph).
Offers basic mouse interaction (zoom, drag) and on-screen text.
- Since:
- 2566
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classprotected classThe thread that reads the images.private final classstatic classManage the visible rectangle of an image with full bounds stored in init.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 TypeFieldDescriptionprivate static final BooleanPropertyprivate booleanprivate static intprivate Stringprivate IImageEntry<?>The file that is currently displayedprivate static final BooleanPropertyShow a background for the error text (may be hard on eyes)private booleanThe image currently displayedprivate IImageViewerThe current image viewerprivate BufferedImageThe image currently displayedprivate final ImageProcessorProcess the image before it is being displayedprivate final ImageDisplay.ImgDisplayMouseListenerprivate static final IntegerPropertyMaximum width (in pixels) for loading imagesprivate static final DoublePropertyMaximum zoom allowedprivate IImageEntry<?>The previous file that is currently displayed.private Stringprivate BufferedImageThe image currently displayed after applyingimageProcessorprivate ImageDisplay.VisRectWhen a selection is done, the rectangle of the selection (in image coordinates)private ImageDisplay.UpdateImageThreadprivate ImageDisplay.VisRectThe rectangle (in image coordinates) of the image that is visible.private static final BooleanPropertyAlternative to mouse wheel zoom; esp.private static final DoublePropertyZoom factor when click or wheel zoomingprivate static 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
ConstructorsConstructorDescriptionConstructs a newImageDisplaywith no image processor.ImageDisplay(ImageProcessor imageProcessor) Constructs a newImageDisplaywith a given image processor. -
Method Summary
Modifier and TypeMethodDescription(package private) static ImageDisplay.VisRectcalculateDrawImageRectangle(ImageDisplay.VisRect visibleRect, Dimension compSize) calculateDrawImageRectangle(package private) static ImageDisplay.VisRectcalculateDrawImageRectangle(ImageDisplay.VisRect imgRect, Rectangle compRect) calculateDrawImageRectangle(package private) static Pointcomp2imgCoord(ImageDisplay.VisRect visibleRect, int xComp, int yComp, Dimension compSize) voiddestroy()Called when the object has been destroyed.private voidensureMaxZoom(Rectangle rectangle) Ensure that a rectangle isn't zoomed in too muchvoidInvoked when the filter is changed.(package private) static PointgetCenterImgCoord(Rectangle visibleRect) private IImageViewergetIImageViewer(IImageEntry<?> entry) Get the image viewer for an entrygetRotation(IImageEntry<?> entry) Get the rotation in the image viewer for an entry(package private) static Pointimg2compCoord(ImageDisplay.VisRect visibleRect, int xImg, int yImg, Dimension compSize) voidprivate voidpaintErrorMessage(Graphics g, IImageEntry<?> imageEntry, IImageEntry<?> oldImageEntry, BufferedImage bufferedImage, boolean currentErrorLoading, Dimension size) Paint an error messageprivate voidPaint OSD textprivate voidpaintSelectedRect(Graphics g, Rectangle target, ImageDisplay.VisRect visibleRectTemp, Dimension size) Paint the selected rectanglevoidTriggered when a preference entry value changes.voidsetEmptyText(String emptyText) Set the message displayed when there is no image to display.Future<?>setImage(IImageEntry<?> entry) Sets a new source image to be displayed by thisImageDisplay.protected ImageDisplay.LoadImageRunnablesetImage0(IImageEntry<?> entry) voidsetOsdText(String text) Sets the On-Screen-Display text.private voidvoidUpdate the visible rectangle (ensure zoom does not exceed specified values).voidMake the current image either scale to fit inside this component, or show a portion of image (1:1), if the image size is larger than the component size.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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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
-
iImageViewer
The current image viewer -
entry
The file that is currently displayed -
oldEntry
The previous file that is currently displayed. Cleared on paint. Only used to help improve UI error information. -
image
The image currently displayed -
processedImage
The image currently displayed after applyingimageProcessor -
imageProcessor
Process the image before it is being displayed -
errorLoading
The image currently displayed -
visibleRect
The rectangle (in image coordinates) of the image that is visible. This rectangle is calculated each time the zoom is modified -
selectedRect
When a selection is done, the rectangle of the selection (in image coordinates) -
imgMouseListener
-
emptyText
-
osdText
-
AGPIFO_STYLE
-
dragButton
-
zoomButton
-
ZOOM_ON_CLICK
Alternative to mouse wheel zoom; esp. handy if no mouse wheel is present -
ZOOM_STEP
Zoom factor when click or wheel zooming -
MAX_ZOOM
Maximum zoom allowed -
MAX_WIDTH
Maximum width (in pixels) for loading images -
ERROR_MESSAGE_BACKGROUND
Show a background for the error text (may be hard on eyes) -
updateImageThreadInstance
-
destroyed
-
-
Constructor Details
-
ImageDisplay
public ImageDisplay()Constructs a newImageDisplaywith no image processor. -
ImageDisplay
Constructs a newImageDisplaywith a given image processor.- Parameters:
imageProcessor- image processor- Since:
- 17740
-
-
Method Details
-
preferenceChanged
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-
destroy
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable
-
setImage
Sets a new source image to be displayed by thisImageDisplay.- Parameters:
entry- new source image- Returns:
- a
Futurerepresenting pending completion of the image loading task - Since:
- 18246 (signature)
-
setImage0
-
setEmptyText
Set the message displayed when there is no image to display. By default it display a simple No image- Parameters:
emptyText- the string to display- Since:
- 15333
-
setOsdText
Sets the On-Screen-Display text.- Parameters:
text- text to display on top of the image
-
filterChanged
Description copied from interface:ImageryFilterSettings.FilterChangeListenerInvoked when the filter is changed.- Specified by:
filterChangedin interfaceImageryFilterSettings.FilterChangeListener
-
updateProcessedImage
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
paintErrorMessage
private void paintErrorMessage(Graphics g, IImageEntry<?> imageEntry, IImageEntry<?> oldImageEntry, BufferedImage bufferedImage, boolean currentErrorLoading, Dimension size) Paint an error message- Parameters:
g- The graphics to paint onimageEntry- The current image entryoldImageEntry- The old image entrybufferedImage- The image being paintedcurrentErrorLoading- If there was an error loading the imagesize- The size of the component
-
paintOsdText
Paint OSD text- Parameters:
g- The graphics to paint on
-
paintSelectedRect
private void paintSelectedRect(Graphics g, Rectangle target, ImageDisplay.VisRect visibleRectTemp, Dimension size) Paint the selected rectangle- Parameters:
g- The graphics to paint ontarget- The target area (i.e., the selection)visibleRectTemp- The current visible rectsize- The size of the component
-
img2compCoord
static Point img2compCoord(ImageDisplay.VisRect visibleRect, int xImg, int yImg, Dimension compSize) -
comp2imgCoord
static Point comp2imgCoord(ImageDisplay.VisRect visibleRect, int xComp, int yComp, Dimension compSize) -
getCenterImgCoord
-
calculateDrawImageRectangle
static ImageDisplay.VisRect calculateDrawImageRectangle(ImageDisplay.VisRect visibleRect, Dimension compSize) calculateDrawImageRectangle- Parameters:
visibleRect- the part of the image that should be drawn (in image coordinates)compSize- the part of the component where the image should be drawn (in component coordinates)- Returns:
- the part of compRect with the same width/height ratio as the image
-
calculateDrawImageRectangle
static ImageDisplay.VisRect calculateDrawImageRectangle(ImageDisplay.VisRect imgRect, Rectangle compRect) calculateDrawImageRectangle- Parameters:
imgRect- the part of the image that should be drawn (in image coordinates)compRect- the part of the component where the image should be drawn (in component coordinates)- Returns:
- the part of compRect with the same width/height ratio as the image
-
zoomBestFitOrOne
Make the current image either scale to fit inside this component, or show a portion of image (1:1), if the image size is larger than the component size. -
getIImageViewer
Get the image viewer for an entry- Parameters:
entry- The entry to get the viewer for. May benull.- Returns:
- The new image viewer, may be
null
-
getRotation
Get the rotation in the image viewer for an entry- Parameters:
entry- The entry to get the rotation for. May benull.- Returns:
- the current rotation in the image viewer, or
null - Since:
- 18263
-
ensureMaxZoom
Ensure that a rectangle isn't zoomed in too much- Parameters:
rectangle- The rectangle to get (typically the visible area)
-
updateVisibleRectangle
Update the visible rectangle (ensure zoom does not exceed specified values). Specifically only visible forIImageViewerimplementations.- Since:
- 18246
-