001 package jagafa.view.newui;
002
003 import java.awt.Color;
004
005 import jagafa.scores.ScoreTable;
006
007 import javax.swing.BorderFactory;
008 import javax.swing.BoxLayout;
009 import javax.swing.JLabel;
010 import javax.swing.JPanel;
011 import javax.swing.JSeparator;
012 import javax.swing.border.Border;
013
014 public class SimpleSTPanel extends JPanel {
015
016 private static final long serialVersionUID = 184472838175055582L;
017
018 private ScoreTable scoreTable_;
019
020 public SimpleSTPanel(ScoreTable scoreTable) {
021 this.scoreTable_ = scoreTable;
022 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
023 create();
024 }
025
026 private JLabel roundsLabel;
027
028 private JLabel team1Label;
029
030 private JLabel team2Label;
031
032 private JLabel winnerLabel;
033
034 public void create() {
035 this.removeAll();
036 this.addTitleBorder("Score Table:");
037
038 int scores[] = this.scoreTable_.getScores();
039
040 int team1 = scores[0] + scores[2];
041 int team2 = scores[1] + scores[3];
042 roundsLabel = new JLabel("Rounds: \t" + this.scoreTable_.roundsPlayed());
043 team1Label = new JLabel( "Team1: \t" + team1);
044 team2Label = new JLabel( "Team2: \t" + team2);
045 winnerLabel = new JLabel("Winner: \t" + this.scoreTable_.getWinningScore());
046 this.add(roundsLabel);
047 this.add(new JSeparator());
048 this.add(team1Label);
049 this.add(team2Label);
050 this.add(new JSeparator());
051 this.add(winnerLabel);
052
053 this.validate();
054 }
055 boolean over = false;
056 public void update() {
057
058 int scores[] = this.scoreTable_.getScores();
059
060 int team1 = scores[0] + scores[2];
061 int team2 = scores[1] + scores[3];
062
063 if (this.scoreTable_.isGameOver()) {
064 winnerLabel.setText("GAME OVER!");
065 if (!over) {
066 roundsLabel.setText("Rounds: \t" + this.scoreTable_.roundsPlayed());
067 team1Label.setText( "Team1: \t" + team1);
068 team2Label.setText( "Team2: \t" + team2);
069 }
070 over = true;
071 this.validate();
072 return;
073 } else {
074 winnerLabel.setText( "Winner: \t" + this.scoreTable_.getWinningScore());
075
076 }
077 roundsLabel.setText("Rounds: \t" + this.scoreTable_.roundsPlayed());
078 team1Label.setText( "Team1: \t" + team1);
079 team2Label.setText( "Team2: \t" + team2);
080
081 this.validate();
082
083 }
084
085 private void addTitleBorder(String title) {
086 Border rawBorder = BorderFactory.createLineBorder(Color.BLACK);
087
088 Border titledB = BorderFactory.createTitledBorder(rawBorder, title);
089 this.setBorder(titledB);
090
091 }
092
093 }