package bwyap.familyfeud.gui.window;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import bwyap.familyfeud.gui.GBC;
import bwyap.familyfeud.gui.control.ConsolePanel;
import bwyap.familyfeud.gui.control.WindowControlPanel;
import bwyap.utility.logging.Logger;

/**
 * This is a control window with controls to 
 * run the Family Feud game from a separate window
 * @author bwyap
 *
 */
public class ControlWindow extends FamilyFeudWindow {
	
	private static final long serialVersionUID = -4445104890877967661L;

	public static final int WIDTH = 800;
	public static final int HEIGHT = 600;
	
	private GameWindow gameWindow;
	private JPanel contentPane;
	private ConsolePanel consolePanel;
	private WindowControlPanel windowControlPanel;
	
	/**
	 * Create a new control window
	 * @param title
	 */
	public ControlWindow(String title, GameWindow gameWindow) {
		super(title, WIDTH, HEIGHT);
		this.gameWindow = gameWindow;
	}

	/**
	 * Initialize window components
	 */
	public void initWindow() {
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setAlwaysOnTop(true);
		setResizable(false);
		setLayout(new BorderLayout());
		
		// init components
		contentPane = new JPanel();
		contentPane.setLayout(new GridBagLayout());
		
		consolePanel = new ConsolePanel();
		contentPane.add(consolePanel, new GBC(0, 1));
		
		windowControlPanel = new WindowControlPanel(gameWindow);
		contentPane.add(windowControlPanel, new GBC(0, 0));
		
		add(contentPane, BorderLayout.CENTER);
		Logger.info("Control window initialized.");
	}

}

@@ -96,33 +96,137 @@
 ut;%0A
-%0Aimport javax.swing.JFram
+import java.awt.event.WindowAdapter;%0Aimport java.awt.event.WindowEvent;%0A%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JOptionPan
 e;%0Ai
@@ -1233,12 +1233,18 @@
 ame.
-EXIT
+DO_NOTHING
 _ON_
@@ -1334,16 +1334,391 @@
 ());%0A%09%09%0A
+%09%09addWindowListener(new WindowAdapter() %7B%0A%09%09%09@Override%0A%09%09%09public void windowClosing(WindowEvent e) %7B%0A%09%09%09%09if (JOptionPane.showConfirmDialog(ControlWindow.this,%0A%09%09%09%09%09%22Are you sure you want to exit the program?%22,%0A%09%09%09%09%09%22Exit program?%22,%0A%09%09%09%09%09JOptionPane.OK_CANCEL_OPTION,%0A%09%09%09%09%09JOptionPane.WARNING_MESSAGE)%0A%09%09%09%09%09== JOptionPane.OK_OPTION) %7B%0A%09%09%09%09%09System.exit(0);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09%0A
 %09%09// ini

Add window listener for window closing