Changeset 24643 in osm for applications
- Timestamp:
- 2010-12-07T16:02:32+01:00 (14 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r22281 r24643 3 3 //License: GPL. Copyright 2008 by Jan Peter Stotz 4 4 5 import java.awt.Color; 5 6 import java.awt.Dimension; 6 7 import java.awt.Font; 7 8 import java.awt.Graphics; 9 import java.awt.Image; 8 10 import java.awt.Insets; 9 11 import java.awt.Point; … … 11 13 import java.awt.event.ActionListener; 12 14 import java.awt.event.MouseEvent; 15 import java.awt.font.TextAttribute; 16 import java.awt.geom.Rectangle2D; 17 import java.util.HashMap; 13 18 import java.util.LinkedList; 14 19 import java.util.List; … … 27 32 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; 28 33 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 34 import org.openstreetmap.josm.data.coor.LatLon; 29 35 30 36 /** … … 74 80 75 81 private TileSource tileSource; 82 83 // Attribution 84 private Image attrImage; 85 private String attrTermsUrl; 86 public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); 87 public static final Font ATTR_LINK_FONT; 88 89 static { 90 HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>(); 91 aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); 92 ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline); 93 } 76 94 77 95 /** … … 211 229 int oldZoom = this.zoom; 212 230 this.zoom = zoom; 213 if (oldZoom != zoom) 231 if (oldZoom != zoom) { 214 232 zoomChanged(oldZoom); 215 if (zoomSlider.getValue() != zoom) 233 } 234 if (zoomSlider.getValue() != zoom) { 216 235 zoomSlider.setValue(zoom); 236 } 217 237 } finally { 218 238 setIgnoreRepaint(false); … … 268 288 */ 269 289 public void setDisplayToFitMapRectangle() { 270 if (mapRectangleList == null || mapRectangleList.size() == 0) {290 if (mapRectangleList == null || mapRectangleList.size() == 0) 271 291 return; 272 }273 292 int x_min = Integer.MAX_VALUE; 274 293 int y_min = Integer.MAX_VALUE; … … 502 521 } 503 522 } 523 paintAttribution(g); 504 524 } 505 525 … … 513 533 } 514 534 } 515 535 516 536 /** 517 537 * Moves the visible map pane. … … 676 696 zoomSlider.setMaximum(tileSource.getMaxZoom()); 677 697 tileController.cancelOutstandingJobs(); 678 if (zoom > tileSource.getMaxZoom()) 698 if (zoom > tileSource.getMaxZoom()) { 679 699 setZoom(tileSource.getMaxZoom()); 700 } 701 boolean requireAttr = tileSource.requiresAttribution(); 702 if (requireAttr) { 703 attrImage = tileSource.getAttributionImage(); 704 attrTermsUrl = tileSource.getTermsOfUseURL(); 705 } else { 706 attrImage = null; 707 attrTermsUrl = null; 708 } 680 709 repaint(); 681 710 } … … 715 744 tileController.setTileLoader(loader); 716 745 } 746 747 private void paintAttribution(Graphics g) { 748 if (!tileSource.requiresAttribution()) return; 749 // Draw attribution 750 Font font = g.getFont(); 751 g.setFont(ATTR_LINK_FONT); 752 753 Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g); 754 int textHeight = (int) termsStringBounds.getHeight() - 5; 755 int termsTextY = getHeight() - textHeight; 756 if (attrTermsUrl != null) { 757 int x = 2; 758 int y = getHeight() - textHeight; 759 g.setColor(Color.black); 760 g.drawString("Background Terms of Use", x + 1, y + 1); 761 g.setColor(Color.white); 762 g.drawString("Background Terms of Use", x, y); 763 } 764 765 // Draw attribution logo 766 if (attrImage != null) { 767 int x = 2; 768 int height = attrImage.getHeight(null); 769 int y = termsTextY - height - textHeight - 5; 770 g.drawImage(attrImage, x, y, null); 771 } 772 773 g.setFont(ATTR_FONT); 774 Coordinate topLeft = getPosition(0,0); 775 Coordinate bottomRight = getPosition(getWidth(),getHeight()); 776 String attributionText = tileSource.getAttributionText(zoom, 777 new LatLon(topLeft.getLat(),topLeft.getLon()), 778 new LatLon(bottomRight.getLat(),bottomRight.getLon())); 779 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); 780 { 781 int x = getWidth() - (int) stringBounds.getWidth(); 782 int y = getHeight() - textHeight; 783 g.setColor(Color.black); 784 g.drawString(attributionText, x + 1, y + 1); 785 g.setColor(Color.white); 786 g.drawString(attributionText, x, y); 787 } 788 789 g.setFont(font); 790 } 717 791 } -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/interfaces/TileSource.java
r24489 r24643 101 101 public boolean requiresAttribution(); 102 102 103 // FIXME: JMapViewer shouldn't reference JOSM classes. 103 104 /** 104 105 * @param zoom The optional zoom level for the view.
Note:
See TracChangeset
for help on using the changeset viewer.