Class ImageDisplay
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- org.openstreetmap.josm.gui.layer.geoimage.ImageDisplay
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,ImageryFilterSettings.FilterChangeListener
,PreferenceChangedListener
,Destroyable
public class ImageDisplay extends javax.swing.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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ImageDisplay.ImgDisplayMouseListener
protected class
ImageDisplay.LoadImageRunnable
The thread that reads the images.private class
ImageDisplay.UpdateImageThread
static class
ImageDisplay.VisRect
Manage the visible rectangle of an image with full bounds stored in init.-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private static BooleanProperty
AGPIFO_STYLE
private boolean
destroyed
private static int
dragButton
private java.lang.String
emptyText
private IImageEntry<?>
entry
The file that is currently displayedprivate static BooleanProperty
ERROR_MESSAGE_BACKGROUND
Show a background for the error text (may be hard on eyes)private boolean
errorLoading
The image currently displayedprivate IImageViewer
iImageViewer
The current image viewerprivate java.awt.image.BufferedImage
image
The image currently displayedprivate ImageProcessor
imageProcessor
Process the image before it is being displayedprivate ImageDisplay.ImgDisplayMouseListener
imgMouseListener
private static IntegerProperty
MAX_WIDTH
Maximum width (in pixels) for loading imagesprivate static DoubleProperty
MAX_ZOOM
Maximum zoom allowedprivate IImageEntry<?>
oldEntry
The previous file that is currently displayed.private java.lang.String
osdText
private java.awt.image.BufferedImage
processedImage
The image currently displayed after applyingimageProcessor
private ImageDisplay.VisRect
selectedRect
When a selection is done, the rectangle of the selection (in image coordinates)private ImageDisplay.UpdateImageThread
updateImageThreadInstance
private ImageDisplay.VisRect
visibleRect
The rectangle (in image coordinates) of the image that is visible.private static BooleanProperty
ZOOM_ON_CLICK
Alternative to mouse wheel zoom; esp.private static DoubleProperty
ZOOM_STEP
Zoom factor when click or wheel zoomingprivate static int
zoomButton
-
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
-
-
Constructor Summary
Constructors Constructor Description ImageDisplay()
Constructs a newImageDisplay
with no image processor.ImageDisplay(ImageProcessor imageProcessor)
Constructs a newImageDisplay
with a given image processor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static ImageDisplay.VisRect
calculateDrawImageRectangle(ImageDisplay.VisRect visibleRect, java.awt.Dimension compSize)
calculateDrawImageRectangle(package private) static ImageDisplay.VisRect
calculateDrawImageRectangle(ImageDisplay.VisRect imgRect, java.awt.Rectangle compRect)
calculateDrawImageRectangle(package private) static java.awt.Point
comp2imgCoord(ImageDisplay.VisRect visibleRect, int xComp, int yComp, java.awt.Dimension compSize)
void
destroy()
Called when the object has been destroyed.private void
ensureMaxZoom(java.awt.Rectangle rectangle)
Ensure that a rectangle isn't zoomed in too muchvoid
filterChanged()
Invoked when the filter is changed.(package private) static java.awt.Point
getCenterImgCoord(java.awt.Rectangle visibleRect)
private IImageViewer
getIImageViewer(IImageEntry<?> entry)
Get the image viewer for an entryVector3D
getRotation(IImageEntry<?> entry)
Get the rotation in the image viewer for an entry(package private) static java.awt.Point
img2compCoord(ImageDisplay.VisRect visibleRect, int xImg, int yImg, java.awt.Dimension compSize)
void
paintComponent(java.awt.Graphics g)
private void
paintErrorMessage(java.awt.Graphics g, IImageEntry<?> imageEntry, IImageEntry<?> oldImageEntry, java.awt.image.BufferedImage bufferedImage, boolean currentErrorLoading, java.awt.Dimension size)
Paint an error messageprivate void
paintOsdText(java.awt.Graphics g)
Paint OSD textprivate void
paintSelectedRect(java.awt.Graphics g, java.awt.Rectangle target, ImageDisplay.VisRect visibleRectTemp, java.awt.Dimension size)
Paint the selected rectanglevoid
preferenceChanged(PreferenceChangeEvent e)
Triggered when a preference entry value changes.void
setEmptyText(java.lang.String emptyText)
Set the message displayed when there is no image to display.java.util.concurrent.Future<?>
setImage(IImageEntry<?> entry)
Sets a new source image to be displayed by thisImageDisplay
.protected ImageDisplay.LoadImageRunnable
setImage0(IImageEntry<?> entry)
void
setOsdText(java.lang.String text)
Sets the On-Screen-Display text.private void
updateProcessedImage()
void
updateVisibleRectangle()
Update the visible rectangle (ensure zoom does not exceed specified values).void
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.-
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, updateUI
-
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, 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 Detail
-
iImageViewer
private IImageViewer iImageViewer
The current image viewer
-
entry
private IImageEntry<?> entry
The file that is currently displayed
-
oldEntry
private IImageEntry<?> oldEntry
The previous file that is currently displayed. Cleared on paint. Only used to help improve UI error information.
-
image
private transient java.awt.image.BufferedImage image
The image currently displayed
-
processedImage
private transient java.awt.image.BufferedImage processedImage
The image currently displayed after applyingimageProcessor
-
imageProcessor
private final ImageProcessor imageProcessor
Process the image before it is being displayed
-
errorLoading
private boolean errorLoading
The image currently displayed
-
visibleRect
private ImageDisplay.VisRect visibleRect
The rectangle (in image coordinates) of the image that is visible. This rectangle is calculated each time the zoom is modified
-
selectedRect
private ImageDisplay.VisRect selectedRect
When a selection is done, the rectangle of the selection (in image coordinates)
-
imgMouseListener
private final ImageDisplay.ImgDisplayMouseListener imgMouseListener
-
emptyText
private java.lang.String emptyText
-
osdText
private java.lang.String osdText
-
AGPIFO_STYLE
private static final BooleanProperty AGPIFO_STYLE
-
dragButton
private static int dragButton
-
zoomButton
private static int zoomButton
-
ZOOM_ON_CLICK
private static final BooleanProperty ZOOM_ON_CLICK
Alternative to mouse wheel zoom; esp. handy if no mouse wheel is present
-
ZOOM_STEP
private static final DoubleProperty ZOOM_STEP
Zoom factor when click or wheel zooming
-
MAX_ZOOM
private static final DoubleProperty MAX_ZOOM
Maximum zoom allowed
-
MAX_WIDTH
private static final IntegerProperty MAX_WIDTH
Maximum width (in pixels) for loading images
-
ERROR_MESSAGE_BACKGROUND
private static final BooleanProperty ERROR_MESSAGE_BACKGROUND
Show a background for the error text (may be hard on eyes)
-
updateImageThreadInstance
private ImageDisplay.UpdateImageThread updateImageThreadInstance
-
destroyed
private boolean destroyed
-
-
Constructor Detail
-
ImageDisplay
public ImageDisplay()
Constructs a newImageDisplay
with no image processor.
-
ImageDisplay
public ImageDisplay(ImageProcessor imageProcessor)
Constructs a newImageDisplay
with a given image processor.- Parameters:
imageProcessor
- image processor- Since:
- 17740
-
-
Method Detail
-
preferenceChanged
public void preferenceChanged(PreferenceChangeEvent e)
Description copied from interface:PreferenceChangedListener
Triggered when a preference entry value changes.- Specified by:
preferenceChanged
in interfacePreferenceChangedListener
- Parameters:
e
- the preference change event
-
destroy
public void destroy()
Description copied from interface:Destroyable
Called when the object has been destroyed.- Specified by:
destroy
in interfaceDestroyable
-
setImage
public java.util.concurrent.Future<?> setImage(IImageEntry<?> entry)
Sets a new source image to be displayed by thisImageDisplay
.- Parameters:
entry
- new source image- Returns:
- a
Future
representing pending completion of the image loading task - Since:
- 18246 (signature)
-
setImage0
protected ImageDisplay.LoadImageRunnable setImage0(IImageEntry<?> entry)
-
setEmptyText
public void setEmptyText(java.lang.String emptyText)
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
public void setOsdText(java.lang.String text)
Sets the On-Screen-Display text.- Parameters:
text
- text to display on top of the image
-
filterChanged
public void filterChanged()
Description copied from interface:ImageryFilterSettings.FilterChangeListener
Invoked when the filter is changed.- Specified by:
filterChanged
in interfaceImageryFilterSettings.FilterChangeListener
-
updateProcessedImage
private void updateProcessedImage()
-
paintComponent
public void paintComponent(java.awt.Graphics g)
- Overrides:
paintComponent
in classjavax.swing.JComponent
-
paintErrorMessage
private void paintErrorMessage(java.awt.Graphics g, IImageEntry<?> imageEntry, IImageEntry<?> oldImageEntry, java.awt.image.BufferedImage bufferedImage, boolean currentErrorLoading, java.awt.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
private void paintOsdText(java.awt.Graphics g)
Paint OSD text- Parameters:
g
- The graphics to paint on
-
paintSelectedRect
private void paintSelectedRect(java.awt.Graphics g, java.awt.Rectangle target, ImageDisplay.VisRect visibleRectTemp, java.awt.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 java.awt.Point img2compCoord(ImageDisplay.VisRect visibleRect, int xImg, int yImg, java.awt.Dimension compSize)
-
comp2imgCoord
static java.awt.Point comp2imgCoord(ImageDisplay.VisRect visibleRect, int xComp, int yComp, java.awt.Dimension compSize)
-
getCenterImgCoord
static java.awt.Point getCenterImgCoord(java.awt.Rectangle visibleRect)
-
calculateDrawImageRectangle
static ImageDisplay.VisRect calculateDrawImageRectangle(ImageDisplay.VisRect visibleRect, java.awt.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, java.awt.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
public void 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
private IImageViewer getIImageViewer(IImageEntry<?> entry)
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
public Vector3D getRotation(IImageEntry<?> entry)
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
private void ensureMaxZoom(java.awt.Rectangle rectangle)
Ensure that a rectangle isn't zoomed in too much- Parameters:
rectangle
- The rectangle to get (typically the visible area)
-
updateVisibleRectangle
public void updateVisibleRectangle()
Update the visible rectangle (ensure zoom does not exceed specified values). Specifically only visible forIImageViewer
implementations.- Since:
- 18246
-
-