package boundary;

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

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

import controller.LightningTimer;
import controller.PlayerLoadLevelSelectCtrl;
import controller.PlayerRestartLevelCtrl;
import model.PlayerModel;
import model.Variation;

/**
 * PlayerEndLevelView comes up when a level is completed.
 *
 * @author Bailey Sheridan
 */
public class PlayerEndLevelView extends JDialog{
  PlayerApplication app;
  PlayerModel model;
  LightningTimer timer;

  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);
    
    JButton backBut = new JButton("Level Select");
    JButton retryBut = new JButton("Replay?");

    // Ugly, I know. Can be extracted out later if someone really wants to.
    backBut.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        PlayerLoadLevelSelectCtrl load = new PlayerLoadLevelSelectCtrl(app, model);
        load.actionPerformed(e);
        dialog.dispose();
      }
    });

    retryBut.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        PlayerRestartLevelCtrl restart = new PlayerRestartLevelCtrl(app, model);
        restart.actionPerformed(e);
        if (model.level.rules.variation == Variation.LIGHTNING) {
          timer = new LightningTimer(app, model);
        }
        dialog.dispose();
      }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(new JLabel(endMsg));
    panel.add(new JLabel("Score: " + model.score));
    backBut.setAlignmentX(CENTER_ALIGNMENT);
    retryBut.setAlignmentX(CENTER_ALIGNMENT);
    panel.add(backBut);
    panel.add(retryBut);
    dialog.setContentPane(panel);
    dialog.setSize(300,200);
    panel.setSize(300, 200);
    dialog.setLocationRelativeTo(f);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.setVisible(true);
  }
}

@@ -12,16 +12,44 @@
 ndary;%0A%0A
+import java.awt.GridLayout;%0A
 import j
@@ -136,32 +136,62 @@
 wing.BoxLayout;%0A
+import javax.swing.ImageIcon;%0A
 import javax.swi
@@ -575,16 +575,36 @@
 Sheridan
+ and Maurizio Vitale
 %0A */%0Apub
@@ -1951,90 +1951,726 @@
     
-panel.add(new JLabel(endMsg));%0A    panel.add(new JLabel(%22Score: %22 + model.score));
+%0A    JLabel lblEndMsg = new JLabel(endMsg);%0A    lblEndMsg.setAlignmentX(CENTER_ALIGNMENT);%0A    panel.add(lblEndMsg);%0A%0A    JLabel lblEndScore = new JLabel(%22Score: %22 + model.score);%0A    lblEndScore.setAlignmentX(CENTER_ALIGNMENT);%0A    panel.add(lblEndScore);%0A    %0A    JPanel panelStars = new JPanel();%0A    panelStars.setLayout(new GridLayout(0,3,0,0));%0A    %0A    for (int i = 0; i %3C 3; i++) %7B%0A  %09  JLabel star;%0A  %09  if (model.score %3E model.level.rules.scoreThresholds%5Bi%5D) %7B%0A  %09%09  star = new JLabel(new ImageIcon(app.loader.getResource(%22star.png%22)));%0A  %09  %7D%0A  %09  else %7B%0A  %09%09  star = new JLabel(new ImageIcon(app.loader.getResource(%22starempty.png%22)));%0A  %09  %7D%0A  %09  panelStars.add(star);%0A    %7D%0A    panel.add(panelStars);%0A    
 %0A   

Add Stars to PlayerEndLevelView