Ticket #23654: josm_23654_2.patch
| File josm_23654_2.patch, 6.8 KB (added by , 15 months ago) |
|---|
-
Readme.txt
35 35 36 36 2. How does JMapViewer work? 37 37 38 JMapViewer loads bitmap tiles from the OpenStreet map tile server (Mapnik renderer).39 Therefore any application using JMapViewer requires a working Internet connection.38 JMapViewer loads bitmap tiles from the OpenStreetMap tile server (Mapnik renderer). 39 Therefore, any application using JMapViewer requires a working Internet connection. 40 40 41 41 3. How do I use JMapViewer in my application? 42 42 43 You can justcreate an instance of the class org.openstreetmap.gui.jmapviewer.JMapViewer43 You can create an instance of the class org.openstreetmap.gui.jmapviewer.JMapViewer 44 44 using the default constructor and add it to your panel/frame/windows. 45 For more details please see the Demo class in the same package.45 For more details, please see the Demo class in the same package. -
src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java
62 62 return; 63 63 } 64 64 65 // Draw attribution66 65 Font font = g.getFont(); 67 66 g.setFont(ATTR_LINK_FONT); 68 67 69 // Draw terms of use text 68 // Draw terms of use text (bottom left corner) 69 final int padding = 4; // should be positive 70 final int fontDescent = g.getFontMetrics().getDescent(); 70 71 int termsTextHeight = 0; 71 int termsTextY = height ;72 int termsTextY = height - 1 - padding; // the 1 is to compensate the text shadow 72 73 73 74 if (attrTermsText != null) { 74 75 Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g); 75 76 int textRealHeight = (int) termsStringBounds.getHeight(); 76 termsTextHeight = textRealHeight - 5;77 77 int termsTextWidth = (int) termsStringBounds.getWidth(); 78 termsTextY = height - termsTextHeight; 79 int x = 2; 80 int y = height - termsTextHeight; 81 attrToUBounds = new Rectangle(x, y-termsTextHeight, termsTextWidth, textRealHeight); 82 g.setColor(Color.black); 83 g.drawString(attrTermsText, x + 1, y + 1); 84 g.setColor(Color.white); 85 g.drawString(attrTermsText, x, y); 78 termsTextHeight = textRealHeight; 79 attrToUBounds = new Rectangle(padding, termsTextY - termsTextHeight + fontDescent, termsTextWidth, textRealHeight); 80 drawShadedText(g, attrTermsText, padding, termsTextY); 81 drawRectangleWithBorder(g, attrToUBounds); 86 82 } else { 87 83 attrToUBounds = null; 88 84 } 89 85 90 // Draw attribution logo 86 // Draw attribution logo (on top the terms of use text) 91 87 if (attrImage != null) { 92 int x = 2;93 88 int imgWidth = attrImage.getWidth(observer); 94 89 int imgHeight = attrImage.getHeight(observer); 95 int y = termsTextY - imgHeight - termsTextHeight - 5;96 attrImageBounds = new Rectangle( x, y, imgWidth, imgHeight);97 g.drawImage(attrImage, x, y, null);90 int y = termsTextY - imgHeight - termsTextHeight; 91 attrImageBounds = new Rectangle(padding, y, imgWidth, imgHeight); 92 g.drawImage(attrImage, padding, y, null); 98 93 } else { 99 94 attrImageBounds = null; 100 95 } 101 96 97 // Draw attribution (bottom right corner) 102 98 g.setFont(ATTR_FONT); 103 99 String attributionText = source.getAttributionText(zoom, topLeft, bottomRight); 104 100 if (attributionText == null) { 105 // In case attribution text has been forgotte, display URL101 // In case the attribution text has been forgotten, display URL 106 102 attributionText = source.getAttributionLinkURL(); 107 103 } 108 104 if (attributionText != null) { 109 105 Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g); 110 int textHeight = (int) stringBounds.getHeight() - 5; 111 int x = width - (int) stringBounds.getWidth(); 112 int y = height - textHeight; 113 g.setColor(Color.black); 114 g.drawString(attributionText, x + 1, y + 1); 115 g.setColor(Color.white); 116 g.drawString(attributionText, x, y); 117 attrTextBounds = new Rectangle(x, y-textHeight, (int) stringBounds.getWidth(), (int) stringBounds.getHeight()); 106 int textWidth = (int) stringBounds.getWidth(); 107 int textHeight = (int) stringBounds.getHeight(); 108 int x = width - textWidth - padding; 109 drawShadedText(g, attributionText, x, termsTextY); 110 attrTextBounds = new Rectangle(x, termsTextY - textHeight + fontDescent, textWidth, textHeight); 111 drawRectangleWithBorder(g, attrTextBounds); 118 112 } else { 119 113 attrTextBounds = null; 120 114 } … … 122 116 g.setFont(font); 123 117 } 124 118 119 /** 120 * Used for debugging. Draws a red outline of the given rectangle. 121 */ 122 private void drawRectangleWithBorder(Graphics g, Rectangle rect) { 123 g.setColor(Color.RED); 124 g.drawRect(rect.x, rect.y, rect.width, rect.height); 125 } 126 127 /** 128 * Draws a string with 1px shadow. 129 * @param g the graphics 130 * @param text the string to be drawn 131 * @param x the x coordinate 132 * @param y the y coordinate 133 */ 134 private static void drawShadedText(Graphics g, String text, int x, int y) { 135 g.setColor(Color.black); 136 g.drawString(text, x + 1, y + 1); 137 g.setColor(Color.white); 138 g.drawString(text, x, y); 139 } 140 125 141 public boolean handleAttributionCursor(Point p) { 126 142 if (attrTextBounds != null && attrTextBounds.contains(p)) { 127 143 return true; … … 166 182 } 167 183 168 184 } 169 -
src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
180 180 * @param url URL to check 181 181 */ 182 182 public static void checkUrl(String url) { 183 assert url != null && ! "".equals(url) : "URL cannot be null or empty";183 assert url != null && !url.isEmpty() : "URL cannot be null or empty"; 184 184 Matcher m = Pattern.compile("\\{[^}]*}").matcher(url); 185 185 while (m.find()) { 186 186 boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> pattern.matcher(m.group()).matches());
