Subject: [PATCH] fix #23654 - improve map imagery attribute padding
---
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java b/src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java
|
a
|
b
|
|
| 13 | 13 | import java.awt.geom.Rectangle2D; |
| 14 | 14 | import java.awt.image.ImageObserver; |
| 15 | 15 | import java.util.HashMap; |
| | 16 | import java.util.Map; |
| 16 | 17 | |
| 17 | 18 | import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; |
| 18 | 19 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; |
| … |
… |
|
| 20 | 21 | public class AttributionSupport { |
| 21 | 22 | public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10); |
| 22 | 23 | public static final Font ATTR_LINK_FONT; |
| | 24 | private static final int PADDING = 5; |
| 23 | 25 | |
| 24 | 26 | private Attributed source; |
| 25 | 27 | |
| … |
… |
|
| 32 | 34 | protected Rectangle attrImageBounds; |
| 33 | 35 | |
| 34 | 36 | static { |
| 35 | | HashMap<TextAttribute, Integer> aUnderline = new HashMap<>(); |
| | 37 | Map<TextAttribute, Integer> aUnderline = new HashMap<>(); |
| 36 | 38 | aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); |
| 37 | 39 | ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline); |
| 38 | 40 | } |
| … |
… |
|
| 66 | 68 | Font font = g.getFont(); |
| 67 | 69 | g.setFont(ATTR_LINK_FONT); |
| 68 | 70 | |
| 69 | | // Draw terms of use text |
| | 71 | // Draw terms of use text (bottom left corner) |
| | 72 | final int fontDescent = g.getFontMetrics().getDescent(); |
| 70 | 73 | int termsTextHeight = 0; |
| 71 | | int termsTextY = height; |
| | 74 | int textY = height - 1 - PADDING; // 1px offset to compensate for the text shadow |
| 72 | 75 | |
| 73 | 76 | if (attrTermsText != null) { |
| 74 | 77 | Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g); |
| 75 | 78 | int textRealHeight = (int) termsStringBounds.getHeight(); |
| 76 | | termsTextHeight = textRealHeight - 5; |
| | 79 | termsTextHeight = textRealHeight; |
| 77 | 80 | 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); |
| | 81 | attrToUBounds = new Rectangle(PADDING, textY - termsTextHeight + fontDescent, termsTextWidth, textRealHeight); |
| | 82 | drawShadedText(g, attrTermsText, PADDING, textY); |
| 86 | 83 | } else { |
| 87 | 84 | attrToUBounds = null; |
| 88 | 85 | } |
| 89 | 86 | |
| 90 | | // Draw attribution logo |
| | 87 | // Draw attribution logo (on top of the terms of use text) |
| 91 | 88 | if (attrImage != null) { |
| 92 | | int x = 2; |
| 93 | 89 | int imgWidth = attrImage.getWidth(observer); |
| 94 | 90 | 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); |
| | 91 | int y = textY - imgHeight - termsTextHeight; |
| | 92 | attrImageBounds = new Rectangle(PADDING, y, imgWidth, imgHeight); |
| | 93 | g.drawImage(attrImage, PADDING, y, null); |
| 98 | 94 | } else { |
| 99 | 95 | attrImageBounds = null; |
| 100 | 96 | } |
| 101 | 97 | |
| | 98 | // Draw attribution (bottom right corner) |
| 102 | 99 | g.setFont(ATTR_FONT); |
| 103 | 100 | String attributionText = source.getAttributionText(zoom, topLeft, bottomRight); |
| 104 | 101 | if (attributionText == null) { |
| 105 | | // In case attribution text has been forgotte, display URL |
| | 102 | // In case the attribution text has been forgotten, display URL |
| 106 | 103 | attributionText = source.getAttributionLinkURL(); |
| 107 | 104 | } |
| 108 | 105 | if (attributionText != null) { |
| 109 | 106 | 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()); |
| | 107 | int textWidth = (int) stringBounds.getWidth(); |
| | 108 | int textHeight = (int) stringBounds.getHeight(); |
| | 109 | int x = width - textWidth - PADDING; |
| | 110 | drawShadedText(g, attributionText, x, textY); |
| | 111 | attrTextBounds = new Rectangle(x, textY - textHeight + fontDescent, textWidth, textHeight); |
| 118 | 112 | } else { |
| 119 | 113 | attrTextBounds = null; |
| 120 | 114 | } |
| … |
… |
|
| 122 | 116 | g.setFont(font); |
| 123 | 117 | } |
| 124 | 118 | |
| | 119 | /** |
| | 120 | * Draws a string with 1px shadow. |
| | 121 | * @param g the graphics |
| | 122 | * @param text the string to be drawn |
| | 123 | * @param x the x coordinate |
| | 124 | * @param y the y coordinate |
| | 125 | */ |
| | 126 | private static void drawShadedText(Graphics g, String text, int x, int y) { |
| | 127 | g.setColor(Color.black); |
| | 128 | g.drawString(text, x + 1, y + 1); |
| | 129 | g.setColor(Color.white); |
| | 130 | g.drawString(text, x, y); |
| | 131 | } |
| | 132 | |
| 125 | 133 | public boolean handleAttributionCursor(Point p) { |
| 126 | 134 | if (p == null) return false; |
| 127 | 135 | |