package boundary;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import controller.PlayerLoadLevelSelectCtrl;
import model.PlayerModel;

/**
 * PlayerEndLevelView comes up when a level is completed.
 * @author Bailey Sheridan
 *
 */
public class PlayerEndLevelView extends JDialog{

	PlayerApplication app;
	PlayerModel model;
	
	public PlayerEndLevelView(PlayerApplication app, PlayerModel model) {
		this.app = app;
		this.model = model;
	}
	
    public void openDialog(String endMsg)
    {
    	JFrame f = new JFrame();
		
        final JDialog dialog = new JDialog(app, "Level Finished", true);
        final JButton backBut = new JButton("Level Select");
        
        // Ugly, I know. Can be extracted out later if someone really wants to.
        backBut.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				PlayerLoadLevelSelectCtrl pllsc = new PlayerLoadLevelSelectCtrl(app, model);
				pllsc.actionPerformed(e);
				dialog.dispose();
			}
        	
        });
        
        JPanel panel = new JPanel();
        panel.add(new JLabel(endMsg));
        panel.add(new JLabel("Score: " + model.score));
        panel.add(backBut);
        JButton[] buttons = { backBut };
        JOptionPane optionPane = new JOptionPane(panel,
                                                 JOptionPane.YES_NO_OPTION,
                                                 JOptionPane.PLAIN_MESSAGE,
                                                 null, buttons, backBut);
        dialog.getContentPane().add(optionPane);
        dialog.setSize(300,200);
        dialog.setLocationRelativeTo(f);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        dialog.setVisible(true);
    }
}

@@ -301,16 +301,58 @@
 ctCtrl;%0A
+import controller.PlayerRestartLevelCtrl;%0A
 import m
@@ -840,22 +840,16 @@
         
-final 
 JButton 
@@ -887,16 +887,67 @@
 lect%22);%0A
+        JButton retryBut = new JButton(%22Replay?%22);%0A
         
@@ -1175,21 +1175,20 @@
 ectCtrl 
-pllsc
+load
  = new P
@@ -1233,13 +1233,12 @@
 %09%09%09%09
-pllsc
+load
 .act
@@ -1304,32 +1304,353 @@
    %7D);%0A        %0A
+        retryBut.addActionListener(new ActionListener()%7B%0A        %09%0A        %09@Override%0A        %09public void actionPerformed(ActionEvent e) %7B%0A        %09%09PlayerRestartLevelCtrl restart = new PlayerRestartLevelCtrl(app, model);%0A        %09%09restart.actionPerformed(e);%0A        %09%09dialog.dispose();%0A        %09%7D%0A        %7D);%0A        %0A
         JPanel p
@@ -1785,32 +1785,61 @@
 l.add(backBut);%0A
+        panel.add(retryBut);%0A
         JButton%5B
@@ -1860,16 +1860,27 @@
 backBut 
+, retryBut 
 %7D;%0A     

Add replay button