Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.inviterList.InviterListPane
 
Classes in this File Line Coverage Branch Coverage Complexity
InviterListPane
0%
0/58
0%
0/14
2.077
InviterListPane$1
0%
0/3
N/A
2.077
InviterListPane$PopupListener
0%
0/12
0%
0/4
2.077
 
 1  
 /******************************************************************************
 2  
  * InviterListPane.java - Display the List of inviters
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.2  2010/03/03 12:19:49  inim
 10  
  * 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.
 11  
  *
 12  
  * Revision 1.1  2010/02/04 05:57:53  inim
 13  
  * Mavenized project folder layout
 14  
  *
 15  
  * Revision 1.5  2009/03/12 16:35:45  dick
 16  
  * Fire the GET_PLAYER_REPORT event if double-click a player.
 17  
  *
 18  
  * Revision 1.4  2009/02/17 14:44:40  dick
 19  
  * Turn off DEBUG.
 20  
  *
 21  
  * Revision 1.3  2009/02/14 15:39:40  dick
 22  
  * BuckoFIBS is released under the GNU license.
 23  
  * Javadoc.
 24  
  *
 25  
  * Revision 1.2  2009/02/01 09:02:03  dick
 26  
  * PlayerNameRenderer becomes InviterNameRenderer in this package.
 27  
  *
 28  
  * Revision 1.1  2009/01/28 19:39:15  dick
 29  
  * package com.buckosoft.fibs.gui.inviterList becomes com.buckosoft.fibs.BuckoFIBS.gui.inviterList.
 30  
  *
 31  
  * Revision 1.4  2009/01/27 19:16:16  dick
 32  
  * playerName gets a custom renderer so we can display warnings.
 33  
  *
 34  
  * Revision 1.3  2008/12/11 20:29:26  dick
 35  
  * Context menu functional.
 36  
  *
 37  
  * Revision 1.2  2008/12/09 19:39:18  dick
 38  
  * Use the InviterTableModel, not a PlayerTableModel.
 39  
  */
 40  
 
 41  
 /* 
 42  
  * This program is free software: you can redistribute it and/or modify
 43  
  * it under the terms of the GNU General Public License as published by
 44  
  * the Free Software Foundation, either version 3 of the License, or
 45  
  * (at your option) any later version.
 46  
  *
 47  
  * This program is distributed in the hope that it will be useful,
 48  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 49  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 50  
  * GNU General Public License for more details.
 51  
  *
 52  
  * You should have received a copy of the GNU General Public License
 53  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 54  
  *
 55  
  * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
 56  
  * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
 57  
  * 
 58  
  */
 59  
 package com.buckosoft.fibs.BuckoFIBS.gui.inviterList;
 60  
 
 61  
 import java.awt.GridBagConstraints;
 62  
 import java.awt.GridBagLayout;
 63  
 import java.awt.Point;
 64  
 import java.awt.event.ActionEvent;
 65  
 import java.awt.event.ActionListener;
 66  
 import java.awt.event.MouseAdapter;
 67  
 import java.awt.event.MouseEvent;
 68  
 import java.awt.event.MouseListener;
 69  
 
 70  
 import javax.swing.JPanel;
 71  
 import javax.swing.JScrollPane;
 72  
 import javax.swing.JTable;
 73  
 import javax.swing.ListSelectionModel;
 74  
 
 75  
 import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher;
 76  
 import com.buckosoft.fibs.domain.Player;
 77  
 
 78  
 /** Display the list of Inviters
 79  
  * @author Dick Balaska
 80  
  * @since 2008/12/08
 81  
  * @version $Revision$ <br> $Date$
 82  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/inviterList/InviterListPane.java">cvs InviterListPane.java</a>
 83  
  */
 84  0
 public class InviterListPane extends JPanel  implements ActionListener{
 85  
         private        final static boolean DEBUG = false;
 86  
         private static final long serialVersionUID = 1L;
 87  0
         private JScrollPane                        inviterListScrollPane = null;
 88  0
         private JTable                                inviterListTable = null;
 89  
         private        InviterTableModel         inviterTableModel;
 90  0
         private        CommandDispatcher        commandDispatcher = null;
 91  0
         private        InviterListPopupMenu inviterListPopupMenu = null;
 92  
 
 93  
 
 94  
         /** This is the default constructor
 95  
          */
 96  
         public InviterListPane() {
 97  0
                 super();
 98  0
                 initialize();
 99  0
         }
 100  
 
 101  
         /** This method initializes this
 102  
          */
 103  
         private void initialize() {
 104  0
                 getInviterListPopupMenu();
 105  0
                 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
 106  0
                 gridBagConstraints1.fill = GridBagConstraints.BOTH;
 107  0
                 gridBagConstraints1.gridy = 1;
 108  0
                 gridBagConstraints1.weightx = 1.0;
 109  0
                 gridBagConstraints1.weighty = 1.0;
 110  0
                 gridBagConstraints1.gridx = 0;
 111  0
                 this.setSize(300, 200);
 112  0
                 this.setLayout(new GridBagLayout());
 113  0
                 this.add(getInviterListScrollPane(), gridBagConstraints1);
 114  
 
 115  0
         }
 116  
 
 117  
         /** Return a reference to our tableModel
 118  
          * @return The InviterTableModel
 119  
          */
 120  
         public InviterTableModel getInviterTableModel() {
 121  0
                 return(inviterTableModel);
 122  
         }
 123  
 
 124  
         /** Set the reference to the CommandDispatcher
 125  
          * @param commandDispatcher The application CommandDispatcher
 126  
          */
 127  
         public void setCommandDispatcher(CommandDispatcher commandDispatcher) {
 128  0
                 this.commandDispatcher = commandDispatcher;
 129  0
         }
 130  
 
 131  
         /** Called directly from the menu.
 132  
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 133  
          */
 134  
         public void actionPerformed(ActionEvent e) {
 135  0
                 Player p =        (Player)inviterListTable.getModel().getValueAt(inviterListTable.getSelectedRow(), 0);
 136  0
                 String playerName = p.getName();
 137  
                 if (DEBUG)
 138  
                         System.out.println("Action performed: " + e.getActionCommand() + " on " + playerName);
 139  0
                 if (e.getActionCommand() == "Accept") {
 140  0
                         this.commandDispatcher.dispatch(CommandDispatcher.Command.ACCEPT_INVITATION, playerName);
 141  
                 } else {
 142  0
                         System.out.println("Unhandled Action: " + e.getActionCommand() + " on " + playerName);                        
 143  
                 }
 144  0
         }
 145  
 
 146  
         private        void        onMousePressed(MouseEvent e) {
 147  0
                 if (e.getButton() != MouseEvent.BUTTON1)
 148  0
                         return;
 149  0
                 if (e.getClickCount() != 2)
 150  0
                         return;
 151  0
                 Player p = (Player)inviterListTable.getModel().getValueAt(inviterListTable.convertRowIndexToModel(inviterListTable.getSelectedRow()), 0);
 152  0
                 if (p == null)
 153  0
                         return;
 154  0
                 String playerName = p.getName();
 155  
                 if (DEBUG)
 156  
                         System.out.println("dblclick performed: on " + playerName);
 157  0
                 this.commandDispatcher.dispatch(CommandDispatcher.Command.GET_PLAYER_REPORT, playerName);
 158  0
         }
 159  
         /**
 160  
          * This method initializes playerListScrollPane        
 161  
          *         
 162  
          * @return javax.swing.JScrollPane        
 163  
          */
 164  
         private JScrollPane getInviterListScrollPane() {
 165  0
                 if (inviterListScrollPane == null) {
 166  0
                         inviterListScrollPane = new JScrollPane();
 167  0
                         inviterListScrollPane.setViewportView(getInviterListTable());
 168  
 
 169  
                 }
 170  0
                 return inviterListScrollPane;
 171  
         }
 172  
         /** This method initializes playerListTable        
 173  
          * @return javax.swing.JTable        
 174  
          */
 175  
         private JTable getInviterListTable() {
 176  0
                 if (inviterListTable == null) {
 177  0
                         inviterTableModel = new InviterTableModel();
 178  0
                         inviterListTable = new JTable(inviterTableModel);
 179  0
                         inviterListTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 180  0
                         InviterNameRenderer playerRenderer = new InviterNameRenderer();
 181  0
                         inviterListTable.setDefaultRenderer(com.buckosoft.fibs.domain.Player.class, playerRenderer);
 182  0
                         playerRenderer.setBackground(inviterListTable.getBackground());
 183  0
                         playerRenderer.setSelectedBackground(inviterListTable.getSelectionBackground());
 184  
                         //Add listener to components that can bring up popup menus.
 185  0
                         MouseListener popupListener = new PopupListener();
 186  0
                         inviterListTable.addMouseListener(popupListener);
 187  
 
 188  0
                         inviterListTable.addMouseListener(new java.awt.event.MouseAdapter() {   
 189  
                                 public void mousePressed(java.awt.event.MouseEvent e) {    
 190  0
                                         onMousePressed(e);
 191  0
                                 }
 192  
                         });
 193  
                 }
 194  0
                 return inviterListTable;
 195  
         }
 196  
 
 197  
         private        InviterListPopupMenu getInviterListPopupMenu() { 
 198  0
                 if (inviterListPopupMenu == null) {
 199  0
                         inviterListPopupMenu = new InviterListPopupMenu();
 200  0
                         inviterListPopupMenu.setMenuHandler(this);
 201  
 
 202  
                 }
 203  0
                 return(inviterListPopupMenu);
 204  
         }
 205  
 
 206  0
         class PopupListener extends MouseAdapter {
 207  
                 public void mousePressed(MouseEvent e) {
 208  0
                         maybeShowPopup(e);
 209  0
                 }
 210  
 
 211  
                 public void mouseReleased(MouseEvent e) {
 212  0
                         maybeShowPopup(e);
 213  0
                 }
 214  
 
 215  
                 private void maybeShowPopup(MouseEvent e) {
 216  0
                         if (e.isPopupTrigger()) {
 217  0
                                 int row = inviterListTable.rowAtPoint(new Point(e.getX(), e.getY()));
 218  0
                                 if (row != -1)
 219  0
                                         inviterListTable.getSelectionModel().setSelectionInterval(row, row);
 220  
                                 //if (DEBUG)
 221  
                                 //        System.out.println("selected row = " + row);
 222  0
                                 inviterListPopupMenu.show(e.getComponent(),
 223  0
                                                 e.getX(), e.getY());
 224  
                         }
 225  0
                 }
 226  
         }
 227  
 }