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