001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.layer.geoimage.viewers.projections; 003 004import java.awt.Component; 005import java.awt.Graphics; 006import java.awt.Image; 007import java.awt.Point; 008import java.awt.Rectangle; 009import java.awt.event.ComponentListener; 010import java.awt.image.BufferedImage; 011import java.util.Set; 012 013import org.openstreetmap.josm.data.imagery.street_level.Projections; 014import org.openstreetmap.josm.gui.layer.geoimage.ImageDisplay; 015import org.openstreetmap.josm.gui.util.imagery.Vector3D; 016 017/** 018 * An interface for image viewers for specific projections 019 * @since 18246 020 */ 021public interface IImageViewer extends ComponentListener { 022 /** 023 * Get the supported projections for the image viewer 024 * @return The projections supported. Typically, only one. 025 */ 026 Set<Projections> getSupportedProjections(); 027 028 /** 029 * Paint the image 030 * @param g The graphics to paint on 031 * @param image The image to paint 032 * @param target The target area 033 * @param visibleRect The visible rectangle 034 */ 035 void paintImage(Graphics g, BufferedImage image, Rectangle target, Rectangle visibleRect); 036 037 /** 038 * Get the default visible rectangle for the projection 039 * @param component The component the image will be displayed in 040 * @param image The image that will be shown 041 * @return The default visible rectangle 042 */ 043 ImageDisplay.VisRect getDefaultVisibleRectangle(Component component, Image image); 044 045 /** 046 * Get the current rotation in the image viewer 047 * @return The rotation 048 * @since 18263 049 */ 050 default Vector3D getRotation() { 051 return null; 052 } 053 054 /** 055 * Indicate that the mouse has been dragged to a point 056 * @param from The point the mouse was dragged from 057 * @param to The point the mouse has been dragged to 058 * @param currentVisibleRect The currently visible rectangle (this is updated by the default implementation) 059 */ 060 default void mouseDragged(Point from, Point to, ImageDisplay.VisRect currentVisibleRect) { 061 currentVisibleRect.isDragUpdate = true; 062 currentVisibleRect.x += from.x - to.x; 063 currentVisibleRect.y += from.y - to.y; 064 } 065 066 /** 067 * Check and modify the visible rect size to appropriate dimensions 068 * @param visibleRect the visible rectangle to update 069 * @param image The image to use for checking 070 */ 071 default void checkAndModifyVisibleRectSize(Image image, ImageDisplay.VisRect visibleRect) { 072 if (visibleRect.width > image.getWidth(null)) { 073 visibleRect.width = image.getWidth(null); 074 } 075 if (visibleRect.height > image.getHeight(null)) { 076 visibleRect.height = image.getHeight(null); 077 } 078 } 079 080 /** 081 * Get the maximum image size that can be displayed 082 * @param imageDisplay The image display 083 * @param image The image 084 * @return The maximum image size (may be the original image passed in) 085 */ 086 default Image getMaxImageSize(ImageDisplay imageDisplay, Image image) { 087 return image; 088 } 089}