Changeset 34760 in osm for applications/viewer
- Timestamp:
- 2018-12-01T21:15:59+01:00 (6 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/FeatureAdapter.java
r31438 r34760 3 3 4 4 import java.awt.Desktop; 5 import java.awt.image.BufferedImage; 5 6 import java.io.IOException; 6 7 import java.net.URI; 7 8 import java.net.URISyntaxException; 9 import java.net.URL; 8 10 import java.text.MessageFormat; 11 import java.util.Objects; 9 12 import java.util.logging.Logger; 13 14 import javax.imageio.ImageIO; 10 15 11 16 public final class FeatureAdapter { 12 17 13 18 private static BrowserAdapter browserAdapter = new DefaultBrowserAdapter(); 19 private static ImageAdapter imageAdapter = new DefaultImageAdapter(); 14 20 private static TranslationAdapter translationAdapter = new DefaultTranslationAdapter(); 15 21 private static LoggingAdapter loggingAdapter = new DefaultLoggingAdapter(); … … 32 38 } 33 39 40 public interface ImageAdapter { 41 BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException; 42 } 43 34 44 public static void registerBrowserAdapter(BrowserAdapter browserAdapter) { 35 FeatureAdapter.browserAdapter = browserAdapter; 45 FeatureAdapter.browserAdapter = Objects.requireNonNull(browserAdapter); 46 } 47 48 public static void registerImageAdapter(ImageAdapter imageAdapter) { 49 FeatureAdapter.imageAdapter = Objects.requireNonNull(imageAdapter); 36 50 } 37 51 38 52 public static void registerTranslationAdapter(TranslationAdapter translationAdapter) { 39 FeatureAdapter.translationAdapter = translationAdapter;53 FeatureAdapter.translationAdapter = Objects.requireNonNull(translationAdapter); 40 54 } 41 55 42 56 public static void registerLoggingAdapter(LoggingAdapter loggingAdapter) { 43 FeatureAdapter.loggingAdapter = loggingAdapter;57 FeatureAdapter.loggingAdapter = Objects.requireNonNull(loggingAdapter); 44 58 } 45 59 46 60 public static void openLink(String url) { 47 61 browserAdapter.openLink(url); 62 } 63 64 public static BufferedImage readImage(URL url) throws IOException { 65 return imageAdapter.read(url, false, false); 48 66 } 49 67 … … 73 91 } 74 92 93 public static class DefaultImageAdapter implements ImageAdapter { 94 @Override 95 public BufferedImage read(URL input, boolean readMetadata, boolean enforceTransparency) throws IOException { 96 return ImageIO.read(input); 97 } 98 } 99 75 100 public static class DefaultTranslationAdapter implements TranslationAdapter { 76 101 @Override -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r34759 r34760 8 8 import java.awt.Point; 9 9 import java.awt.event.MouseEvent; 10 import java.io.IOException; 10 11 import java.net.URL; 11 12 import java.util.ArrayList; … … 164 165 add(zoomSlider); 165 166 int size = 18; 166 URL url = JMapViewer.class.getResource("images/plus.png"); 167 if (url != null) { 168 ImageIcon icon = new ImageIcon(url); 167 ImageIcon icon = getImageIcon("images/plus.png"); 168 if (icon != null) { 169 169 zoomInButton = new JButton(icon); 170 170 } else { … … 177 177 zoomInButton.setFocusable(false); 178 178 add(zoomInButton); 179 url = JMapViewer.class.getResource("images/minus.png"); 180 if (url != null) { 181 ImageIcon icon = new ImageIcon(url); 179 icon = getImageIcon("images/minus.png"); 180 if (icon != null) { 182 181 zoomOutButton = new JButton(icon); 183 182 } else { … … 190 189 zoomOutButton.setFocusable(false); 191 190 add(zoomOutButton); 191 } 192 193 private static ImageIcon getImageIcon(String name) { 194 URL url = JMapViewer.class.getResource(name); 195 if (url != null) { 196 try { 197 return new ImageIcon(FeatureAdapter.readImage(url)); 198 } catch (IOException e) { 199 e.printStackTrace(); 200 } 201 } 202 return null; 192 203 } 193 204 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java
r34616 r34760 82 82 private static BufferedImage loadImage(String path) { 83 83 try { 84 return ImageIO.read(JMapViewer.class.getResourceAsStream(path));84 return FeatureAdapter.readImage(JMapViewer.class.getResource(path)); 85 85 } catch (IOException | IllegalArgumentException ex) { 86 86 ex.printStackTrace(); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
r34094 r34760 4 4 import java.awt.Image; 5 5 import java.io.IOException; 6 import java.io.InputStream;7 6 import java.net.MalformedURLException; 8 7 import java.net.URL; … … 18 17 import java.util.regex.Pattern; 19 18 20 import javax.imageio.ImageIO;21 19 import javax.xml.parsers.DocumentBuilder; 22 20 import javax.xml.parsers.DocumentBuilderFactory; … … 29 27 30 28 import org.openstreetmap.gui.jmapviewer.Coordinate; 29 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 31 30 import org.openstreetmap.gui.jmapviewer.JMapViewer; 32 31 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; … … 191 190 public Image getAttributionImage() { 192 191 try { 193 final InputStream imageResource = JMapViewer.class.getResourceAsStream("images/bing_maps.png");192 final URL imageResource = JMapViewer.class.getResource("images/bing_maps.png"); 194 193 if (imageResource != null) { 195 return ImageIO.read(imageResource);194 return FeatureAdapter.readImage(imageResource); 196 195 } else { 197 196 // Some Linux distributions (like Debian) will remove Bing logo from sources, so get it at runtime … … 204 203 if (brandLogoUri != null && !brandLogoUri.isEmpty()) { 205 204 System.out.println("Reading Bing logo from "+brandLogoUri); 206 return ImageIO.read(new URL(brandLogoUri));205 return FeatureAdapter.readImage(new URL(brandLogoUri)); 207 206 } 208 207 }
Note:
See TracChangeset
for help on using the changeset viewer.