source: osm/applications/editors/josm/plugins/slippy_map_chooser/src/SourceButton.java@ 13260

Last change on this file since 13260 was 13260, checked in by stoecker, 16 years ago

close #2020. patch by Detlef Reichl

File size: 2.9 KB
Line 
1import java.awt.Graphics;
2import java.awt.Point;
3
4import javax.swing.ImageIcon;
5
6import org.openstreetmap.josm.tools.ImageProvider;
7
8public class SourceButton {
9
10 private int x = 0;
11 private int y = 30;
12
13 private ImageIcon enlargeImage;
14 private ImageIcon shrinkImage;
15 private ImageIcon imageMapnik;
16 private ImageIcon imageOsmarender;
17
18 private boolean isEnlarged = false;
19
20 private boolean isMapnik = true;
21
22 public static final int HIDE_OR_SHOW = 1;
23 public static final int MAPNIK = 2;
24 public static final int OSMARENDER = 3;
25
26 public SourceButton() {
27 enlargeImage = ImageProvider.get("", "layer-switcher-maximize.png");
28 shrinkImage = ImageProvider.get("", "layer-switcher-minimize.png");
29 imageMapnik = ImageProvider.get("", "blue_Mapnik.png");
30 imageOsmarender = ImageProvider.get("", "blue_Osmarender.png");
31 }
32
33 public void paint(Graphics g) {
34
35 if (isEnlarged) {
36 if (isMapnik) {
37 g.drawImage(imageMapnik.getImage(), g.getClipBounds().width
38 - imageMapnik.getIconWidth(), y, null);
39 } else {
40 g.drawImage(imageOsmarender.getImage(), g.getClipBounds().width
41 - imageMapnik.getIconWidth(), y, null);
42 }
43
44 if (shrinkImage != null) {
45 this.x = g.getClipBounds().width - shrinkImage.getIconWidth();
46 g.drawImage(shrinkImage.getImage(), x, y, null);
47 }
48
49 } else {
50 if (enlargeImage != null) {
51 this.x = g.getClipBounds().width - enlargeImage.getIconWidth();
52 g.drawImage(enlargeImage.getImage(), x, y, null);
53 }
54 }
55 }
56
57 public void toggle() {
58 this.isEnlarged = !this.isEnlarged;
59
60 }
61
62 public int hit(Point point) {
63 if (isEnlarged) {
64 if (x < point.x && point.x < x + shrinkImage.getIconWidth()) {
65 if (y < point.y && point.y < y + shrinkImage.getIconHeight()) {
66 return HIDE_OR_SHOW;
67 }
68 } else if (x - imageMapnik.getIconWidth() < point.x && point.x < x) {
69 if (y < point.y && point.y < y + imageMapnik.getIconHeight() / 2) {
70 isMapnik = false;
71 return OSMARENDER;
72 } else if (y + imageMapnik.getIconHeight() / 2 < point.y
73 && point.y < y + imageMapnik.getIconHeight()) {
74 isMapnik = true;
75 return MAPNIK;
76 }
77 }
78 } else {
79 if (x < point.x && point.x < x + enlargeImage.getIconWidth()) {
80 if (y < point.y && point.y < y + enlargeImage.getIconHeight()) {
81 return HIDE_OR_SHOW;
82 }
83 }
84 }
85
86 return 0;
87 }
88
89 public void setIsMapStyleMapnik (boolean style) {
90 isMapnik = style;
91 }
92}
Note: See TracBrowser for help on using the repository browser.