package mjs.graphical.jfc;

import com.sun.java.swing.JButton;
import com.sun.java.swing.ImageIcon;

import java.awt.Color;

import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

public class ActiveButton extends JButton {
    private Color _highlightFG;
    private Color _normalFG;
    private Color _highlightBG;
    private Color _normalBG;

    private ImageIcon _highlightIcon;
    private ImageIcon _normalIcon;

    private String _highlightText;
    private String _normalText;

    public ActiveButton(String normalText, String highlightText, Color normalFG, 
                        Color highlightFG, Color normalBG, Color highlightBG, 
                        ImageIcon normalIcon, ImageIcon highlightIcon) {
        super(normalText);
        _normalText = normalText;
        _highlightText = highlightText;
        _normalFG = normalFG;
        _normalBG = normalBG;
        _normalIcon = normalIcon;
        _highlightFG = highlightFG;
        _highlightBG = highlightBG;
        _highlightIcon = highlightIcon;

        setOpaque(true);
        setHighlightState(false);
        
        addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {}
            public void mouseReleased(MouseEvent e) {}

            public void mouseEntered(MouseEvent e) {
                setForeground(_highlightFG);
                setBackground(_highlightBG);
                setIcon(_highlightIcon);
                setText(_highlightText);
            }

            public void mouseExited(MouseEvent e) {
                setForeground(_normalFG);
                setBackground(_normalBG);
                setIcon(_normalIcon);
                setText(_normalText);
            }
        });
    }                    
                        
    public ActiveButton(String text) {
        // sane defaults
        this(text, text, Color.black, Color.black, Color.gray, Color.gray, null, null);
    }

    public void setHighlightText(String ht) {
        _highlightText = ht;
    }

    public String getHighlightText() {
        return _highlightText;
    }

    public void setNormalText(String nt) {
        _normalText = nt;
    }

    public String getNormalText() {
        return _normalText;
    }

    public void setHighlightIcon(ImageIcon i) {
        _highlightIcon = i;
    }

    public void setNormalIcon(ImageIcon i) {
        _normalIcon = i;
    }

    public ImageIcon getHighlightIcon() {
        return _highlightIcon;
    }

    public ImageIcon getNormalIcon() {
        return _normalIcon;
    }

    public void setHighlightFG(Color c) {
        _highlightFG = c;
    }

    public void setHighlightBG(Color c) {
        _highlightBG = c;
    }

    public void setNormalFG(Color c) {
        _normalFG = c;
    }

    public void setNormalBG(Color c) {
        _normalBG = c;
    }

    public Color getHighlightFG() {
        return _highlightFG;
    }

    public Color getHighlightBG() {
        return _highlightBG;
    }

    public Color getNormalFG() {
        return _normalFG;
    }

    public Color getNormalBG() {
        return _normalBG;
    }
    
    public void setHighlightState(boolean state) {
        if (state == true) {
            setText(_highlightText);
            setBackground(_highlightBG);
            setForeground(_highlightFG);
            setIcon(_highlightIcon);
        } else {
            setText(_normalText);
            setBackground(_normalBG);
            setForeground(_normalFG);
            setIcon(_normalIcon);
        }
    }
}