package simogl.gui;

import javax.swing.ImageIcon;
import javax.swing.JToggleButton;

import simogl.effect.sound.SampledSound;

public class BuildingButton extends JToggleButton
{	 
	private SampledSound soundClicked = null;
    private String filePath = "./resources/sounds/samples/menuclick.wav";
	
	/**
	 * Creates a new toggle button for a building in the 
	 * building selection panel with the specified parameters.
	 * @param id insert the constant of the building-type here for
	 * which you would like to create the button 
	 * (e.g. AbstractBuilding.HOUSE). This id will be set as the buttons
	 * action command
	 */
	public BuildingButton(int id)
	{
		super();		
		this.setActionCommand(Integer.toString(id));
		this.addActionListener();
		this.soundClicked = new SampledSound(filePath);
	}
	
	
	/**
	 * Creates a new toggle button for a building in the 
	 * building selection panel with the specified parameters.
	 * @param id insert the constant of the building-type here for
	 * which you would like to create the button 
	 * (e.g. AbstractBuilding.HOUSE). This id will be set as the buttons
	 * action command
	 * @param text text to add to the button
	 */
	public BuildingButton(int id, String text)
	{
		super(text);
		this.setActionCommand(Integer.toString(id));
		this.addActionListener();
		this.soundClicked = new SampledSound(filePath);
	}
	
	
	/**
	 * Creates a new toggle button for a building in the 
	 * building selection panel with the specified parameters.
	 * @param id insert the constant of the building-type here for
	 * which you would like to create the button 
	 * (e.g. AbstractBuilding.HOUSE). This id will be set as the buttons
	 * action command
	 * @param icon icon to use on the button
	 */
	public BuildingButton(int id, ImageIcon icon)
	{
		super(icon);
		this.setActionCommand(Integer.toString(id));
		this.addActionListener();
		this.soundClicked = new SampledSound(filePath);
	}
	
	/**
	 * Creates a new toggle button for a building in the 
	 * building selection panel with the specified parameters.
	 * @param id insert the constant of the building-type here for
	 * which you would like to create the button
	 * (e.g. AbstractBuilding.HOUSE)
	 * @param icon icon to use on the button
	 * @param text text to add to the button
	 */
	public BuildingButton(int id, ImageIcon icon, String text)
	{
		super(text, icon);
		this.setActionCommand(Integer.toString(id));
		this.addActionListener();
		this.soundClicked = new SampledSound(filePath);
	}
	
	/**
	 * Helper method to add an action listener to the button.
	 *
	 */
	private void addActionListener()
	{
		this.addActionListener(new java.awt.event.ActionListener()
		        {
		            public void actionPerformed(java.awt.event.ActionEvent evt)
		            {
		            	buttonAction();
		            }
		        });
	}
	
	/**
	 * Helper method that contains all the things that shall be 
	 * performed, when the button is clicked.
	 *
	 */
	private void buttonAction()
	{		
		this.soundClicked.play(false);
	}	
}
