Changeset 3597 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2010-10-09T15:25:28+02:00 (14 years ago)
Author:
jttt
Message:

Paint layers list in slippy map chooser dynamically (so other layers can be added in future)

Location:
trunk/src/org/openstreetmap/josm/gui/bbox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r3105 r3597  
    44import java.awt.Dimension;
    55import java.awt.Graphics;
     6import java.awt.Graphics2D;
    67import java.awt.Point;
    78import java.awt.Rectangle;
     
    116117
    117118            iSizeButton.paint(g);
    118             iSourceButton.paint(g);
     119            iSourceButton.paint((Graphics2D)g);
    119120        } catch (Exception e) {
    120121            e.printStackTrace();
     
    227228     * Sets the current bounding box in this bbox chooser without
    228229     * emiting a property change event.
    229      * 
     230     *
    230231     * @param bbox the bounding box. null to reset the bounding box
    231232     */
  • trunk/src/org/openstreetmap/josm/gui/bbox/SourceButton.java

    r3094 r3597  
    11package org.openstreetmap.josm.gui.bbox;
    22
    3 import java.awt.Graphics;
     3import java.awt.Color;
     4import java.awt.Font;
     5import java.awt.FontMetrics;
     6import java.awt.Graphics2D;
    47import java.awt.Point;
     8import java.awt.RenderingHints;
    59
    610import javax.swing.ImageIcon;
     
    1014public class SourceButton {
    1115
    12     private int x = 0;
    13     private int y = 30;
     16    // Filled in paint, used in hit
     17    private int barX;
     18    private int barY;
     19    private int barWidth;
     20    private int layerHeight;
     21
     22    private String[] sources = new String[] {"Mapnik", "Osmarender", "Cyclemap"};
    1423
    1524    private ImageIcon enlargeImage;
    1625    private ImageIcon shrinkImage;
    17     private ImageIcon imageMapnik;
    18     private ImageIcon imageOsmarender;
    19     private ImageIcon imageCycleMap;
    2026
    2127    private boolean isEnlarged = false;
     
    3137        enlargeImage = ImageProvider.get("layer-switcher-maximize.png");
    3238        shrinkImage = ImageProvider.get("layer-switcher-minimize.png");
    33         imageMapnik = ImageProvider.get("blue_Mapnik.png");
    34         imageOsmarender = ImageProvider.get("blue_Osmarender.png");
    35         imageCycleMap = ImageProvider.get("blue_CycleMap.png");
    3639    }
    3740
    38     public void paint(Graphics g) {
     41    public void paint(Graphics2D g) {
     42        if (isEnlarged) {
     43            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     44            int leftPadding = 5;
     45            int radioButtonSize = 10;
     46            int topPadding = 5;
     47            int bottomPadding = 5;
    3948
    40         if (isEnlarged) {
    41             if (currentMap == MAPNIK) {
    42                 g.drawImage(imageMapnik.getImage(), g.getClipBounds().width
    43                         - imageMapnik.getIconWidth(), y, null);
    44             }else if(currentMap == CYCLEMAP){
    45                  g.drawImage(imageCycleMap.getImage(), g.getClipBounds().width
    46                          - imageCycleMap.getIconWidth(), y, null);
    47             }
    48             else {
    49                 g.drawImage(imageOsmarender.getImage(), g.getClipBounds().width
    50                         - imageMapnik.getIconWidth(), y, null);
     49            int textWidth = 0;
     50
     51            g.setFont(g.getFont().deriveFont(Font.BOLD).deriveFont(15.0f));
     52            FontMetrics fm = g.getFontMetrics();
     53            for (String source: sources) {
     54                int width = fm.stringWidth(source);
     55                if (width > textWidth) {
     56                    textWidth = width;
     57                }
    5158            }
    5259
    53             if (shrinkImage != null) {
    54                 this.x = g.getClipBounds().width - shrinkImage.getIconWidth();
    55                 g.drawImage(shrinkImage.getImage(), x, y, null);
     60            barWidth = textWidth + 50;
     61            barX = g.getClipBounds().width  - barWidth - shrinkImage.getIconWidth();
     62            barY = 30;
     63            layerHeight = 20;
     64
     65            g.setColor(new Color(0, 0, 139, 179));
     66            g.fillRoundRect(barX, barY, barWidth + shrinkImage.getIconWidth(), sources.length * layerHeight + topPadding + bottomPadding, 10, 10);
     67            for (int i=0; i<sources.length; i++) {
     68                g.setColor(Color.WHITE);
     69                g.fillOval(barX + leftPadding, barY + topPadding + i * layerHeight + 6, radioButtonSize, radioButtonSize);
     70                g.drawString(sources[i], barX + leftPadding + radioButtonSize + leftPadding, barY + topPadding + i * layerHeight + g.getFontMetrics().getHeight());
     71                if (currentMap == i + 2) {
     72                    g.setColor(Color.BLACK);
     73                    g.fillOval(barX + leftPadding + 1, barY + topPadding + 7 + i * layerHeight, radioButtonSize - 2, radioButtonSize - 2);
     74                }
    5675            }
    5776
     77            g.drawImage(shrinkImage.getImage(), barX + barWidth, barY, null);
    5878        } else {
    59             if (enlargeImage != null) {
    60                 this.x = g.getClipBounds().width - enlargeImage.getIconWidth();
    61                 g.drawImage(enlargeImage.getImage(), x, y, null);
    62             }
     79            barWidth = 0;
     80            barX = g.getClipBounds().width  - shrinkImage.getIconWidth();
     81            barY = 30;
     82            g.drawImage(enlargeImage.getImage(), barX + barWidth, barY, null);
    6383        }
    6484    }
     
    7191    public int hit(Point point) {
    7292        if (isEnlarged) {
    73             if (x < point.x && point.x < x + shrinkImage.getIconWidth()) {
    74                 if (y < point.y && point.y < y + shrinkImage.getIconHeight()) {
     93            if (barX + barWidth < point.x) {
     94                if (barY < point.y && point.y < barY + shrinkImage.getIconHeight())
    7595                    return HIDE_OR_SHOW;
    76                 }
    77             } else if (x - imageMapnik.getIconWidth() < point.x && point.x < x) {
    78                 if (y < point.y && point.y < y + imageMapnik.getIconHeight() / 3) {
    79                     currentMap = OSMARENDER;
    80                     return OSMARENDER;
    81                 } else if (y + imageMapnik.getIconHeight() / 3 < point.y
    82                         && point.y < y + imageMapnik.getIconHeight() *2/3) {
    83                     currentMap = MAPNIK;
    84                     return MAPNIK;
    85                 } else if (y + imageMapnik.getIconHeight()* 2/3 < point.y
    86                         && point.y < y + imageMapnik.getIconHeight()) {
    87                     currentMap = CYCLEMAP;
    88                     return CYCLEMAP;
     96            } else if (barX < point.x && point.x < barX + barWidth) {
     97                int result = (point.y - barY - 5) / layerHeight;
     98                if (result >= 0 && result < sources.length) {
     99                    currentMap = result + 2;
     100                    return currentMap;
    89101                }
    90102            }
    91103        } else {
    92             if (x < point.x && point.x < x + enlargeImage.getIconWidth()) {
    93                 if (y < point.y && point.y < y + enlargeImage.getIconHeight()) {
     104            if (barX + barWidth < point.x) {
     105                if (barY < point.y && point.y < barY + shrinkImage.getIconHeight())
    94106                    return HIDE_OR_SHOW;
    95                 }
    96107            }
    97108        }
     
    104115     */
    105116    public void setMapStyle (int style) {
    106        currentMap = (style < 2 || style > 4) ? MAPNIK : style;
     117        currentMap = (style < 2 || style > 4) ? MAPNIK : style;
    107118    }
    108119}
Note: See TracChangeset for help on using the changeset viewer.