Ignore:
Timestamp:
2011-10-06T10:12:46+02:00 (13 years ago)
Author:
bastik
Message:

unified redundant attribution code from org.openstreetmap.gui.jmapviewer.JMapViewer and org.openstreetmap.josm.gui.layer.TMSLayer

new: i18n support for the jmapviewer component

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r26701 r26783  
    8989    private TileSource tileSource;
    9090
    91     // Attribution
    92     private Image attrImage;
    93     private String attrTermsUrl;
    94     public static final Font ATTR_FONT = new Font("Arial", Font.PLAIN, 10);
    95     public static final Font ATTR_LINK_FONT;
    96 
    97     protected Rectangle attrTextBounds = null;
    98     protected Rectangle attrToUBounds = null;
    99     protected Rectangle attrImageBounds = null;
    100 
    101     static {
    102         HashMap<TextAttribute, Integer> aUnderline = new HashMap<TextAttribute, Integer>();
    103         aUnderline.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    104         ATTR_LINK_FONT = ATTR_FONT.deriveFont(aUnderline);
    105     }
     91    protected AttributionSupport attribution = new AttributionSupport();
    10692
    10793    /**
     
    584570        }
    585571
    586         paintAttribution(g);
     572        attribution.paintAttribution(g, getWidth(), getHeight(), getPosition(0, 0), getPosition(getWidth(), getHeight()), zoom, this);
    587573    }
    588574
     
    832818            setZoom(tileSource.getMaxZoom());
    833819        }
    834         boolean requireAttr = tileSource.requiresAttribution();
    835         if (requireAttr) {
    836             attrImage = tileSource.getAttributionImage();
    837             attrTermsUrl = tileSource.getTermsOfUseURL();
    838         } else {
    839             attrImage = null;
    840             attrTermsUrl = null;
    841         }
     820
     821        attribution.initialize(tileSource);
    842822        repaint();
    843823    }
     
    894874    }
    895875
    896     private void paintAttribution(Graphics g) {
    897         if (!tileSource.requiresAttribution())
    898             return;
    899         // Draw attribution
    900         Font font = g.getFont();
    901         g.setFont(ATTR_LINK_FONT);
    902 
    903         Rectangle2D termsStringBounds = g.getFontMetrics().getStringBounds("Background Terms of Use", g);
    904         int textRealHeight = (int) termsStringBounds.getHeight();
    905         int textHeight = textRealHeight - 5;
    906         int textWidth = (int) termsStringBounds.getWidth();
    907         int termsTextY = getHeight() - textHeight;
    908         if (attrTermsUrl != null) {
    909             int x = 2;
    910             int y = getHeight() - textHeight;
    911             attrToUBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight);
    912             g.setColor(Color.black);
    913             g.drawString("Background Terms of Use", x + 1, y + 1);
    914             g.setColor(Color.white);
    915             g.drawString("Background Terms of Use", x, y);
    916         }
    917 
    918         // Draw attribution logo
    919         if (attrImage != null) {
    920             int x = 2;
    921             int imgWidth = attrImage.getWidth(this);
    922             int height = attrImage.getHeight(null);
    923             int y = termsTextY - height - textHeight - 5;
    924             attrImageBounds = new Rectangle(x, y, imgWidth, height);
    925             g.drawImage(attrImage, x, y, null);
    926         }
    927 
    928         g.setFont(ATTR_FONT);
    929         Coordinate topLeft = getPosition(0, 0);
    930         Coordinate bottomRight = getPosition(getWidth(), getHeight());
    931         String attributionText = tileSource.getAttributionText(zoom, topLeft, bottomRight);
    932         if (attributionText != null) {
    933             Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(attributionText, g);
    934             int x = getWidth() - (int) stringBounds.getWidth();
    935             int y = getHeight() - textHeight;
    936             g.setColor(Color.black);
    937             g.drawString(attributionText, x + 1, y + 1);
    938             g.setColor(Color.white);
    939             g.drawString(attributionText, x, y);
    940             attrTextBounds = new Rectangle(x, y-textHeight, textWidth, textRealHeight);
    941         }
    942 
    943         g.setFont(font);
    944     }
    945 
    946876    protected EventListenerList listenerList = new EventListenerList();
    947877
     
    962892    /**
    963893     * Send an update to all objects registered with viewer
    964      * 
     894     *
    965895     * @param event to dispatch
    966896     */
Note: See TracChangeset for help on using the changeset viewer.