source: josm/trunk/src/org/openstreetmap/josm/gui/download/SourceButton.java@ 1390

Last change on this file since 1390 was 1390, checked in by stoecker, 15 years ago

added slippy_map_chooser

File size: 3.6 KB
Line 
1package org.openstreetmap.josm.gui.download;
2
3import java.awt.Graphics;
4import java.awt.Point;
5
6import javax.swing.ImageIcon;
7
8import org.openstreetmap.josm.tools.ImageProvider;
9
10public class SourceButton {
11
12 private int x = 0;
13 private int y = 30;
14
15 private ImageIcon enlargeImage;
16 private ImageIcon shrinkImage;
17 private ImageIcon imageMapnik;
18 private ImageIcon imageOsmarender;
19 private ImageIcon imageCycleMap;
20
21 private boolean isEnlarged = false;
22
23 private int currentMap = MAPNIK;
24
25 public static final int HIDE_OR_SHOW = 1;
26 public static final int MAPNIK = 2;
27 public static final int OSMARENDER = 3;
28 public static final int CYCLEMAP = 4;
29
30 public SourceButton() {
31 enlargeImage = ImageProvider.get("layer-switcher-maximize.png");
32 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 }
37
38 public void paint(Graphics g) {
39
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);
51 }
52
53 if (shrinkImage != null) {
54 this.x = g.getClipBounds().width - shrinkImage.getIconWidth();
55 g.drawImage(shrinkImage.getImage(), x, y, null);
56 }
57
58 } else {
59 if (enlargeImage != null) {
60 this.x = g.getClipBounds().width - enlargeImage.getIconWidth();
61 g.drawImage(enlargeImage.getImage(), x, y, null);
62 }
63 }
64 }
65
66 public void toggle() {
67 this.isEnlarged = !this.isEnlarged;
68
69 }
70
71 public int hit(Point point) {
72 if (isEnlarged) {
73 if (x < point.x && point.x < x + shrinkImage.getIconWidth()) {
74 if (y < point.y && point.y < y + shrinkImage.getIconHeight()) {
75 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;
89 }
90 }
91 } else {
92 if (x < point.x && point.x < x + enlargeImage.getIconWidth()) {
93 if (y < point.y && point.y < y + enlargeImage.getIconHeight()) {
94 return HIDE_OR_SHOW;
95 }
96 }
97 }
98
99 return 0;
100 }
101
102 /**
103 * One of the constants OSMARENDER,MAPNIK or CYCLEMAP
104 */
105 public void setMapStyle (int style) {
106 currentMap = (style < 2 || style > 4) ? MAPNIK : style;
107 }
108}
Note: See TracBrowser for help on using the repository browser.