Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.RatingGraphPanelConfigureDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
RatingGraphPanelConfigureDialog
0%
0/168
0%
0/34
1.8
RatingGraphPanelConfigureDialog$1
0%
0/4
N/A
1.8
RatingGraphPanelConfigureDialog$2
0%
0/4
N/A
1.8
RatingGraphPanelConfigureDialog$3
0%
0/3
N/A
1.8
RatingGraphPanelConfigureDialog$4
0%
0/2
N/A
1.8
RatingGraphPanelConfigureDialog$5
0%
0/3
N/A
1.8
RatingGraphPanelConfigureDialog$6
0%
0/3
N/A
1.8
RatingGraphPanelConfigureDialog$7
0%
0/3
N/A
1.8
 
 1  
 /******************************************************************************
 2  
  * RatingGraphPanelConfigure.java - 
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.4  2011/01/01 06:10:51  dick
 10  
  * Javadoc.
 11  
  *
 12  
  * Revision 1.3  2010/03/03 13:12:21  inim
 13  
  * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
 14  
  *
 15  
  * Revision 1.2  2010/03/03 12:19:49  inim
 16  
  * 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.
 17  
  *
 18  
  * Revision 1.1  2010/02/04 05:57:53  inim
 19  
  * Mavenized project folder layout
 20  
  *
 21  
  * Revision 1.2  2010/01/29 23:38:35  dick
 22  
  * Javadoc.
 23  
  *
 24  
  * Revision 1.1  2010/01/29 23:07:35  dick
 25  
  * RatingGraphPanelConfigure becomes RatingGraphPanelConfigureDialog.
 26  
  *
 27  
  * Revision 1.1  2010/01/27 02:11:10  dick
 28  
  * Empty RatingGraphPanelConfigure.
 29  
  *
 30  
  */
 31  
 
 32  
 /* 
 33  
  * This program is free software: you can redistribute it and/or modify
 34  
  * it under the terms of the GNU General Public License as published by
 35  
  * the Free Software Foundation, either version 3 of the License, or
 36  
  * (at your option) any later version.
 37  
  *
 38  
  * This program is distributed in the hope that it will be useful,
 39  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 40  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 41  
  * GNU General Public License for more details.
 42  
  *
 43  
  * You should have received a copy of the GNU General Public License
 44  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 45  
  *
 46  
  * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
 47  
  * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
 48  
  * 
 49  
  */
 50  
 package com.buckosoft.fibs.BuckoFIBS.gui;
 51  
 
 52  
 import java.awt.BorderLayout;
 53  
 import java.awt.Dimension;
 54  
 import java.awt.Frame;
 55  
 import java.awt.GridBagConstraints;
 56  
 import java.awt.GridBagLayout;
 57  
 import java.awt.Insets;
 58  
 
 59  
 import javax.swing.ButtonGroup;
 60  
 import javax.swing.JButton;
 61  
 import javax.swing.JDialog;
 62  
 import javax.swing.JFrame;
 63  
 import javax.swing.JPanel;
 64  
 import javax.swing.JRadioButton;
 65  
 import javax.swing.JTextField;
 66  
 import javax.swing.event.DocumentEvent;
 67  
 import javax.swing.event.DocumentListener;
 68  
 
 69  
 import com.buckosoft.fibs.BuckoFIBS.BFProperties;
 70  
 import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher;
 71  
 import com.buckosoft.fibs.domain.config.RatingGraphConfig;
 72  
 
 73  
 /**
 74  
  * @author dick
 75  
  * @since Jan 26, 2010
 76  
  * @see 
 77  
  */
 78  
 /** Configure the Rating Graph Panel
 79  
  * @author Dick Balaska
 80  
  * @since 2010/01/26
 81  
  * @version $Revision$ <br> $Date$
 82  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/RatingGraphPanelConfigureDialog.java">cvs RatingGraphPanelConfigureDialog.java</a>
 83  
  */
 84  0
 public class RatingGraphPanelConfigureDialog extends JDialog implements DocumentListener {
 85  
         private        final static boolean DEBUG = false;
 86  
         private        CommandDispatcher        commandDispatcher;
 87  
         private        BFProperties                properties;
 88  
 
 89  
         private static final long serialVersionUID = 1L;
 90  0
         private JPanel jContentPane = null;
 91  0
         private JPanel jPanelGraphType = null;
 92  0
         private JRadioButton jRadioButtonAllMatches = null;
 93  0
         private JRadioButton jRadioButtonLastXMatches = null;
 94  0
         private JTextField jTextFieldNumberOfMatches = null;
 95  0
         private JRadioButton jRadioButtonFromDate = null;
 96  0
         private JPanel jPanelOKCancel = null;
 97  0
         private JButton jButtonOK = null;
 98  0
         private JButton jButtonCancel = null;
 99  
         private        RatingGraphConfig ratingGraphConfig;
 100  
         
 101  
         /**
 102  
          * @param owner
 103  
          */
 104  
         public RatingGraphPanelConfigureDialog(Frame owner) {
 105  0
                 super(owner);
 106  0
                 initialize();
 107  0
         }
 108  
 
 109  
         /** Create and display the RatingGraphConfigure dialog.
 110  
          * Just set and forget.  It's modal and manages ok and cancel on its own.
 111  
          * @param owner Probably an instance of MainDialog
 112  
          * @param commandDispatcher The BuckoFIBS commandDispatcher
 113  
          */
 114  
         public RatingGraphPanelConfigureDialog(JFrame owner, CommandDispatcher commandDispatcher) {
 115  0
                 super(owner, true);
 116  0
                 this.commandDispatcher = commandDispatcher;
 117  0
                 this.properties = commandDispatcher.getProperties();
 118  0
                 initialize();
 119  0
                 this.setLocationRelativeTo(owner);
 120  
 
 121  0
                 BFProperties props = this.commandDispatcher.getProperties();
 122  0
                 ratingGraphConfig = props.getRatingGraphConfig().clone();
 123  0
                 switch (ratingGraphConfig.getTypeAsInt()) {
 124  
                 case 0:
 125  0
                         this.jRadioButtonAllMatches.getModel().setSelected(true);
 126  0
                         break;
 127  
                 case 1:
 128  0
                         this.jRadioButtonLastXMatches.getModel().setSelected(true);
 129  0
                         break;
 130  
                 case 2:
 131  0
                         this.jRadioButtonFromDate.getModel().setSelected(true);
 132  
                         break;
 133  
                 }
 134  0
                 this.jTextFieldNumberOfMatches.setText("" + props.getRatingGraphConfig().getMatchCount());
 135  0
                 this.jTextFieldNumberOfMatches.setEnabled(ratingGraphConfig.getType() == RatingGraphConfig.Type.displayLastXMatches);
 136  0
         }
 137  
 
 138  
         /** This method initializes this
 139  
          * @return void
 140  
          */
 141  
         private void initialize() {
 142  0
                 this.setSize(300, 200);
 143  0
                 this.setTitle("Configure the Rating Graph");
 144  0
                 this.setContentPane(getJContentPane());
 145  0
         }
 146  
 
 147  
         private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
 148  0
                 setVisible(false);
 149  0
                 RatingGraphConfig rgc = this.commandDispatcher.getProperties().getRatingGraphConfig();
 150  0
                 if (this.jRadioButtonAllMatches.getModel().isSelected())
 151  0
                         rgc.setTypeAsInt(0);
 152  0
                 if (this.jRadioButtonLastXMatches.getModel().isSelected())
 153  0
                         rgc.setTypeAsInt(1);
 154  0
                 if (this.jRadioButtonFromDate.getModel().isSelected())
 155  0
                         rgc.setTypeAsInt(2);
 156  
 
 157  0
                 int i = -1;
 158  
                 try {
 159  0
                         i = Integer.parseInt(this.jTextFieldNumberOfMatches.getText());
 160  0
                 } catch (NumberFormatException e) {
 161  0
                         i = -1;
 162  0
                 }
 163  0
                 if (i < 1)
 164  0
                         i = 1;
 165  0
                 rgc.setMatchCount(i);
 166  0
                 this.properties.setRatingGraphConfig(rgc);
 167  0
                 dispose();
 168  0
         }
 169  
 
 170  
         private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
 171  0
                 setVisible(false);
 172  0
                 dispose();
 173  0
         }
 174  
 
 175  
         /** This method initializes jContentPane
 176  
          * 
 177  
          * @return javax.swing.JPanel
 178  
          */
 179  
         private JPanel getJContentPane() {
 180  0
                 if (jContentPane == null) {
 181  0
                         BorderLayout borderLayout = new BorderLayout();
 182  0
                         borderLayout.setHgap(15);
 183  0
                         borderLayout.setVgap(11);
 184  0
                         jContentPane = new JPanel();
 185  0
                         jContentPane.setLayout(borderLayout);
 186  0
                         jContentPane.add(getJPanelGraphType(), BorderLayout.CENTER);
 187  0
                         jContentPane.add(getJPanelOKCancel(), BorderLayout.SOUTH);
 188  
                 }
 189  0
                 return jContentPane;
 190  
         }
 191  
 
 192  
         /** This method initializes jPanelGraphType        
 193  
          *         
 194  
          * @return javax.swing.JPanel        
 195  
          */
 196  
         private JPanel getJPanelGraphType() {
 197  0
                 if (jPanelGraphType == null) {
 198  0
                         GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
 199  0
                         gridBagConstraints4.gridx = 0;
 200  0
                         gridBagConstraints4.gridy = 4;
 201  0
                         GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
 202  0
                         gridBagConstraints3.gridx = 0;
 203  0
                         gridBagConstraints3.anchor = GridBagConstraints.WEST;
 204  0
                         gridBagConstraints3.gridy = 3;
 205  0
                         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
 206  0
                         gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
 207  0
                         gridBagConstraints2.gridy = 2;
 208  0
                         gridBagConstraints2.weightx = 1.0;
 209  0
                         gridBagConstraints2.anchor = GridBagConstraints.WEST;
 210  0
                         gridBagConstraints2.ipadx = 0;
 211  0
                         gridBagConstraints2.insets = new Insets(0, 22, 0, 0);
 212  0
                         gridBagConstraints2.gridx = 0;
 213  0
                         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
 214  0
                         gridBagConstraints1.gridx = 0;
 215  0
                         gridBagConstraints1.anchor = GridBagConstraints.WEST;
 216  0
                         gridBagConstraints1.gridy = 1;
 217  0
                         GridBagConstraints gridBagConstraints = new GridBagConstraints();
 218  0
                         gridBagConstraints.gridx = 0;
 219  0
                         gridBagConstraints.anchor = GridBagConstraints.WEST;
 220  0
                         gridBagConstraints.gridy = 0;
 221  0
                         jPanelGraphType = new JPanel();
 222  0
                         jPanelGraphType.setLayout(new GridBagLayout());
 223  0
                         jPanelGraphType.add(getJRadioButtonAllMatches(), gridBagConstraints);
 224  0
                         jPanelGraphType.add(getJRadioButtonLastXMatches(), gridBagConstraints1);
 225  0
                         jPanelGraphType.add(getJTextFieldNumberOfMatches(), gridBagConstraints2);
 226  0
                         jPanelGraphType.add(getJRadioButtonFromDate(), gridBagConstraints3);
 227  0
                         ButtonGroup group = new ButtonGroup();
 228  0
                     group.add(getJRadioButtonAllMatches());
 229  0
                     group.add(getJRadioButtonLastXMatches());
 230  0
                     group.add(getJRadioButtonFromDate());
 231  
                 }
 232  0
                 return jPanelGraphType;
 233  
         }
 234  
 
 235  
         /** This method initializes jRadioButtonAllMatches        
 236  
          *         
 237  
          * @return javax.swing.JRadioButton        
 238  
          */
 239  
         private JRadioButton getJRadioButtonAllMatches() {
 240  0
                 if (jRadioButtonAllMatches == null) {
 241  0
                         jRadioButtonAllMatches = new JRadioButton();
 242  0
                         jRadioButtonAllMatches.setText("All Matches");
 243  0
                         jRadioButtonAllMatches.addActionListener(new java.awt.event.ActionListener() {
 244  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 245  0
                                         ratingGraphConfig.setType(RatingGraphConfig.Type.displayAllMatches);
 246  0
                                         commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig);
 247  0
                                 }
 248  
                         });
 249  
                 }
 250  0
                 return jRadioButtonAllMatches;
 251  
         }
 252  
 
 253  
         /** This method initializes jRadioButtonLastXMatches        
 254  
          *         
 255  
          * @return javax.swing.JRadioButton        
 256  
          */
 257  
         private JRadioButton getJRadioButtonLastXMatches() {
 258  0
                 if (jRadioButtonLastXMatches == null) {
 259  0
                         jRadioButtonLastXMatches = new JRadioButton();
 260  0
                         jRadioButtonLastXMatches.setText("Last X Matches");
 261  0
                         jRadioButtonLastXMatches.addActionListener(new java.awt.event.ActionListener() {
 262  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 263  0
                                         ratingGraphConfig.setType(RatingGraphConfig.Type.displayLastXMatches);
 264  0
                                         commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig);
 265  0
                                 }
 266  
                         });
 267  0
                         jRadioButtonLastXMatches
 268  0
                                         .addChangeListener(new javax.swing.event.ChangeListener() {
 269  
                                                 public void stateChanged(javax.swing.event.ChangeEvent e) {
 270  0
                                                         getJTextFieldNumberOfMatches().setEnabled(jRadioButtonLastXMatches.getModel().isSelected());
 271  0
                                                 }
 272  
                                         });
 273  
                 }
 274  0
                 return jRadioButtonLastXMatches;
 275  
         }
 276  
 
 277  
         /** This method initializes jTextFieldNumberOfMatches        
 278  
          *         
 279  
          * @return javax.swing.JTextField        
 280  
          */
 281  
         private JTextField getJTextFieldNumberOfMatches() {
 282  0
                 if (jTextFieldNumberOfMatches == null) {
 283  0
                         jTextFieldNumberOfMatches = new JTextField();
 284  0
                         jTextFieldNumberOfMatches.setPreferredSize(new Dimension(60, 20));
 285  0
                         jTextFieldNumberOfMatches.addKeyListener(new java.awt.event.KeyAdapter() {
 286  
                                 public void keyTyped(java.awt.event.KeyEvent e) {
 287  
                                         
 288  0
                                 }
 289  
                         });
 290  0
                         jTextFieldNumberOfMatches.getDocument().addDocumentListener(this);
 291  
                 }
 292  0
                 return jTextFieldNumberOfMatches;
 293  
         }
 294  
 
 295  
         /* (non-Javadoc)
 296  
          * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
 297  
          */
 298  
         @Override
 299  
         public void changedUpdate(DocumentEvent arg0) {
 300  0
                 updateFromTextChanged(arg0);
 301  
                 
 302  0
         }
 303  
 
 304  
         /* (non-Javadoc)
 305  
          * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
 306  
          */
 307  
         @Override
 308  
         public void insertUpdate(DocumentEvent arg0) {
 309  0
                 updateFromTextChanged(arg0);
 310  0
         }
 311  
 
 312  
         /* (non-Javadoc)
 313  
          * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
 314  
          */
 315  
         @Override
 316  
         public void removeUpdate(DocumentEvent arg0) {
 317  0
                 updateFromTextChanged(arg0);
 318  0
         }
 319  
 
 320  
         private void updateFromTextChanged(DocumentEvent documentEvent) {
 321  0
                 int i = -1;
 322  
                 try {
 323  0
                         i = Integer.parseInt(jTextFieldNumberOfMatches.getText());
 324  0
                 } catch (NumberFormatException e1) {
 325  0
                         i = -1;
 326  0
                 }
 327  0
                 if (i < 1)
 328  0
                         i = 1;
 329  
                 if (DEBUG)
 330  
                         System.out.println("docChanged(" + i + ")");
 331  0
                 ratingGraphConfig.setMatchCount(i);
 332  0
                 commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig);
 333  
 
 334  0
         }
 335  
 
 336  
         /**
 337  
          * This method initializes jRadioButtonFromDate        
 338  
          *         
 339  
          * @return javax.swing.JRadioButton        
 340  
          */
 341  
         private JRadioButton getJRadioButtonFromDate() {
 342  0
                 if (jRadioButtonFromDate == null) {
 343  0
                         jRadioButtonFromDate = new JRadioButton();
 344  0
                         jRadioButtonFromDate.setText("From Date");
 345  0
                         jRadioButtonFromDate.setEnabled(false);
 346  0
                         jRadioButtonFromDate.addActionListener(new java.awt.event.ActionListener() {
 347  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 348  0
                                         System.out.println("actionPerformed()"); // TODO Date does nothing.
 349  0
                                 }
 350  
                         });
 351  
                 }
 352  0
                 return jRadioButtonFromDate;
 353  
         }
 354  
 
 355  
         /**
 356  
          * This method initializes jPanelOKCancel        
 357  
          *         
 358  
          * @return javax.swing.JPanel        
 359  
          */
 360  
         private JPanel getJPanelOKCancel() {
 361  0
                 if (jPanelOKCancel == null) {
 362  0
                         GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
 363  0
                         gridBagConstraints6.gridx = 1;
 364  0
                         gridBagConstraints6.anchor = GridBagConstraints.EAST;
 365  0
                         gridBagConstraints6.insets = new Insets(0, 30, 0, 0);
 366  0
                         gridBagConstraints6.gridy = 5;
 367  0
                         GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
 368  0
                         gridBagConstraints5.gridx = 0;
 369  0
                         gridBagConstraints5.weighty = 0.5;
 370  0
                         gridBagConstraints5.fill = GridBagConstraints.BOTH;
 371  0
                         gridBagConstraints5.anchor = GridBagConstraints.CENTER;
 372  0
                         gridBagConstraints5.insets = new Insets(0, 0, 0, 20);
 373  0
                         gridBagConstraints5.weightx = 0.0;
 374  0
                         gridBagConstraints5.gridy = 5;
 375  0
                         jPanelOKCancel = new JPanel();
 376  0
                         jPanelOKCancel.setLayout(new GridBagLayout());
 377  0
                         jPanelOKCancel.add(getJButtonOK(), gridBagConstraints5);
 378  0
                         jPanelOKCancel.add(getJButtonCancel(), gridBagConstraints6);
 379  
                 }
 380  0
                 return jPanelOKCancel;
 381  
         }
 382  
 
 383  
         /**
 384  
          * This method initializes jButtonOK        
 385  
          *         
 386  
          * @return javax.swing.JButton        
 387  
          */
 388  
         private JButton getJButtonOK() {
 389  0
                 if (jButtonOK == null) {
 390  0
                         jButtonOK = new JButton();
 391  0
                         jButtonOK.setText("OK");
 392  0
                         jButtonOK.addActionListener(new java.awt.event.ActionListener() {
 393  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 394  0
                                         okButtonActionPerformed(e);
 395  0
                                 }
 396  
                         });
 397  
                 }
 398  0
                 return jButtonOK;
 399  
         }
 400  
 
 401  
         /**
 402  
          * This method initializes jButtonCancel        
 403  
          *         
 404  
          * @return javax.swing.JButton        
 405  
          */
 406  
         private JButton getJButtonCancel() {
 407  0
                 if (jButtonCancel == null) {
 408  0
                         jButtonCancel = new JButton();
 409  0
                         jButtonCancel.setText("Cancel");
 410  0
                         jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
 411  
                                 public void actionPerformed(java.awt.event.ActionEvent e) {
 412  0
                                         cancelButtonActionPerformed(e);
 413  0
                                 }
 414  
                         });
 415  
                 }
 416  0
                 return jButtonCancel;
 417  
         }
 418  
 
 419  
 }  //  @jve:decl-index=0:visual-constraint="13,8"