/*
 * Created on Nov 4, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package WheelOfFortune.game.userOutput;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import WheelOfFortune.game.*;
import WheelOfFortune.game.player.*;
import WheelOfFortune.game.userInput.*;


/**
 * @author caih
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GameOutput extends JFrame implements ActionListener{
	private GameOutput go;
	private int width = 800;
	private int height = 600;
	private BoardPanel bp;
	private PlayerPanel pp;
	private ConsolePanel cp;
	private WheelPanel wp;
	private JMenuBar mb;
	/**
	 * @return Returns the mb.
	 */
	public JMenuBar getMb() {
		return mb;
	}
	private JMenuItem newMI;
	private JMenuItem exitMI;
	private GameInput gi;
	private MainMenu mm;
	private Player[] p;
	/**
	 * 
	 */
	public GameOutput(MainMenu mm,Player[] p) {
		this.mm = mm;
		go = this;
		this.p = p;
		setTitle("Future Designers' Wheel of Fortune");
		setSize(width,height);
		setResizable(false);
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension d = tk.getScreenSize();
		int screenHeight = d.height;
		int screenWidth = d.width;
		setLocation((screenWidth - width) / 2, (screenHeight - height) / 2);

		GameWindowListener gwl = new GameWindowListener();
		this.addWindowListener(gwl);
		
		// menu
		JMenu fileM = new JMenu("File");
		fileM.setMnemonic('F');
		JMenuItem newMI = new JMenuItem("New Game", 'N');
		JMenuItem exitMI = new JMenuItem("Exit", 'x');
		fileM.add(newMI);
		fileM.addSeparator();
		fileM.add(exitMI);
		exitMI.addActionListener(this);
		newMI.addActionListener(this);
		
		mb = new JMenuBar();
		setJMenuBar(mb);
		mb.add(fileM);
		

		bp = new BoardPanel();
		bp.setPreferredSize(new Dimension(395, 350));
		
		pp = new PlayerPanel(p);
		pp.setPreferredSize(new Dimension(395, 280));
		
		cp = new ConsolePanel();
		cp.setPreferredSize(new Dimension(395, 190));
		
		wp = new WheelPanel();
		wp.setPreferredSize(new Dimension(395, 260));
		
		JPanel left = new JPanel();
		left.setLayout(new BorderLayout());
		left.add(bp,BorderLayout.NORTH);
		left.add(cp,BorderLayout.SOUTH);

		
		JPanel right = new JPanel();
		right.setLayout(new BorderLayout());
		right.add(pp,BorderLayout.NORTH);
		right.add(wp,BorderLayout.SOUTH);
		
		Container cPane = getContentPane();
		cPane.add(left,BorderLayout.WEST);
		cPane.add(right,BorderLayout.EAST);
		
	}
	 public class GameWindowListener extends WindowAdapter
	 {
	 	public void windowClosing(WindowEvent e)
	 	{
			int selection = JOptionPane.showConfirmDialog(go,
					"Are you sure you want to exit this game",
					"Confirm Exit",
					JOptionPane.YES_NO_OPTION,
					JOptionPane.WARNING_MESSAGE);
			if(selection == JOptionPane.YES_OPTION)
			{
				go.dispose();
				mm.setVisible(true);
			}
	 	}
	 }
	public void setInput(GameInput gi)
	{
		this.gi = gi;
	}
	public void actionPerformed(ActionEvent e)	
	{
		int selection = JOptionPane.showConfirmDialog(this,
				"Are you sure you want to exit this game",
				"Confirm Exit",
				JOptionPane.YES_NO_OPTION,
				JOptionPane.WARNING_MESSAGE);
		if(selection == JOptionPane.YES_OPTION)
		{
			if(e.getSource() == exitMI)
			{
				go.dispose();
				mm.setVisible(true);
			}
			else
			{
				go.dispose();
				mm.getOF().show();
			}
		}
	}
	public void changeSkin(String path)
	{
		String p = path + "\\";
		bp.changeSkin(p);
		pp.changeSkin(p);
		wp.changeSkin(p);

	}
	/**
	 * @return Returns the bp.
	 */
	public BoardPanel getBP() {
		return bp;
	}
	/**
	 * @return Returns the cp.
	 */
	public ConsolePanel getCP() {
		return cp;
	}
	/**
	 * @return Returns the exitMI.
	 */
	public JMenuItem getExitMI() {
		return exitMI;
	}
	/**
	 * @return Returns the newMI.
	 */
	public JMenuItem getNewMI() {
		return newMI;
	}
	/**
	 * @return Returns the pp.
	 */
	public PlayerPanel getPP() {
		return pp;
	}
	/**
	 * @return Returns the wp.
	 */
	public WheelPanel getWP() {
		return wp;
	}
	
	public void println(String s)
	{
		cp.println(s);
	}
	public void print (String s)
	{
		cp.print(s);
	}
	public void updatePanels(GameModel gm, String s)
	{
		println(s);
		bp.updatePanel(gm);
		pp.updatePanel(gm, gi);
		wp.repaint();
	}
	public void updatePanels(GameModel gm)
	{
		bp.updatePanel(gm);
		pp.updatePanel(gm, gi);
		wp.repaint();
	}
	
}
