package de.gymnew.sudoku.gui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import de.gymnew.sudoku.model.Sudoku;

public class MainFrameHandler implements MouseListener {

	private MainFrame frame;

	public MainFrameHandler(MainFrame frame) {
		this.frame = frame;
	}

	/* ================================================== */
	// From DrawPanel
	/* ================================================== */

	@Override
	public void mouseClicked(MouseEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent event) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent event) {
		// TODO Auto-generated method stub

	}

	/* ================================================== */
	// From MainFrame
	/* ================================================== */

	public void onMenuQuit() {
		System.exit(0);

	}

	public void onMenuLoad() {
		JFileChooser chooser = new JFileChooser();
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();

		if (file != null) {
			try {
				frame.setSudoku(Sudoku.load(file));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else{
			JOptionPane.showMessageDialog(frame, "Keine Datei ausgew\u00E4hlt");
		}
	}

	public void onMenuSave() {
		JFileChooser chooser = new JFileChooser();
		chooser.showOpenDialog(null);
		File file = chooser.getSelectedFile();

		if (file != null) {
			try {
				frame.getSudoku().save(file);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else{
			JOptionPane.showMessageDialog(frame, "Kein Speicherort ausgew\u00E4hlt");
		}

	}

	public void onMenuStartSolver() {
		// TODO Auto-generated method stub

	}

	public void onMenuCredits() {
		JOptionPane.showMessageDialog(frame, "Tobias Bodensteiner, Sven Gebauer, Tobias Gr\u00F6mer, Katharina Hauer, Valentin Kellner, Elena Menzl, Jonas Piehler, Alexander Puff, Maximilian Rauch, Catrin Schnupfhagn, Rudolf Wimmer, Matthias Zetzl");

	}

	public void onMenuStopSolver() {
		// TODO Auto-generated method stub

	}
}

@@ -1478,42 +1478,139 @@
 %09%09%09%09
-// TODO Auto-generated catch block
+JOptionPane.showMessageDialog(frame, %22Sudoku konnte nicht geladen werden!%22, %22Fehler beim Laden!%22,%0A%09%09%09%09%09%09JOptionPane.ERROR_MESSAGE);
 %0A%09%09%09
@@ -1631,39 +1631,38 @@
 race();%0A%09%09%09%7D%0A%09%09%7D
-%0A%09%09
+ 
 else
+ 
 %7B%0A%09%09%09JOptionPane
@@ -1712,24 +1712,78 @@
 ew%5Cu00E4hlt%22
+, %22Fehler beim Laden!%22,%0A%09%09%09%09%09JOptionPane.ERROR_MESSAGE
 );%0A%09%09%7D%0A%09%7D%0A%0A%09
@@ -2030,42 +2030,147 @@
 %09%09%09%09
-// TODO Auto-generated catch block
+JOptionPane.showMessageDialog(frame, %22Sudoku konnte nicht gespeichert werden!%22,%0A%09%09%09%09%09%09%22Fehler beim Speichern!%22, JOptionPane.ERROR_MESSAGE);
 %0A%09%09%09
@@ -2203,15 +2203,14 @@
 %0A%09%09%7D
-%0A%09%09
+ 
 else
+ 
 %7B%0A%09%09
@@ -2281,16 +2281,74 @@
 00E4hlt%22
+, %22Fehler beim Speichern!%22,%0A%09%09%09%09%09JOptionPane.ERROR_MESSAGE
 );%0A%09%09%7D%0A%0A
@@ -2497,17 +2497,21 @@
 g(frame,
- 
+%0A%09%09%09%09
 %22Tobias 
@@ -2705,16 +2705,64 @@
 s Zetzl%22
+,%0A%09%09%09%09%22Credits%22, JOptionPane.INFORMATION_MESSAGE
 );%0A%0A%09%7D%0A%0A

handle IOExeptions