1 | import java.awt.Graphics;
|
---|
2 | import java.awt.Point;
|
---|
3 |
|
---|
4 | import javax.swing.ImageIcon;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
7 |
|
---|
8 | public 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 | }
|
---|