Changeset 26806 in osm for applications/viewer/jmapviewer
- Timestamp:
- 2011-10-08T13:01:32+02:00 (13 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java
r26794 r26806 16 16 import java.util.HashMap; 17 17 18 import org.openstreetmap.gui.jmapviewer.interfaces. TileSource;18 import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; 19 19 20 20 public class AttributionSupport { 21 21 22 private TileSource tileSource;22 private Attributed source; 23 23 24 24 private Image attrImage; … … 38 38 } 39 39 40 public void initialize( TileSource tileSource) {41 this. tileSource = tileSource;42 boolean requireAttr = tileSource.requiresAttribution();40 public void initialize(Attributed source) { 41 this.source = source; 42 boolean requireAttr = source.requiresAttribution(); 43 43 if (requireAttr) { 44 attrImage = tileSource.getAttributionImage();45 attrTermsText = tileSource.getTermsOfUseText();46 attrTermsUrl = tileSource.getTermsOfUseURL();44 attrImage = source.getAttributionImage(); 45 attrTermsText = source.getTermsOfUseText(); 46 attrTermsUrl = source.getTermsOfUseURL(); 47 47 if (attrTermsUrl != null && attrTermsText == null) { 48 48 attrTermsText = tr("Background Terms of Use"); … … 55 55 56 56 public void paintAttribution(Graphics g, int width, int height, Coordinate topLeft, Coordinate bottomRight, int zoom, ImageObserver observer) { 57 if ( tileSource == null || !tileSource.requiresAttribution())57 if (source == null || !source.requiresAttribution()) 58 58 return; 59 59 // Draw attribution … … 91 91 92 92 g.setFont(ATTR_FONT); 93 String attributionText = tileSource.getAttributionText(zoom, topLeft, bottomRight);93 String attributionText = source.getAttributionText(zoom, topLeft, bottomRight); 94 94 if (attributionText != null) { 95 95 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); … … 108 108 109 109 public boolean handleAttribution(Point p, boolean click) { 110 if ( tileSource == null || !tileSource.requiresAttribution())110 if (source == null || !source.requiresAttribution()) 111 111 return false; 112 112 … … 114 114 115 115 if (attrTextBounds != null && attrTextBounds.contains(p)) { 116 String attributionURL = tileSource.getAttributionLinkURL();116 String attributionURL = source.getAttributionLinkURL(); 117 117 if (attributionURL != null) { 118 118 if (click) { … … 122 122 } 123 123 } else if (attrImageBounds != null && attrImageBounds.contains(p)) { 124 String attributionImageURL = tileSource.getAttributionImageURL();124 String attributionImageURL = source.getAttributionImageURL(); 125 125 if (attributionImageURL != null) { 126 126 if (click) { 127 FeatureAdapter.openLink( tileSource.getAttributionImageURL());127 FeatureAdapter.openLink(source.getAttributionImageURL()); 128 128 } 129 129 return true; 130 130 } 131 131 } else if (attrToUBounds != null && attrToUBounds.contains(p)) { 132 String termsOfUseURL = tileSource.getTermsOfUseURL();132 String termsOfUseURL = source.getTermsOfUseURL(); 133 133 if (termsOfUseURL != null) { 134 134 if (click) { -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r26793 r26806 13 13 * @author Jan Peter Stotz 14 14 */ 15 public interface TileSource {15 public interface TileSource extends Attributed { 16 16 17 17 /** … … 97 97 int getTileSize(); 98 98 99 /**100 * @return True if the tile source requires attribution in text or image form.101 */102 boolean requiresAttribution();103 104 /**105 * @param zoom The optional zoom level for the view.106 * @param botRight The bottom right of the bounding box for attribution.107 * @param topLeft The top left of the bounding box for attribution.108 * @return Attribution text for the image source.109 */110 String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight);111 112 /**113 * @return The URL to open when the user clicks the attribution text.114 */115 String getAttributionLinkURL();116 117 /**118 * @return The URL for the attribution image. Null if no image should be displayed.119 */120 Image getAttributionImage();121 122 /**123 * @return The URL to open when the user clicks the attribution image.124 * When return value is null, the image is still displayed (provided getAttributionImage()125 * returns a value other than null), but the image does not link to a website.126 */127 String getAttributionImageURL();128 129 /**130 * @return The attribution "Terms of Use" text.131 * In case it returns null, but getTermsOfUseURL() is not null, a default132 * terms of use text is used.133 */134 String getTermsOfUseText();135 136 /**137 * @return The URL to open when the user clicks the attribution "Terms of Use" text.138 */139 String getTermsOfUseURL();140 141 99 double latToTileY(double lat, int zoom); 142 100 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractOsmTileSource.java
r26793 r26806 17 17 } 18 18 19 public AbstractOsmTileSource(String name, String base_url, String attr_img_url) {20 super(name, base_url, attr_img_url);21 }22 19 public int getMaxZoom() { 23 20 return 18; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/AbstractTSMTileSource.java
r26793 r26806 1 /**2 *3 */4 1 package org.openstreetmap.gui.jmapviewer.tilesources; 2 3 //License: GPL. 5 4 6 5 import java.awt.Image; … … 12 11 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 13 12 14 public abstract class AbstractTSMTileSource implementsTileSource {13 public abstract class AbstractTSMTileSource extends AbstractTileSource { 15 14 16 15 protected String name; 17 16 protected String baseUrl; 18 protected String attrImgUrl;19 17 20 18 public AbstractTSMTileSource(String name, String base_url) { 21 this(name, base_url, null);22 }23 24 public AbstractTSMTileSource(String name, String base_url, String attr_img_url) {25 19 this.name = name; 26 20 this.baseUrl = base_url; … … 28 22 baseUrl = baseUrl.substring(0,baseUrl.length()-1); 29 23 } 30 attrImgUrl = attr_img_url;31 24 } 32 25 … … 82 75 83 76 @Override 84 public boolean requiresAttribution() {85 return false;86 }87 88 @Override89 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {90 throw new UnsupportedOperationException("no attribution");91 }92 93 @Override94 public String getAttributionLinkURL() {95 throw new UnsupportedOperationException("no attribution");96 }97 98 @Override99 public Image getAttributionImage() {100 if (attrImgUrl != null)101 return new ImageIcon(attrImgUrl).getImage();102 103 else104 return null;105 }106 107 @Override108 public String getAttributionImageURL() {109 throw new UnsupportedOperationException("no attribution");110 }111 112 @Override113 public String getTermsOfUseText() {114 throw new UnsupportedOperationException("no attribution");115 }116 117 @Override118 public String getTermsOfUseURL() {119 throw new UnsupportedOperationException("no attribution");120 }121 122 @Override123 77 public double latToTileY(double lat, int zoom) { 124 78 double l = lat / 180 * Math.PI; -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TMSTileSource.java
r26793 r26806 8 8 9 9 public class TMSTileSource extends AbstractTSMTileSource { 10 10 11 protected int maxZoom; 11 12 protected int minZoom = 0; 12 protected String attributionText;13 protected String attributionLinkURL;14 protected Image attributionImage;15 protected String attributionImageURL;16 protected String termsOfUseText;17 protected String termsOfUseURL;18 13 19 14 public TMSTileSource(String name, String url, int maxZoom) { … … 42 37 } 43 38 44 @Override45 public boolean requiresAttribution() {46 return attributionText != null;47 }48 49 @Override50 public String getAttributionText(int zoom, Coordinate topLeft, Coordinate botRight) {51 return attributionText;52 }53 54 @Override55 public String getAttributionLinkURL() {56 return attributionLinkURL;57 }58 59 @Override60 public Image getAttributionImage() {61 return attributionImage;62 }63 64 @Override65 public String getAttributionImageURL() {66 return attributionImageURL;67 }68 69 @Override70 public String getTermsOfUseText() {71 return termsOfUseText;72 }73 74 @Override75 public String getTermsOfUseURL() {76 return termsOfUseURL;77 }78 79 public void setAttributionText(String text) {80 attributionText = text;81 }82 83 public void setAttributionLinkURL(String text) {84 attributionLinkURL = text;85 }86 87 public void setAttributionImage(Image img) {88 attributionImage = img;89 }90 91 public void setAttributionImageURL(String text) {92 attributionImageURL = text;93 }94 95 public void setTermsOfUseText(String text) {96 termsOfUseText = text;97 }98 99 public void setTermsOfUseURL(String text) {100 termsOfUseURL = text;101 }102 39 }
Note:
See TracChangeset
for help on using the changeset viewer.