- Timestamp:
- 2010-10-09T15:25:28+02:00 (14 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r3105 r3597 4 4 import java.awt.Dimension; 5 5 import java.awt.Graphics; 6 import java.awt.Graphics2D; 6 7 import java.awt.Point; 7 8 import java.awt.Rectangle; … … 116 117 117 118 iSizeButton.paint(g); 118 iSourceButton.paint( g);119 iSourceButton.paint((Graphics2D)g); 119 120 } catch (Exception e) { 120 121 e.printStackTrace(); … … 227 228 * Sets the current bounding box in this bbox chooser without 228 229 * emiting a property change event. 229 * 230 * 230 231 * @param bbox the bounding box. null to reset the bounding box 231 232 */ -
trunk/src/org/openstreetmap/josm/gui/bbox/SourceButton.java
r3094 r3597 1 1 package org.openstreetmap.josm.gui.bbox; 2 2 3 import java.awt.Graphics; 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.FontMetrics; 6 import java.awt.Graphics2D; 4 7 import java.awt.Point; 8 import java.awt.RenderingHints; 5 9 6 10 import javax.swing.ImageIcon; … … 10 14 public class SourceButton { 11 15 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"}; 14 23 15 24 private ImageIcon enlargeImage; 16 25 private ImageIcon shrinkImage; 17 private ImageIcon imageMapnik;18 private ImageIcon imageOsmarender;19 private ImageIcon imageCycleMap;20 26 21 27 private boolean isEnlarged = false; … … 31 37 enlargeImage = ImageProvider.get("layer-switcher-maximize.png"); 32 38 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");36 39 } 37 40 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; 39 48 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 } 51 58 } 52 59 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 } 56 75 } 57 76 77 g.drawImage(shrinkImage.getImage(), barX + barWidth, barY, null); 58 78 } 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); 63 83 } 64 84 } … … 71 91 public int hit(Point point) { 72 92 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()) 75 95 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; 89 101 } 90 102 } 91 103 } 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()) 94 106 return HIDE_OR_SHOW; 95 }96 107 } 97 108 } … … 104 115 */ 105 116 public void setMapStyle (int style) { 106 currentMap = (style < 2 || style > 4) ? MAPNIK : style;117 currentMap = (style < 2 || style > 4) ? MAPNIK : style; 107 118 } 108 119 }
Note:
See TracChangeset
for help on using the changeset viewer.