001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.bbox;
003
004import java.awt.Graphics;
005import java.awt.Point;
006
007import javax.swing.ImageIcon;
008
009import org.openstreetmap.josm.tools.ImageProvider;
010
011/**
012 * @author Tim Haussmann
013 */
014public 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}