001    // License: GPL. Copyright 2007 by Tim Haussmann
002    package org.openstreetmap.josm.gui.bbox;
003    
004    import java.awt.Graphics;
005    import java.awt.Point;
006    
007    import javax.swing.ImageIcon;
008    
009    import org.openstreetmap.josm.tools.ImageProvider;
010    
011    /**
012     * @author Tim Haussmann
013     */
014    public class SizeButton{
015    
016        private int x = 0;
017        private int y = 0;
018    
019        private ImageIcon enlargeImage;
020        private ImageIcon shrinkImage;
021        private boolean isEnlarged = false;
022    
023        public SizeButton(){
024            enlargeImage = ImageProvider.get("view-fullscreen.png");
025            shrinkImage = ImageProvider.get("view-fullscreen-revert.png");
026        }
027    
028        public void paint(Graphics g) {
029            if(isEnlarged) {
030                if(shrinkImage != null)
031                    g.drawImage(shrinkImage.getImage(),x,y, null);
032            } else {
033                if(enlargeImage != null)
034                    g.drawImage(enlargeImage.getImage(),x,y, null);
035            }
036        }
037    
038        public void toggle() {
039            isEnlarged = !isEnlarged;
040        }
041    
042        public boolean isEnlarged() {
043            return isEnlarged;
044        }
045    
046        public boolean hit(Point point) {
047            if(x < point.x && point.x < x + enlargeImage.getIconWidth()) {
048                if(y < point.y && point.y < y + enlargeImage.getIconHeight()) {
049                    return true;
050                }
051            }
052            return false;
053        }
054    
055    }