- Timestamp:
- 2011-07-03T01:02:51+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4194 r4195 7 7 import java.util.regex.Pattern; 8 8 9 import javax.swing.ImageIcon; 10 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.Bounds; 9 13 import org.openstreetmap.josm.io.OsmApi; 10 14 import org.openstreetmap.josm.tools.CheckParameterUtil; 15 import org.openstreetmap.josm.tools.ImageProvider; 16 import org.openstreetmap.gui.jmapviewer.tilesources.OsmTileSource.Mapnik; 17 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource; 11 18 12 19 /** … … 33 40 } 34 41 35 String name;42 private String name; 36 43 private String url = null; 37 String cookies = null; 38 public final String eulaAcceptanceRequired; 39 ImageryType imageryType = ImageryType.WMS; 40 double pixelPerDegree = 0.0; 41 int maxZoom = 0; 42 int defaultMaxZoom = 0; 43 int defaultMinZoom = 0; 44 private String cookies = null; 45 private String eulaAcceptanceRequired= null; 46 private ImageryType imageryType = ImageryType.WMS; 47 private double pixelPerDegree = 0.0; 48 private int maxZoom = 0; 49 private int defaultMaxZoom = 0; 50 private int defaultMinZoom = 0; 51 private Bounds bounds = null; 52 private String attributionText; 53 private String attributionImage; 54 private String attributionLinkURL; 55 private String termsOfUseURL; 44 56 45 57 public ImageryInfo(String name) { 46 58 this.name=name; 47 this.eulaAcceptanceRequired = null;48 59 } 49 60 … … 51 62 this.name=name; 52 63 setUrl(url); 53 this.eulaAcceptanceRequired = null;54 64 } 55 65 … … 72 82 this.cookies=cookies; 73 83 this.pixelPerDegree=pixelPerDegree; 74 this.eulaAcceptanceRequired = null;75 84 } 76 85 77 86 public ArrayList<String> getInfoArray() { 78 String e2 = null;79 String e3 = null;80 String e4 = null;81 if(url != null && !url.isEmpty()) {82 e2 = getFullUrl();83 }84 if(cookies != null && !cookies.isEmpty()) {85 e3 = cookies;86 }87 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {88 if(pixelPerDegree != 0.0) {89 e4 = String.valueOf(pixelPerDegree);90 }91 } else {92 if(maxZoom != 0) {93 e4 = String.valueOf(maxZoom);94 }95 }96 if(e4 != null && e3 == null) {97 e3 = "";98 }99 if(e3 != null && e2 == null) {100 e2 = "";101 }102 103 87 ArrayList<String> res = new ArrayList<String>(); 104 88 res.add(name); 105 if(e2 != null) { 106 res.add(e2); 107 } 108 if(e3 != null) { 109 res.add(e3); 110 } 111 if(e4 != null) { 112 res.add(e4); 113 } 89 res.add((url != null && !url.isEmpty()) ? getFullUrl() : null); 90 res.add(cookies); 91 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 92 res.add(pixelPerDegree != 0.0 ? String.valueOf(pixelPerDegree) : null); 93 } else { 94 res.add(maxZoom != 0 ? String.valueOf(maxZoom) : null); 95 } 96 res.add(bounds != null ? bounds.encodeAsString(",") : null); 97 res.add(attributionText); 98 res.add(attributionLinkURL); 99 res.add(attributionImage); 100 res.add(termsOfUseURL); 114 101 return res; 115 102 } … … 118 105 ArrayList<String> array = new ArrayList<String>(list); 119 106 this.name=array.get(0); 120 if(array.size() >= 2 ) {107 if(array.size() >= 2 && !array.get(1).isEmpty()) { 121 108 setUrl(array.get(1)); 122 109 } 123 if(array.size() >= 3 ) {110 if(array.size() >= 3 && !array.get(2).isEmpty()) { 124 111 this.cookies=array.get(2); 125 112 } 126 if(array.size() >= 4 ) {113 if(array.size() >= 4 && !array.get(3).isEmpty()) { 127 114 if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 128 115 this.pixelPerDegree=Double.valueOf(array.get(3)); … … 131 118 } 132 119 } 133 this.eulaAcceptanceRequired = null; 120 if(array.size() >= 5 && !array.get(4).isEmpty()) { 121 try { 122 bounds = new Bounds(array.get(4), ","); 123 } catch (IllegalArgumentException e) { 124 Main.warn(e.toString()); 125 } 126 } 127 if(array.size() >= 6 && !array.get(5).isEmpty()) { 128 setAttributionText(array.get(5)); 129 } 130 if(array.size() >= 7 && !array.get(6).isEmpty()) { 131 setAttributionLinkURL(array.get(6)); 132 } 133 if(array.size() >= 8 && !array.get(7).isEmpty()) { 134 setAttributionImage(array.get(7)); 135 } 136 if(array.size() >= 9 && !array.get(8).isEmpty()) { 137 setTermsOfUseURL(array.get(8)); 138 } 134 139 } 135 140 … … 139 144 this.cookies=i.cookies; 140 145 this.imageryType=i.imageryType; 146 this.defaultMinZoom=i.defaultMinZoom; 147 this.maxZoom=i.maxZoom; 141 148 this.defaultMaxZoom=i.defaultMaxZoom; 142 149 this.pixelPerDegree=i.pixelPerDegree; 143 150 this.eulaAcceptanceRequired = null; 151 this.bounds = i.bounds; 152 this.attributionImage = i.attributionImage; 153 this.attributionLinkURL = i.attributionLinkURL; 154 this.attributionText = i.attributionText; 155 this.termsOfUseURL = i.termsOfUseURL; 144 156 } 145 157 … … 168 180 public void setMaxZoom(int maxZoom) { 169 181 this.maxZoom = maxZoom; 182 } 183 184 public void setBounds(Bounds b) { 185 this.bounds = b; 186 } 187 188 public void setAttributionText(String text) { 189 attributionText = text; 190 } 191 192 public void setAttributionImage(String text) { 193 attributionImage = text; 194 } 195 196 public void setAttributionLinkURL(String text) { 197 attributionLinkURL = text; 198 } 199 200 public void setTermsOfUseURL(String text) { 201 termsOfUseURL = text; 170 202 } 171 203 … … 224 256 } 225 257 258 public String getEulaAcceptanceRequired() { 259 return eulaAcceptanceRequired; 260 } 261 226 262 public String getFullUrl() { 227 263 return imageryType.getUrlString() + (defaultMaxZoom != 0 … … 247 283 } 248 284 return res; 285 } 286 287 public void setAttribution(TMSTileSource s) 288 { 289 if(attributionLinkURL != null) { 290 if(attributionLinkURL.equals("osm")) 291 s.setAttributionLinkURL(new Mapnik().getAttributionLinkURL()); 292 else 293 s.setAttributionLinkURL(attributionLinkURL); 294 } 295 if(attributionText != null) { 296 if(attributionText.equals("osm")) 297 s.setAttributionText(new Mapnik().getAttributionText(0, null, null)); 298 else 299 s.setAttributionText(attributionText); 300 } 301 if(attributionImage != null) { 302 ImageIcon i = ImageProvider.getIfAvailable(null, attributionImage); 303 if(i != null) 304 s.setAttributionImage(i.getImage()); 305 } 306 if(termsOfUseURL != null) { 307 if(termsOfUseURL.equals("osm")) 308 s.setTermsOfUseURL(new Mapnik().getTermsOfUseURL()); 309 else 310 s.setTermsOfUseURL(termsOfUseURL); 311 } 249 312 } 250 313 -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r4145 r4195 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 19 import org.openstreetmap.josm.data.Bounds; 19 20 import org.openstreetmap.josm.io.MirroredInputStream; 20 21 … … 73 74 { 74 75 String val[] = line.split(";"); 75 if(!line.startsWith("#") && (val.length == 3 || val.length == 4)) {76 if(!line.startsWith("#") && val.length >= 3) { 76 77 boolean force = "true".equals(val[0]); 77 78 String name = tr(val[1]); … … 79 80 String eulaAcceptanceRequired = null; 80 81 81 if (val.length == 4) {82 if (val.length >= 4 && !val[3].isEmpty()) { 82 83 // 4th parameter optional for license agreement (EULA) 83 84 eulaAcceptanceRequired = val[3]; 84 85 } 85 86 86 defaultLayers.add(new ImageryInfo(name, url, eulaAcceptanceRequired)); 87 ImageryInfo info = new ImageryInfo(name, url, eulaAcceptanceRequired); 88 89 if (val.length >= 5 && !val[4].isEmpty()) { 90 // 5th parameter optional for bounds 91 try { 92 info.setBounds(new Bounds(val[4], ",")); 93 } catch (IllegalArgumentException e) { 94 Main.warn(e.toString()); 95 } 96 } 97 if (val.length >= 6 && !val[5].isEmpty()) { 98 info.setAttributionText(val[5]); 99 } 100 if (val.length >= 7 && !val[6].isEmpty()) { 101 info.setAttributionLinkURL(val[6]); 102 } 103 if (val.length >= 8 && !val[7].isEmpty()) { 104 info.setTermsOfUseURL(val[7]); 105 } 106 if (val.length >= 9 && !val[8].isEmpty()) { 107 info.setAttributionImage(val[8]); 108 } 109 110 defaultLayers.add(info); 87 111 88 112 if (force) { -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r4168 r4195 3 3 4 4 import java.awt.Color; 5 import java.awt.Desktop; 5 6 import java.awt.Dimension; 6 7 import java.awt.Graphics; … … 12 13 import java.io.File; 13 14 import java.io.IOException; 15 import java.net.URI; 16 import java.net.URISyntaxException; 14 17 import java.util.ArrayList; 15 18 import java.util.Arrays; … … 217 220 } 218 221 222 public boolean handleAttribution(Point p, boolean click) { 223 TileSource ts = tileController.getTileSource(); 224 if(!ts.requiresAttribution()) 225 return false; 226 227 /* TODO: Somehow indicate the link is clickable state to user */ 228 229 try { 230 if((attrImageBounds != null && attrImageBounds.contains(p)) 231 || (attrTextBounds != null && attrTextBounds.contains(p))) { 232 if(click) 233 Desktop.getDesktop().browse(new URI(ts.getAttributionLinkURL())); 234 /*else 235 Main.warn(ts.getAttributionLinkURL());*/ 236 return true; 237 } else if(attrToUBounds.contains(p)) { 238 if(click) 239 Desktop.getDesktop().browse(new URI(ts.getTermsOfUseURL())); 240 /*else 241 Main.warn(ts.getTermsOfUseURL());*/ 242 return true; 243 } 244 } catch (IOException e1) { 245 e1.printStackTrace(); 246 } catch (URISyntaxException e1) { 247 e1.printStackTrace(); 248 } 249 return false; 250 } 251 219 252 protected Point getTopLeftCoordinates() { 220 253 return new Point(center.x - (getWidth() / 2), center.y - (getHeight() / 2)); -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapControler.java
r3720 r4195 149 149 iSizeButton.toggle(); 150 150 iSlippyMapChooser.resizeSlippyMap(); 151 } else if (iSlippyMapChooser.handleAttribution(e.getPoint(), true)) { 152 /* do nothing, handleAttribution() already did the work */ 151 153 } else if (sourceButton == SourceButton.HIDE_OR_SHOW) { 152 154 iSourceButton.toggle(); 153 155 iSlippyMapChooser.repaint(); 154 155 156 } else if (sourceButton != 0) { 156 157 iSlippyMapChooser.toggleMapSource(iSourceButton.hitToTileSource(sourceButton)); … … 170 171 @Override 171 172 public void mouseMoved(MouseEvent e) { 173 iSlippyMapChooser.handleAttribution(e.getPoint(), false); 172 174 } 173 175 -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4188 r4195 159 159 private Image attrImage; 160 160 private String attrTermsUrl; 161 private Rectangle attrImageBounds, attrToUBounds ;161 private Rectangle attrImageBounds, attrToUBounds, attrTextBounds; 162 162 private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13); 163 163 private static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); … … 233 233 public static TileSource getTileSource(ImageryInfo info) { 234 234 if (info.getImageryType() == ImageryType.TMS) { 235 if(ImageryInfo.isUrlWithPatterns(info.getUrl())) 236 return new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 237 else 238 return new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 235 if(ImageryInfo.isUrlWithPatterns(info.getUrl())) { 236 TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 237 info.setAttribution(t); 238 return t; 239 } else { 240 TMSTileSource t = new TMSTileSource(info.getName(),info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 241 info.setAttribution(t); 242 return t; 243 } 239 244 } else if (info.getImageryType() == ImageryType.BING) 240 245 return new BingAerialTileSource(); … … 317 322 if(!isProjectionSupported(Main.getProjection())) { 318 323 JOptionPane.showMessageDialog(Main.parent, 319 tr("TMS layers do not support the projection { 1}.\n{2}\n"324 tr("TMS layers do not support the projection {0}.\n{1}\n" 320 325 + "Change the projection or remove the layer.", 321 326 Main.getProjection().toCode(), nameSupportedProjections()), … … 455 460 return; 456 461 457 if(attrImageBounds != null && attrImageBounds.contains(e.getPoint())) { 462 if((attrImageBounds != null && attrImageBounds.contains(e.getPoint())) 463 || (attrTextBounds != null && attrTextBounds.contains(e.getPoint()))) { 458 464 try { 459 465 java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); … … 1200 1206 // Draw terms of use text 1201 1207 Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g); 1202 int textHeight = (int) termsStringBounds.getHeight() - 5; 1208 int textRealHeight = (int) termsStringBounds.getHeight(); 1209 int textHeight = textRealHeight - 5; 1203 1210 int textWidth = (int) termsStringBounds.getWidth(); 1204 1211 int termsTextY = mv.getHeight() - textHeight; … … 1206 1213 int x = 2; 1207 1214 int y = mv.getHeight() - textHeight; 1208 attrToUBounds = new Rectangle(x, y , textWidth, textHeight);1215 attrToUBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 1209 1216 myDrawString(g, "Background Terms of Use", x, y); 1210 1217 } … … 1228 1235 int y = mv.getHeight() - textHeight; 1229 1236 myDrawString(g, attributionText, x, y); 1237 attrTextBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 1230 1238 } 1231 1239 -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4193 r4195 530 530 } 531 531 532 if (info. eulaAcceptanceRequired!= null) {533 if (!confirmEulaAcceptance(gui, info. eulaAcceptanceRequired)) {532 if (info.getEulaAcceptanceRequired() != null) { 533 if (!confirmEulaAcceptance(gui, info.getEulaAcceptanceRequired())) { 534 534 continue outer; 535 535 }
Note:
See TracChangeset
for help on using the changeset viewer.