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 classImageDisplay.ImgDisplayMouseListenerprotected classImageDisplay.LoadImageRunnableThe thread that reads the images.private classImageDisplay.UpdateImageThreadstatic classImageDisplay.VisRectManage 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 BooleanPropertyAGPIFO_STYLEprivate booleandestroyedprivate static intdragButtonprivate java.lang.StringemptyTextprivate IImageEntry<?>entryThe file that is currently displayedprivate static BooleanPropertyERROR_MESSAGE_BACKGROUNDShow a background for the error text (may be hard on eyes)private booleanerrorLoadingThe image currently displayedprivate IImageVieweriImageViewerThe current image viewerprivate java.awt.image.BufferedImageimageThe image currently displayedprivate ImageProcessorimageProcessorProcess the image before it is being displayedprivate ImageDisplay.ImgDisplayMouseListenerimgMouseListenerprivate static IntegerPropertyMAX_WIDTHMaximum width (in pixels) for loading imagesprivate static DoublePropertyMAX_ZOOMMaximum zoom allowedprivate IImageEntry<?>oldEntryThe previous file that is currently displayed.private java.lang.StringosdTextprivate java.awt.image.BufferedImageprocessedImageThe image currently displayed after applyingimageProcessorprivate ImageDisplay.VisRectselectedRectWhen a selection is done, the rectangle of the selection (in image coordinates)private ImageDisplay.UpdateImageThreadupdateImageThreadInstanceprivate ImageDisplay.VisRectvisibleRectThe rectangle (in image coordinates) of the image that is visible.private static BooleanPropertyZOOM_ON_CLICKAlternative to mouse wheel zoom; esp.private static DoublePropertyZOOM_STEPZoom factor when click or wheel zoomingprivate static intzoomButton-
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 newImageDisplaywith no image processor.ImageDisplay(ImageProcessor imageProcessor)Constructs a newImageDisplaywith a given image processor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static ImageDisplay.VisRectcalculateDrawImageRectangle(ImageDisplay.VisRect visibleRect, java.awt.Dimension compSize)calculateDrawImageRectangle(package private) static ImageDisplay.VisRectcalculateDrawImageRectangle(ImageDisplay.VisRect imgRect, java.awt.Rectangle compRect)calculateDrawImageRectangle(package private) static java.awt.Pointcomp2imgCoord(ImageDisplay.VisRect visibleRect, int xComp, int yComp, java.awt.Dimension compSize)voiddestroy()Called when the object has been destroyed.private voidensureMaxZoom(java.awt.Rectangle rectangle)Ensure that a rectangle isn't zoomed in too muchvoidfilterChanged()Invoked when the filter is changed.(package private) static java.awt.PointgetCenterImgCoord(java.awt.Rectangle visibleRect)private IImageViewergetIImageViewer(IImageEntry<?> entry)Get the image viewer for an entryVector3DgetRotation(IImageEntry<?> entry)Get the rotation in the image viewer for an entry(package private) static java.awt.Pointimg2compCoord(ImageDisplay.VisRect visibleRect, int xImg, int yImg, java.awt.Dimension compSize)voidpaintComponent(java.awt.Graphics g)private voidpaintErrorMessage(java.awt.Graphics g, IImageEntry<?> imageEntry, IImageEntry<?> oldImageEntry, java.awt.image.BufferedImage bufferedImage, boolean currentErrorLoading, java.awt.Dimension size)Paint an error messageprivate voidpaintOsdText(java.awt.Graphics g)Paint OSD textprivate voidpaintSelectedRect(java.awt.Graphics g, java.awt.Rectangle target, ImageDisplay.VisRect visibleRectTemp, java.awt.Dimension size)Paint the selected rectanglevoidpreferenceChanged(PreferenceChangeEvent e)Triggered when a preference entry value changes.voidsetEmptyText(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.LoadImageRunnablesetImage0(IImageEntry<?> entry)voidsetOsdText(java.lang.String text)Sets the On-Screen-Display text.private voidupdateProcessedImage()voidupdateVisibleRectangle()Update the visible rectangle (ensure zoom does not exceed specified values).voidzoomBestFitOrOne()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 newImageDisplaywith no image processor.
-
ImageDisplay
public ImageDisplay(ImageProcessor imageProcessor)
Constructs a newImageDisplaywith a given image processor.- Parameters:
imageProcessor- image processor- Since:
- 17740
-
-
Method Detail
-
preferenceChanged
public void preferenceChanged(PreferenceChangeEvent e)
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-
destroy
public void destroy()
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin 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
Futurerepresenting 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.FilterChangeListenerInvoked when the filter is changed.- Specified by:
filterChangedin interfaceImageryFilterSettings.FilterChangeListener
-
updateProcessedImage
private void updateProcessedImage()
-
paintComponent
public void paintComponent(java.awt.Graphics g)
- Overrides:
paintComponentin 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 forIImageViewerimplementations.- Since:
- 18246
-
-