
package ch.hearc.pokerface.gui;

import java.awt.CardLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import ch.hearc.pokerface.gui.gamescreen.table.board.JPanelGameBoard;
import ch.hearc.pokerface.gui.menuscreens.JOPTableConfiguration;
import ch.hearc.pokerface.gui.menuscreens.JPanelMainMenu;
import ch.hearc.pokerface.gui.menuscreens.JPanelProfile;
import ch.hearc.pokerface.gui.options.JPanelTopBar;
import ch.hearc.pokerface.gui.tools.ImageShop;
import ch.hearc.pokerface.gui.tools.SplashWindow;

public class JFrameMain extends JFrame
{
	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	private JPanelProfile	panelProfile;
	private JPanelMainMenu	panelMainMenu;
	private JPanelGameBoard	panelGameBoard;
	private CardLayout		layout;

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public JFrameMain()
	{
		createSplashScreen(); //TODO il faut introduire un fichier manifest pour lancer le splash screen
		JPanelTopBar.getInstance().setFrameMain(this);

		geometry();
		control();
		appearance();
	}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	// CARD MANIPULATIONS
	public void setCard(String card)
	{
		try
		{
			if (card == "panelGameBoard")
			{
				JOPTableConfiguration tableConfig = new JOPTableConfiguration(this, panelGameBoard);
				if (!tableConfig.switchToGame()) { return; // Abort the process of switching to gameBoard
				}
				// Game is launching

				panelGameBoard.refreshAllComponents();
				setFullscreen(true);
			}
			else if (card == "panelProfile")
			{
				panelProfile.refreshProfilesData();
			}
			layout.show(this.getContentPane(), card);
		}
		catch (Exception e)
		{
		}
	}

	public void gameToMainMenu()
	{
		setFullscreen(false);

		panelMainMenu.refreshTopBar();
		setCard("panelMainMenu");
	}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	public JPanelProfile getProfilePanel()
	{
		return panelProfile;
	}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void setFullscreen(boolean isFullscreened)
	{
		setVisible(false);
		dispose();
		if (isFullscreened)
		{
			setExtendedState(MAXIMIZED_BOTH);
		}
		else
		{
			setExtendedState(NORMAL);
			setSize(1200, (int)(1200 * 0.75));
		}
		/*setUndecorated(!isUndecorated());
		if (isFullscreened)
		{
			GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
		}
		else
		{
			GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
		}*/
		setVisible(true);
	}

	private void geometry()
	{

		/**
		 * Layout
		 */
		layout = new CardLayout();
		setLayout(layout);

		/**
		 * Instanciations
		 */
		try
		{
			panelProfile = new JPanelProfile(this);
			panelMainMenu = new JPanelMainMenu(this);
		}
		catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		panelGameBoard = new JPanelGameBoard();

		/**
		 * Adds
		 */

		add(panelProfile, "panelProfile");
		add(panelGameBoard, "panelGameBoard");
		add(panelMainMenu, "panelMainMenu");
	}

	private void control()
	{
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		addWindowListener(new WindowAdapter()
		{
			@Override
			public void windowClosing(WindowEvent arg0)
			{
				panelProfile.serializeProfiles();
			}
		});
	}

	private void appearance()
	{

		setSize(1200, (int)(1200 * 0.75));

		setTitle("\u2666 \u2665 \u2660 \u2663 Pokerface \u2663 \u2660 \u2665 \u2666");

		setResizable(false);

		layout.show(this.getContentPane(), "panelProfile");

		//setUndecorated(true);
		this.setVisible(true);
		validate();

		setIconImage(ImageShop.IMAGE_APPICON);
	}

	private void createSplashScreen()
	{
		SplashWindow.splash(ImageShop.IMAGE_SPLASH);
		try
		{
			//Thread.sleep(2000);
		}
		catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SplashWindow.disposeSplash();
	}

}

@@ -1612,29 +1612,16 @@
 d)%0D%0A%09%7B%0D%0A
-%09%09try%0D%0A%09%09%7B%0D%0A%09
 %09%09if (ca
@@ -1647,21 +1647,19 @@
 rd%22)%0D%0A%09%09
-%09
 %7B%0D%0A
-%09
 %09%09%09JOPTa
@@ -1739,17 +1739,16 @@
 oard);%0D%0A
-%09
 %09%09%09if (!
@@ -1836,21 +1836,19 @@
 ard%0D%0A%09%09%09
-%09
 %7D%0D%0A
-%09
 %09%09%09// Ga
@@ -1866,17 +1866,16 @@
 hing%0D%0A%0D%0A
-%09
 %09%09%09panel
@@ -1909,17 +1909,16 @@
 nts();%0D%0A
-%09
 %09%09%09setFu
@@ -1936,21 +1936,19 @@
 ue);%0D%0A%09%09
-%09
 %7D%0D%0A
-%09
 %09%09else i
@@ -1973,29 +1973,27 @@
 rofile%22)%0D%0A%09%09
-%09
 %7B%0D%0A
-%09
 %09%09%09panelProf
@@ -2022,21 +2022,19 @@
 a();%0D%0A%09%09
-%09
 %7D%0D%0A
-%09
 %09%09layout
@@ -2074,46 +2074,8 @@
 );%0D%0A
-%09%09%7D%0D%0A%09%09catch (Exception e)%0D%0A%09%09%7B%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A

Remove useless try/catch