Ticket #23654: josm_23654_2.patch

File josm_23654_2.patch, 6.8 KB (added by gaben, 15 months ago)
  • Readme.txt

     
    3535
    36362. How does JMapViewer work?
    3737
    38 JMapViewer loads bitmap tiles from the OpenStreetmap tile server (Mapnik renderer).
    39 Therefore any application using JMapViewer requires a working Internet connection.   
     38JMapViewer loads bitmap tiles from the OpenStreetMap tile server (Mapnik renderer).
     39Therefore, any application using JMapViewer requires a working Internet connection.
    4040
    41413. How do I use JMapViewer in my application?
    4242
    43 You can just create an instance of the class org.openstreetmap.gui.jmapviewer.JMapViewer
     43You can create an instance of the class org.openstreetmap.gui.jmapviewer.JMapViewer
    4444using the default constructor and add it to your panel/frame/windows.
    45 For more details please see the Demo class in the same package.
     45For more details, please see the Demo class in the same package.
  • src/org/openstreetmap/gui/jmapviewer/AttributionSupport.java

     
    6262            return;
    6363        }
    6464
    65         // Draw attribution
    6665        Font font = g.getFont();
    6766        g.setFont(ATTR_LINK_FONT);
    6867
    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();
    7071        int termsTextHeight = 0;
    71         int termsTextY = height;
     72        int termsTextY = height - 1 - padding;  // the 1 is to compensate the text shadow
    7273
    7374        if (attrTermsText != null) {
    7475            Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds(attrTermsText, g);
    7576            int textRealHeight = (int) termsStringBounds.getHeight();
    76             termsTextHeight = textRealHeight - 5;
    7777            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);
    8682        } else {
    8783            attrToUBounds = null;
    8884        }
    8985
    90         // Draw attribution logo
     86        // Draw attribution logo (on top the terms of use text)
    9187        if (attrImage != null) {
    92             int x = 2;
    9388            int imgWidth = attrImage.getWidth(observer);
    9489            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);
    9893        } else {
    9994            attrImageBounds = null;
    10095        }
    10196
     97        // Draw attribution (bottom right corner)
    10298        g.setFont(ATTR_FONT);
    10399        String attributionText = source.getAttributionText(zoom, topLeft, bottomRight);
    104100        if (attributionText == null) {
    105             // In case attribution text has been forgotte, display URL
     101            // In case the attribution text has been forgotten, display URL
    106102            attributionText = source.getAttributionLinkURL();
    107103        }
    108104        if (attributionText != null) {
    109105            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);
    118112        } else {
    119113            attrTextBounds = null;
    120114        }
     
    122116        g.setFont(font);
    123117    }
    124118
     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
    125141    public boolean handleAttributionCursor(Point p) {
    126142        if (attrTextBounds != null && attrTextBounds.contains(p)) {
    127143            return true;
     
    166182    }
    167183
    168184}
    169 
  • src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

     
    180180     * @param url URL to check
    181181     */
    182182    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";
    184184        Matcher m = Pattern.compile("\\{[^}]*}").matcher(url);
    185185        while (m.find()) {
    186186            boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> pattern.matcher(m.group()).matches());