Changeset 4489 in josm for trunk/src/org
- Timestamp:
- 2011-10-06T10:14:16+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r4288 r4489 42 42 import javax.swing.UIManager; 43 43 44 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 44 45 import org.openstreetmap.josm.actions.JosmAction; 45 46 import org.openstreetmap.josm.actions.OpenFileAction; … … 79 80 import org.openstreetmap.josm.tools.I18n; 80 81 import org.openstreetmap.josm.tools.ImageProvider; 82 import org.openstreetmap.josm.tools.OpenBrowser; 81 83 import org.openstreetmap.josm.tools.OsmUrlToBounds; 82 84 import org.openstreetmap.josm.tools.PlatformHook; … … 252 254 validator = new OsmValidator(); 253 255 MapView.addLayerChangeListener(validator); 256 257 // hooks for the jmapviewer component 258 FeatureAdapter.registerBrowserAdapter(new FeatureAdapter.BrowserAdapter() { 259 @Override 260 public void openLink(String url) { 261 OpenBrowser.displayUrl(url); 262 } 263 }); 264 FeatureAdapter.registerTranslationAdapter(I18n.getTranslationAdapter()); 254 265 255 266 toolbar.refreshToolbarControl(); … … 796 807 /** 797 808 * Replies the current projection. 798 * 809 * 799 810 * @return 800 811 */ … … 805 816 /** 806 817 * Sets the current projection 807 * 818 * 808 819 * @param p the projection 809 820 */ … … 849 860 /** 850 861 * Register a projection change listener 851 * 862 * 852 863 * @param listener the listener. Ignored if null. 853 864 */ … … 865 876 /** 866 877 * Removes a projection change listener 867 * 878 * 868 879 * @param listener the listener. Ignored if null. 869 880 */ -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r4465 r4489 215 215 216 216 public boolean handleAttribution(Point p, boolean click) { 217 TileSource ts = tileController.getTileSource(); 218 if(!ts.requiresAttribution()) 219 return false; 220 221 /* TODO: Somehow indicate the link is clickable state to user */ 222 223 if ((attrImageBounds != null && attrImageBounds.contains(p)) 224 || (attrTextBounds != null && attrTextBounds.contains(p))) { 225 if (click) 226 OpenBrowser.displayUrl(ts.getAttributionLinkURL()); 227 /*else 228 Main.warn(ts.getAttributionLinkURL());*/ 229 return true; 230 } else if (attrToUBounds != null && attrToUBounds.contains(p)) { 231 if (click) 232 OpenBrowser.displayUrl(ts.getTermsOfUseURL()); 233 /*else 234 Main.warn(ts.getTermsOfUseURL());*/ 235 return true; 236 } 237 return false; 217 return attribution.handleAttribution(p, click); 238 218 } 239 219 -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4465 r4489 36 36 import javax.swing.SwingUtilities; 37 37 38 import org.openstreetmap.gui.jmapviewer.AttributionSupport; 38 39 import org.openstreetmap.gui.jmapviewer.Coordinate; 39 40 import org.openstreetmap.gui.jmapviewer.JobDispatcher; … … 158 159 JCheckBoxMenuItem showErrorsPopup; 159 160 Tile showMetadataTile; 160 private Image attrImage; 161 private String attrTermsUrl; 162 private Rectangle attrImageBounds, attrToUBounds, attrTextBounds; 161 private AttributionSupport attribution = new AttributionSupport(); 163 162 private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13); 164 private static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);165 private static final Font ATTR_LINK_FONT;166 static {167 HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>();168 aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);169 ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline);170 }171 163 172 164 protected boolean autoZoom; … … 248 240 { 249 241 this.tileSource = tileSource; 250 boolean requireAttr = tileSource.requiresAttribution(); 251 if(requireAttr) { 252 attrImage = tileSource.getAttributionImage(); 253 /*if(attrImage == null) { 254 Main.debug("Attribution image was null."); 255 } else { 256 Main.debug("Got an attribution image " + attrImage.getHeight(this) + "x" + attrImage.getWidth(this)); 257 }*/ 258 259 attrTermsUrl = tileSource.getTermsOfUseURL(); 260 } 242 attribution.initialize(tileSource); 261 243 262 244 currentZoomLevel = getBestZoom(); … … 477 459 tileOptionMenu.show(e.getComponent(), e.getX(), e.getY()); 478 460 } else if (e.getButton() == MouseEvent.BUTTON1) { 479 if (!tileSource.requiresAttribution()) 480 return; 481 482 if ((attrImageBounds != null && attrImageBounds.contains(e.getPoint())) 483 || (attrTextBounds != null && attrTextBounds.contains(e.getPoint()))) { 484 OpenBrowser.displayUrl(tileSource.getAttributionLinkURL()); 485 } else if (attrToUBounds != null && attrToUBounds.contains(e.getPoint())) { 486 OpenBrowser.displayUrl(tileSource.getTermsOfUseURL()); 487 } 461 attribution.handleAttribution(e.getPoint(), true); 488 462 } 489 463 } … … 920 894 return new Coordinate(ll.lat(),ll.lon()); 921 895 } 896 922 897 private final TileSet nullTileSet = new TileSet((LatLon)null, (LatLon)null, 0); 923 898 private class TileSet { … … 1239 1214 this.paintTileText(ts, t, g, mv, displayZoomLevel, t); 1240 1215 } 1241 1242 if (tileSource.requiresAttribution()) { 1243 // Draw attribution 1244 Font font = g.getFont(); 1245 g.setFont(ATTR_LINK_FONT); 1246 g.setColor(Color.white); 1247 1248 // Draw terms of use text 1249 Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g); 1250 int textRealHeight = (int) termsStringBounds.getHeight(); 1251 int textHeight = textRealHeight - 5; 1252 int textWidth = (int) termsStringBounds.getWidth(); 1253 int termsTextY = mv.getHeight() - textHeight; 1254 if(attrTermsUrl != null) { 1255 int x = 2; 1256 int y = mv.getHeight() - textHeight; 1257 attrToUBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 1258 myDrawString(g, "Background Terms of Use", x, y); 1259 } 1260 1261 // Draw attribution logo 1262 if(attrImage != null) { 1263 int x = 2; 1264 int imgWidth = attrImage.getWidth(this); 1265 int height = attrImage.getHeight(this); 1266 int y = termsTextY - height - textHeight - 5; 1267 attrImageBounds = new Rectangle(x, y, imgWidth, height); 1268 g.drawImage(attrImage, x, y, this); 1269 } 1270 1271 g.setFont(ATTR_FONT); 1272 String attributionText = tileSource.getAttributionText(displayZoomLevel, 1273 getShiftedCoord(topLeft), getShiftedCoord(botRight)); 1274 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); 1275 { 1276 int x = mv.getWidth() - (int) stringBounds.getWidth(); 1277 int y = mv.getHeight() - textHeight; 1278 myDrawString(g, attributionText, x, y); 1279 attrTextBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight); 1280 } 1281 1282 g.setFont(font); 1283 } 1216 1217 attribution.paintAttribution(g, mv.getWidth(), mv.getHeight(), getShiftedCoord(topLeft), getShiftedCoord(botRight), displayZoomLevel, this); 1284 1218 1285 1219 //g.drawString("currentZoomLevel=" + currentZoomLevel, 120, 120); -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r4477 r4489 22 22 import javax.swing.UIManager; 23 23 24 import org.openstreetmap.gui.jmapviewer.FeatureAdapter.TranslationAdapter; 24 25 import org.openstreetmap.josm.Main; 25 26 … … 203 204 * For instance, {@code trn("There was an error!", "There were errors!", i)} or 204 205 * {@code trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)}. 205 * 206 * 206 207 * @param singularText the singular text to translate. 207 208 * Must be a string literal. (No constants or local vars.) … … 694 695 return 0; 695 696 } 697 698 public static TranslationAdapter getTranslationAdapter() { 699 return new TranslationAdapter() { 700 @Override 701 public String tr(String text, Object... objects) { 702 return I18n.tr(text, objects); 703 } 704 }; 705 } 696 706 }
Note:
See TracChangeset
for help on using the changeset viewer.