/**
 * @(#)MouseOverButtonUI.java	11/03/05
 * 
 * Copyright 2005 3GP01, KCL.  All unmodified code is copyright of its respective owner.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * The GNU General Public Licence should be contained within licence.txt;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA  02110-1301, USA.
 */

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonUI;

/**
 * This class extends BasicButtonUI, and provides mouse rollover functionality to enable
 * the border of buttons to change colour.
 * 
 * @author 3GP01 - Hardev Bhamra, Deepak Chandarana, James Tompkin
 * @version 1.0
 * @see Scrabble
 */

public class MouseOverButtonUI extends BasicButtonUI 
{
	public final static MouseOverButtonUI buttonUI = new MouseOverButtonUI();

	public static ComponentUI createUI(JComponent c) 
	{
		return buttonUI;
	}

	Color supplementaryColor = Scrabble.supplementaryColor;

	Color highlightColor = Scrabble.highlightColor;

	Border paddingBorder = BorderFactory.createMatteBorder(3, 15, 3, 15,
			supplementaryColor);

	Border outlineBorder = BorderFactory.createEtchedBorder(Color.WHITE,
			Color.GRAY);

	Border border;

	MouseListener mouseListener;

	public void installUI(JComponent c) 
	{	
		supplementaryColor = Scrabble.supplementaryColor;
		highlightColor = Scrabble.highlightColor;
		
		super.installUI(c);

		mouseListener = new MouseAdapter() 
		{
			public void mouseEntered(MouseEvent e) 
			{
				JButton c = (JButton) e.getSource();
				if (c.getIcon() == null) 
				{	if(c.isEnabled())
					{	outlineBorder = BorderFactory.createEtchedBorder(highlightColor,
								Color.GRAY);
						border = BorderFactory.createCompoundBorder(outlineBorder,
								paddingBorder);
						c.setBorder(border);
					}
				}
			}

			public void mouseExited(MouseEvent e) 
			{
				JButton c = (JButton) e.getSource();
				if (c.getIcon() == null) 
				{
					outlineBorder = BorderFactory.createEtchedBorder(
							Color.WHITE, Color.GRAY);
					border = BorderFactory.createCompoundBorder(outlineBorder,
							paddingBorder);
					c.setBorder(border);
				}
			}
		};
		c.addMouseListener(mouseListener);
	}

	public void uninstallUI(JComponent c) 
	{
		c.removeMouseListener(mouseListener);
		super.uninstallUI(c);
	}
}