package simogl.gui;


import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;

import simogl.gameobjects.building.AbstractBuilding;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BuildingSelectionPanel extends JPanel 
{
	private static ButtonGroup buttonGroupBuildings = null;
	
	private static BuildingButton buttonInvisible = null;
	private BuildingButton buttonHouse = null;
	private BuildingButton buttonFarm = null; 
	private BuildingButton buttonCityHall = null; 

	public BuildingSelectionPanel() 
	{
		// set layout
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), "Buildings", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Dialog",1,16)));
		
		// create button group for the buildings
		this.buttonGroupBuildings = new ButtonGroup();
		
		
		//add invisible button, that always gest selected, when no other
		// button is selected
		buttonInvisible = new BuildingButton(-1);
		buttonGroupBuildings.add(buttonInvisible);
		buttonInvisible.setSelected(true);
		
		// house button
		this.buttonHouse = new BuildingButton(AbstractBuilding.HOUSE,
				new ImageIcon("./resources/images/menu/house64x64.png"));
		this.buttonHouse.setText("<html>House" +
				"<br><small>Price: 15</small>" +
				"<br><small>Reg. Costs: 0</small></html");
		this.buttonHouse.setFocusable(false);
		buttonGroupBuildings.add(this.buttonHouse);
		this.add(this.buttonHouse);
		
		// farm button
		this.buttonFarm = new BuildingButton(AbstractBuilding.FARM,
				new ImageIcon("./resources/images/menu/farm64x64.png"));
		this.buttonFarm.setText("<html>Farm" +
				"<br><small>Price: 20</small>" +
				"<br><small>Reg. Costs: 6</small></html>");
		this.buttonFarm.setFocusable(false);
		buttonGroupBuildings.add(this.buttonFarm);
		this.add(this.buttonFarm);
		
		// city hall button
		this.buttonCityHall = new BuildingButton(AbstractBuilding.CITY_HALL,
				new ImageIcon("./resources/images/menu/cityhall64x64.png"));
		this.buttonCityHall.setText("<html>City Hall" +
				"<br><small>Price: 25</small>" +
				"<br><small>Reg. Costs: 9</small></html>");
		this.buttonCityHall.setFocusable(false);
		buttonGroupBuildings.add(this.buttonCityHall);
		this.add(this.buttonCityHall);
		
	}
	
	/**
	 * Returns the id of the button that is selected in the panel. The
	 * returned id should be the same as one of the building type 
	 * constants, such as AbstractBuilding.HOUSE or AbstractBuilding.FARM
	 * @return button id of the selected toggle button
	 */
	public static int getSelectedButtonID()
	{
		return Integer.parseInt(
				buttonGroupBuildings.getSelection().getActionCommand());
	}
	
	/**
	 * Deselects the current selected building button. It will seem
	 * like no button is toggled anymore, but actually the invisible
	 * toggle button gets selected.
	 *
	 */
	public static void deselectButtons()
	{
		buttonInvisible.setSelected(true);
	}
}
