Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.playerList.group.GroupPopupSubmenu
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupPopupSubmenu
0%
0/29
0%
0/4
1.667
GroupPopupSubmenu$PopupGroup
0%
0/1
N/A
1.667
 
 1  
 /******************************************************************************
 2  
  * GroupPopupSubmenu.java - The group submenu for putting a player in groups
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright© 2010 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.2  2011/01/01 06:22:09  dick
 10  
  * Javadoc.
 11  
  *
 12  
  * Revision 1.1  2011/01/01 00:17:56  dick
 13  
  * The group submenu for putting a player in groups
 14  
  *
 15  
  */
 16  
 
 17  
 /* 
 18  
  * This program is free software: you can redistribute it and/or modify
 19  
  * it under the terms of the GNU General Public License as published by
 20  
  * the Free Software Foundation, either version 3 of the License, or
 21  
  * (at your option) any later version.
 22  
  *
 23  
  * This program is distributed in the hope that it will be useful,
 24  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 25  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 26  
  * GNU General Public License for more details.
 27  
  *
 28  
  * You should have received a copy of the GNU General Public License
 29  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 30  
  *
 31  
  * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
 32  
  * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
 33  
  * 
 34  
  */
 35  
 package com.buckosoft.fibs.BuckoFIBS.gui.playerList.group;
 36  
 
 37  
 import java.awt.Dimension;
 38  
 import java.awt.event.ActionEvent;
 39  
 import java.awt.event.ActionListener;
 40  
 import java.util.LinkedList;
 41  
 
 42  
 import javax.swing.JCheckBoxMenuItem;
 43  
 import javax.swing.JMenu;
 44  
 
 45  
 import com.buckosoft.fibs.BuckoFIBS.GroupManager;
 46  
 import com.buckosoft.fibs.domain.Player;
 47  
 
 48  
 /** The group submenu for putting a player in groups
 49  
  * @author Dick Balaska
 50  
  * @since 2010/12/31
 51  
  * @version $Revision$ <br> $Date$
 52  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/playerList/group/GroupPopupSubmenu.java">cvs GroupPopupSubmenu.java</a>
 53  
  */
 54  
 public class GroupPopupSubmenu extends JMenu implements ActionListener {
 55  
         private        final static boolean DEBUG = false;
 56  
         private static final long serialVersionUID = 1L;
 57  
 
 58  
         private GroupManager groupManager;
 59  
         
 60  
         
 61  
         /** A small helper class that contains a group name and its selected status.
 62  
          * Used for building the GroupPopupSubmenu
 63  
          * @author Dick Balaska
 64  
          * @since 2010/12/31
 65  
          * @version $Revision$ <br> $Date$
 66  
          * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/playerList/group/GroupPopupSubmenu.java">cvs GroupPopupSubmenu.java</a>
 67  
          */
 68  0
         public class PopupGroup {
 69  
                 /** The name of the group to display */
 70  
                 public String name;
 71  
 
 72  
                 /** Draw this entry as selected */
 73  
                 public boolean selected;
 74  
         }
 75  
 
 76  
         /** Default constructor and initialize. 
 77  
          */
 78  
         public GroupPopupSubmenu() {
 79  0
                 super();
 80  0
                 initialize();
 81  0
         }
 82  
 
 83  
         /** Called when a menu entry from this menu is selected.
 84  
          * @param e What just happened?
 85  
          */
 86  
         public void actionPerformed(ActionEvent e) {
 87  
                 //this.groupManager.menuEvent(e);
 88  0
                 String s = e.getActionCommand();
 89  0
                 int i = s.indexOf('-');
 90  0
                 String gn = s.substring(0, i);
 91  0
                 String pn = s.substring(i+1);
 92  
                 if (DEBUG)
 93  
                         System.out.println("menu: '" + s + "' gn='" + gn + "' pn='" + pn + "'");
 94  0
                 this.groupManager.popupMenuItemSelected(gn, pn);
 95  0
         }
 96  
 
 97  
         /**
 98  
          * This method initializes this
 99  
          * 
 100  
          */
 101  
         private void initialize() {
 102  0
         this.setSize(new Dimension(73, 40));
 103  0
         this.setText("Groups");
 104  0
         }
 105  
 
 106  
         /**
 107  
          * @return the gameManager
 108  
          */
 109  
         public GroupManager getGroupManager() {
 110  0
                 return groupManager;
 111  
         }
 112  
 
 113  
         /** Set our reference to the object that will receive menu events
 114  
          * @param groupManager the groupManager to set
 115  
          */
 116  
         public void setGroupManager(GroupManager groupManager) {
 117  0
                 this.groupManager = groupManager;
 118  0
         }
 119  
         
 120  
         /** Empty and recreate the entries in the popup menu for this player.
 121  
          * @param player The player who we right-clicked on.
 122  
          */
 123  
         public void repopulate(Player player) {
 124  
                 if (DEBUG)
 125  
                         System.out.println("GroupPopupSubmenu: repopulate for player " + player.getId() + " '" + player.getName() + "'");
 126  0
                 this.removeAll();
 127  0
                 LinkedList<PopupGroup> lpg = this.groupManager.getGroupsForPlayer(this, player.getId());
 128  0
                 for (PopupGroup pg : lpg) {
 129  0
                         if (pg.name.equals("All"))
 130  0
                                 continue;
 131  0
                         JCheckBoxMenuItem mi  = new JCheckBoxMenuItem();
 132  0
                         mi.setText(pg.name);
 133  0
                         mi.setSelected(pg.selected);
 134  
                         //mi.setSelected(true);
 135  0
                         mi.setActionCommand(pg.name + "-" + player.getName());
 136  0
                         mi.setToolTipText("Add this player to this group.");
 137  0
                         mi.addActionListener(this);
 138  0
                         this.add(mi);
 139  0
                 }
 140  0
         }
 141  
 }