Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.boardTab.MatchStatusPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
MatchStatusPanel
0%
0/179
0%
0/16
2.5
 
 1  
 /******************************************************************************
 2  
  * MatchStatusPanel.java - Draw the Match statistics at the top of the board.
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.2  2011/05/31 19:45:15  dick
 10  
  * Javadoc.
 11  
  *
 12  
  * Revision 1.1  2011/05/15 02:17:33  dick
 13  
  * c.b.f.B.gui.board becomes c.b.f.B.gui.boardTab.
 14  
  *
 15  
  * Revision 1.6  2011/05/14 04:43:01  dick
 16  
  * I needed to deal with some lightweight Boards.
 17  
  * So finally make the primary document Document
 18  
  * and demote just the Board handling to a domain object.
 19  
  *
 20  
  * Revision 1.5  2011/05/12 20:27:40  dick
 21  
  * Scratch a to do block
 22  
  *
 23  
  * Revision 1.4  2010/12/22 04:36:08  dick
 24  
  * Display the player's rating next to his name.
 25  
  *
 26  
  * Revision 1.3  2010/03/03 13:12:21  inim
 27  
  * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
 28  
  *
 29  
  * Revision 1.2  2010/03/03 12:19:49  inim
 30  
  * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010.
 31  
  *
 32  
  * Revision 1.1  2010/02/04 05:57:53  inim
 33  
  * Mavenized project folder layout
 34  
  *
 35  
  * Revision 1.3  2009/02/14 15:27:42  dick
 36  
  * BuckoFIBS is released under the GNU license.
 37  
  *
 38  
  * Revision 1.2  2009/01/29 08:27:22  dick
 39  
  * Draw the correct player in yellow.
 40  
  *
 41  
  * Revision 1.1  2009/01/28 19:37:28  dick
 42  
  * package com.buckosoft.fibs.gui.board becomes com.buckosoft.fibs.BuckoFIBS.gui.board.
 43  
  *
 44  
  * Revision 1.3  2009/01/10 05:07:29  dick
 45  
  * Put the correct data in the correct place.
 46  
  * Add pipCount handling.
 47  
  *
 48  
  * Revision 1.2  2009/01/08 18:33:29  dick
 49  
  * Fleshing out functionality.
 50  
  *
 51  
  * Revision 1.1  2009/01/08 01:33:35  dick
 52  
  * Draw the Match statistics at the top of the board.
 53  
  */
 54  
 
 55  
 /* 
 56  
  * This program is free software: you can redistribute it and/or modify
 57  
  * it under the terms of the GNU General Public License as published by
 58  
  * the Free Software Foundation, either version 3 of the License, or
 59  
  * (at your option) any later version.
 60  
  *
 61  
  * This program is distributed in the hope that it will be useful,
 62  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 63  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 64  
  * GNU General Public License for more details.
 65  
  *
 66  
  * You should have received a copy of the GNU General Public License
 67  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 68  
  *
 69  
  * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
 70  
  * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
 71  
  * 
 72  
  */
 73  
 package com.buckosoft.fibs.BuckoFIBS.gui.boardTab;
 74  
 
 75  
 import java.awt.Color;
 76  
 import java.awt.Dimension;
 77  
 import java.awt.Font;
 78  
 import java.awt.GridBagConstraints;
 79  
 import java.awt.GridBagLayout;
 80  
 import java.awt.Insets;
 81  
 
 82  
 import javax.swing.JLabel;
 83  
 import javax.swing.JPanel;
 84  
 import javax.swing.SwingConstants;
 85  
 
 86  
 import com.buckosoft.fibs.BuckoFIBS.gui.MainDialog;
 87  
 import com.buckosoft.fibs.document.Document;
 88  
 import com.buckosoft.fibs.domain.Board;
 89  
 import com.buckosoft.fibs.domain.Player;
 90  
 
 91  
 /** Draw the Match statistics at the top of the board.
 92  
  * @author Dick Balaska
 93  
  * @since 2009/01/06
 94  
  * @version $Revision$ <br> $Date$
 95  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/board/MatchStatusPanel.java">cvs MatchStatusPanel.java</a>
 96  
  */
 97  
 public class MatchStatusPanel extends JPanel {
 98  
         private static final long serialVersionUID = 1L;
 99  
 
 100  0
         private        Document        document = null;
 101  0
         private        Board        board = null;  //  @jve:decl-index=0:
 102  
 
 103  0
         private JLabel player0Name = null;
 104  0
         private JLabel player1Name = null;
 105  
 
 106  0
         private JLabel player0MatchScore = null;
 107  0
         private JLabel player1MatchScore = null;
 108  
 
 109  0
         private JLabel player0PipCount = null;
 110  0
         private JLabel player1PipCount = null;
 111  
 
 112  0
         private JLabel pipDifference = null;
 113  
 
 114  0
         private JLabel matchLength = null;
 115  
 
 116  0
         private JLabel jLabelBuckoFIBS = null;
 117  
 
 118  
         private        MainDialog        mainDialog;
 119  
 
 120  0
         private JLabel player1Rating = null;
 121  
 
 122  0
         private JLabel player0Rating = null;
 123  
 
 124  
         /** Crate and initialize a MatchStatusPanel         */
 125  
         public MatchStatusPanel() {
 126  0
                 super();
 127  0
                 initialize();
 128  0
         }
 129  
 
 130  
         /** Set the reference to the document
 131  
          * @param document The BuckoFIBS document
 132  
          */
 133  
         public void setDocument(Document document) {
 134  0
                 this.document = document;
 135  0
         }
 136  
         /** Set the reference to our Board
 137  
          * @param board Reference to the board to display info about
 138  
          */
 139  
         public void setBoard(Board board) {
 140  0
                 this.board = board;
 141  0
                 updateStatus();
 142  0
         }
 143  
 
 144  
         /** Set the reference to the MainDialog
 145  
          * @param mainDialog The MainDialog
 146  
          */
 147  
         public void setMainDialog(MainDialog mainDialog) {
 148  0
                 this.mainDialog = mainDialog;
 149  0
         }
 150  
 
 151  
         /** Update the widgets based on changes to the board
 152  
          */
 153  
         public void updateStatus() {
 154  0
                 if (board != null) {
 155  
 
 156  0
                         String pn0 = board.getPlayerName()[0];
 157  0
                         String pn1 = board.getPlayerName()[1];
 158  
                         try {
 159  0
                                 Player p = mainDialog.getPlayerTableModel().getPlayer(pn1);
 160  0
                                 if (p != null)
 161  0
                                         player1Rating.setText("" + p.getRating());
 162  0
                                 if (board.isYouPlaying())
 163  0
                                         p = mainDialog.getPlayerTableModel().getPlayer(document.getName());
 164  
                                 else
 165  0
                                         p = mainDialog.getPlayerTableModel().getPlayer(pn0);
 166  0
                                 if (p != null)
 167  0
                                         player0Rating.setText("" + p.getRating());
 168  
                                 
 169  0
                         } catch (Exception e) {
 170  0
                                 e.printStackTrace();
 171  0
                         }
 172  0
                         player0Name.setText(pn0);
 173  0
                         player1Name.setText(pn1);
 174  0
                         this.matchLength.setText("ML: " + board.getMatchLength());
 175  0
                         this.player0MatchScore.setText("" + board.getMatchScore()[0]);
 176  0
                         this.player1MatchScore.setText("" + board.getMatchScore()[1]);
 177  0
                         Color player0Color = Color.white;
 178  0
                         Color player1Color = Color.white;
 179  0
                         if (board.getWhosTurn()*board.getXO() == 1)
 180  0
                                 player0Color = Color.yellow;
 181  0
                         else if (board.getWhosTurn()*board.getXO() == -1)
 182  0
                                 player1Color = Color.yellow;
 183  0
                         player0Name.setForeground(player0Color);
 184  0
                         player0Rating.setForeground(player0Color);
 185  0
                         player1Name.setForeground(player1Color);
 186  0
                         player1Rating.setForeground(player1Color);
 187  
                         
 188  0
                         int pp[] = board.getPipCount();
 189  0
                         this.player0PipCount.setText("" + pp[0]);
 190  0
                         this.player1PipCount.setText("" + pp[1]);
 191  0
                         int diff = pp[1] - pp[0];
 192  0
                         Color c = Color.yellow;
 193  0
                         if (diff > 0)
 194  0
                                 c = Color.green;
 195  0
                         if (diff < 0)
 196  0
                                 c = Color.red;
 197  0
                         this.pipDifference.setText("" + diff);
 198  0
                         this.pipDifference.setForeground(c);
 199  
                 }
 200  0
         }
 201  
 
 202  
         /**
 203  
          * This method initializes this
 204  
          * 
 205  
          */
 206  
         private void initialize() {
 207  0
         GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
 208  0
         gridBagConstraints41.gridx = 1;
 209  0
         gridBagConstraints41.anchor = GridBagConstraints.WEST;
 210  0
         gridBagConstraints41.weightx = 0.3;
 211  0
         gridBagConstraints41.gridy = 1;
 212  0
         player0Rating = new JLabel();
 213  0
         player0Rating.setText("????.??");
 214  0
         player0Rating.setFont(new Font("Dialog", Font.BOLD, 10));
 215  0
         player0Rating.setHorizontalTextPosition(SwingConstants.LEFT);
 216  0
         player0Rating.setForeground(Color.white);
 217  0
         GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
 218  0
         gridBagConstraints31.gridx = 1;
 219  0
         gridBagConstraints31.anchor = GridBagConstraints.WEST;
 220  0
         gridBagConstraints31.weightx = 0.3;
 221  0
         gridBagConstraints31.gridy = 0;
 222  0
         player1Rating = new JLabel();
 223  0
         player1Rating.setText("????.??");
 224  0
         player1Rating.setFont(new Font("Dialog", Font.BOLD, 10));
 225  0
         player1Rating.setForeground(Color.white);
 226  0
         player1Rating.setHorizontalTextPosition(SwingConstants.LEFT);
 227  0
         GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
 228  0
         gridBagConstraints8.gridx = 6;
 229  0
         gridBagConstraints8.gridy = 1;
 230  0
         jLabelBuckoFIBS = new JLabel();
 231  0
         jLabelBuckoFIBS.setText("BuckoFIBS");
 232  0
         jLabelBuckoFIBS.setFont(new Font("Dialog", Font.ITALIC, 10));
 233  0
         jLabelBuckoFIBS.setForeground(Color.green);
 234  0
         GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
 235  0
         gridBagConstraints7.gridx = 6;
 236  0
         gridBagConstraints7.anchor = GridBagConstraints.EAST;
 237  0
         gridBagConstraints7.gridy = 0;
 238  0
         matchLength = new JLabel();
 239  0
         matchLength.setText("ML: 0");
 240  0
         matchLength.setForeground(Color.white);
 241  0
         GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
 242  0
         gridBagConstraints6.gridx = 5;
 243  0
         gridBagConstraints6.gridheight = 2;
 244  0
         gridBagConstraints6.weightx = 4.0;
 245  0
         gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL;
 246  0
         gridBagConstraints6.anchor = GridBagConstraints.WEST;
 247  0
         gridBagConstraints6.insets = new Insets(0, 10, 0, 0);
 248  0
         gridBagConstraints6.gridy = 0;
 249  0
         pipDifference = new JLabel();
 250  0
         pipDifference.setText("0");
 251  0
         pipDifference.setForeground(Color.yellow);
 252  0
         GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
 253  0
         gridBagConstraints5.gridx = 4;
 254  0
         gridBagConstraints5.anchor = GridBagConstraints.EAST;
 255  0
         gridBagConstraints5.weightx = 1.0;
 256  0
         gridBagConstraints5.gridy = 0;
 257  0
         player1PipCount = new JLabel();
 258  0
         player1PipCount.setText("0");
 259  0
         player1PipCount.setForeground(Color.white);
 260  0
         GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
 261  0
         gridBagConstraints4.gridx = 4;
 262  0
         gridBagConstraints4.weightx = 1.0;
 263  0
         gridBagConstraints4.anchor = GridBagConstraints.EAST;
 264  0
         gridBagConstraints4.gridy = 1;
 265  0
         player0PipCount = new JLabel();
 266  0
         player0PipCount.setText("0");
 267  0
         player0PipCount.setForeground(Color.white);
 268  0
         GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
 269  0
         gridBagConstraints3.gridx = 2;
 270  0
         gridBagConstraints3.weightx = 1.0;
 271  0
         gridBagConstraints3.anchor = GridBagConstraints.WEST;
 272  0
         gridBagConstraints3.gridy = 0;
 273  0
         player1MatchScore = new JLabel();
 274  0
         player1MatchScore.setText("0");
 275  0
         player1MatchScore.setForeground(Color.white);
 276  0
         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
 277  0
         gridBagConstraints2.gridx = 2;
 278  0
         gridBagConstraints2.weightx = 1.0;
 279  0
         gridBagConstraints2.anchor = GridBagConstraints.WEST;
 280  0
         gridBagConstraints2.insets = new Insets(0, 0, 0, 0);
 281  0
         gridBagConstraints2.gridy = 1;
 282  0
         player0MatchScore = new JLabel();
 283  0
         player0MatchScore.setText("0");
 284  0
         player0MatchScore.setForeground(Color.white);
 285  0
         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
 286  0
         gridBagConstraints1.insets = new Insets(1, 1, 1, 1);
 287  0
         gridBagConstraints1.gridy = 1;
 288  0
         gridBagConstraints1.anchor = GridBagConstraints.WEST;
 289  0
         gridBagConstraints1.weightx = 0.2;
 290  0
         gridBagConstraints1.gridx = 0;
 291  0
         GridBagConstraints gridBagConstraints = new GridBagConstraints();
 292  0
         gridBagConstraints.insets = new Insets(1, 1, 1, 1);
 293  0
         gridBagConstraints.gridy = 0;
 294  0
         gridBagConstraints.anchor = GridBagConstraints.WEST;
 295  0
         gridBagConstraints.fill = GridBagConstraints.NONE;
 296  0
         gridBagConstraints.weightx = 0.2;
 297  0
         gridBagConstraints.weighty = 0.9;
 298  0
         gridBagConstraints.gridx = 0;
 299  0
         this.setLayout(new GridBagLayout());
 300  0
         this.setBackground(Color.darkGray);
 301  0
         this.setSize(new Dimension(450, 32));
 302  0
         this.setPreferredSize(new Dimension(450, 36));
 303  0
         this.setForeground(Color.white);
 304  0
         player1Name = new JLabel();
 305  0
         player1Name.setText("Player1");
 306  0
         player1Name.setForeground(Color.white);
 307  0
         player0Name = new JLabel();
 308  0
         player0Name.setText("Player0");
 309  0
         player0Name.setForeground(Color.white);
 310  0
         this.add(player0Name, gridBagConstraints1);
 311  0
         this.add(player1Name, gridBagConstraints);
 312  0
         this.add(player0MatchScore, gridBagConstraints2);
 313  0
         this.add(player1MatchScore, gridBagConstraints3);
 314  0
         this.add(player0PipCount, gridBagConstraints4);
 315  0
         this.add(player1PipCount, gridBagConstraints5);
 316  0
         this.add(pipDifference, gridBagConstraints6);
 317  0
         this.add(matchLength, gridBagConstraints7);
 318  0
         this.add(jLabelBuckoFIBS, gridBagConstraints8);
 319  0
         this.add(player1Rating, gridBagConstraints31);
 320  0
         this.add(player0Rating, gridBagConstraints41);
 321  0
         }
 322  
 }  //  @jve:decl-index=0:visual-constraint="10,10"