View Javadoc
1   /******************************************************************************
2    * PlayerListPopupMenu.java - The popup menu for the PlayerList
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.5  2011/01/01 06:12:31  dick
10   * Don't need to keep GroupManager local.
11   *
12   * Revision 1.4  2011/01/01 00:19:08  dick
13   * Build the groups for the submenu.
14   *
15   * Revision 1.3  2010/03/03 13:12:21  inim
16   * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
17   *
18   * Revision 1.2  2010/03/03 12:19:49  inim
19   * 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.
20   *
21   * Revision 1.1  2010/02/04 05:57:53  inim
22   * Mavenized project folder layout
23   *
24   * Revision 1.5  2010/01/24 06:21:36  dick
25   * Don't update the playerList if the popupmenu is open, it gets confused.
26   *
27   * Revision 1.4  2010/01/23 06:26:04  dick
28   * Add the RepBot menu.
29   *
30   * Revision 1.3  2009/02/14 15:46:36  dick
31   * BuckoFIBS is released under the GNU license.
32   *
33   * Revision 1.2  2009/02/01 21:28:25  dick
34   * Handle the InvitePopupSubmenu.
35   *
36   * Revision 1.1  2009/01/28 19:39:44  dick
37   * package com.buckosoft.fibs.gui.playerList becomes com.buckosoft.fibs.BuckoFIBS.gui.playerList.
38   *
39   * Revision 1.3  2009/01/24 17:08:03  dick
40   * Javadoc.
41   *
42   * Revision 1.2  2008/12/12 14:46:36  dick
43   * Enable the Watch command.
44   *
45   * Revision 1.1  2008/04/07 08:08:25  dick
46   * The popup menu for the PlayerList.
47   */
48  
49  /* 
50   * This program is free software: you can redistribute it and/or modify
51   * it under the terms of the GNU General Public License as published by
52   * the Free Software Foundation, either version 3 of the License, or
53   * (at your option) any later version.
54   *
55   * This program is distributed in the hope that it will be useful,
56   * but WITHOUT ANY WARRANTY; without even the implied warranty of
57   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58   * GNU General Public License for more details.
59   *
60   * You should have received a copy of the GNU General Public License
61   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
62   *
63   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
64   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
65   * 
66   */
67  package com.buckosoft.fibs.BuckoFIBS.gui.playerList;
68  
69  import java.awt.event.ActionEvent;
70  import java.awt.event.ActionListener;
71  
72  import javax.swing.JMenuItem;
73  import javax.swing.JPopupMenu;
74  
75  import com.buckosoft.fibs.BuckoFIBS.GroupManager;
76  import com.buckosoft.fibs.BuckoFIBS.gui.playerList.group.GroupPopupSubmenu;
77  import com.buckosoft.fibs.domain.Player;
78  
79  /** The popup menu for the PlayerList.
80   * @author Dick Balaska
81   * @since 2008/04/07
82   * @version $Revision$ <br> $Date$
83   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/playerList/PlayerListPopupMenu.java">cvs PlayerListPopupMenu.java</a>
84   */
85  public class PlayerListPopupMenu extends JPopupMenu implements ActionListener {
86  	private	final static boolean DEBUG = false;
87  	private static final long serialVersionUID = 1L;
88  
89  	private JMenuItem watchMenuItem = null;
90  	private JMenuItem lookMenuItem = null;
91  	private JMenuItem unwatchMenuItem = null;
92  	private JMenuItem whoisMenuItem = null;
93  	private JMenuItem viewProfileMenuItem = null;
94  	private JMenuItem updateMenuItem = null;
95  	private	InvitePopupSubmenu	invitePopupSubmenu = null;
96  	private RepBotPopupSubmenu	repbotPopupSubmenu = null;
97  	private GroupPopupSubmenu	groupPopupSubmenu = null;
98  
99  	private	ActionListener	menuHandler = null;  //  @jve:decl-index=0:
100 
101 	private	Player		player;
102 	
103 	public final static String s_setVisible = "setVisible";
104 	/**
105 	 * This method initializes 
106 	 * 
107 	 */
108 	public PlayerListPopupMenu() {
109 		super();
110 		initialize();
111 	}
112 
113 	/**
114 	 * This method initializes this
115 	 * 
116 	 */
117 	private void initialize() {
118 		this.add(getInvitePopupSubmenu());
119 		this.add(getGroupPopupSubmenu());
120         this.addSeparator();
121         this.add(getLookMenuItem());
122         this.add(getWatchMenuItem());
123         this.add(getUnwatchMenuItem());
124         this.addSeparator();
125 		this.add(getRepBotPopupSubmenu());
126         this.add(getWhoisMenuItem());
127         this.add(getViewProfileMenuItem());
128         this.add(getUpdateMenuItem());
129 			
130 	}
131 
132 	/** Set our reference to the object that will receive menu events
133 	 * @param c The ActionListener object
134 	 */ 
135 	public	void setMenuHandler(ActionListener c) {
136 		this.menuHandler = c;
137 		this.getInvitePopupSubmenu().setMenuHandler(c);
138 		this.getRepBotPopupSubmenu().setMenuHandler(c);
139 	}
140 
141 	public void setGroupManager(GroupManager groupManager) {
142 		this.getGroupPopupSubmenu().setGroupManager(groupManager);
143 	}
144 	
145 	/** Set the Player who was selected when this menu opened.
146 	 * @param player The Player selected
147 	 */
148 	public void setPlayer(Player player) {
149 		this.player = player;
150 	}
151 
152 	/** Get the Player who was selected when this menu opened.
153 	 * @return The Player selected
154 	 */
155 	public Player getPlayer() {
156 		return(player);
157 	}
158 
159 	/* (non-Javadoc)
160 	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
161 	 */
162 	public void actionPerformed(ActionEvent e) {
163 		menuHandler.actionPerformed(e);
164 	}
165 
166 	/**
167 	 * This method initializes watchMenuItem	
168 	 * 	
169 	 * @return javax.swing.JMenuItem	
170 	 */
171 	private JMenuItem getWatchMenuItem() {
172 		if (watchMenuItem == null) {
173 			watchMenuItem = new JMenuItem();
174 			watchMenuItem.setText("Watch");
175 			watchMenuItem.addActionListener(this);
176 		}
177 		return watchMenuItem;
178 	}
179 
180 	/**
181 	 * This method initializes lookMenuItem	
182 	 * 	
183 	 * @return javax.swing.JMenuItem	
184 	 */
185 	private JMenuItem getLookMenuItem() {
186 		if (lookMenuItem == null) {
187 			lookMenuItem = new JMenuItem();
188 			lookMenuItem.setText("Look");
189 			lookMenuItem.setEnabled(false);
190 			lookMenuItem.addActionListener(this);
191 		}
192 		return lookMenuItem;
193 	}
194 
195 	/**
196 	 * This method initializes unwatchMenuItem	
197 	 * 	
198 	 * @return javax.swing.JMenuItem	
199 	 */
200 	private JMenuItem getUnwatchMenuItem() {
201 		if (unwatchMenuItem == null) {
202 			unwatchMenuItem = new JMenuItem();
203 			unwatchMenuItem.setText("Unwatch");
204 			unwatchMenuItem.setEnabled(false);
205 			unwatchMenuItem.addActionListener(this);
206 		}
207 		return unwatchMenuItem;
208 	}
209 
210 	/**
211 	 * This method initializes whoisMenuItem	
212 	 * 	
213 	 * @return javax.swing.JMenuItem	
214 	 */
215 	private JMenuItem getWhoisMenuItem() {
216 		if (whoisMenuItem == null) {
217 			whoisMenuItem = new JMenuItem();
218 			whoisMenuItem.setText("Whois");
219 			whoisMenuItem.setEnabled(false);
220 			whoisMenuItem.addActionListener(this);
221 		}
222 		return whoisMenuItem;
223 	}
224 
225 	/**
226 	 * This method initializes viewProfileMenuItem	
227 	 * 	
228 	 * @return javax.swing.JMenuItem	
229 	 */
230 	private JMenuItem getViewProfileMenuItem() {
231 		if (viewProfileMenuItem == null) {
232 			viewProfileMenuItem = new JMenuItem();
233 			viewProfileMenuItem.setText("View Profile");
234 			viewProfileMenuItem.setEnabled(false);
235 			viewProfileMenuItem.addActionListener(this);
236 		}
237 		return viewProfileMenuItem;
238 	}
239 
240 	/**
241 	 * This method initializes updateMenuItem	
242 	 * 	
243 	 * @return javax.swing.JMenuItem	
244 	 */
245 	private JMenuItem getUpdateMenuItem() {
246 		if (updateMenuItem == null) {
247 			updateMenuItem = new JMenuItem();
248 			updateMenuItem.setText("Update");
249 			updateMenuItem.setEnabled(true);
250 			updateMenuItem.addActionListener(this);
251 		}
252 		return updateMenuItem;
253 	}
254 
255 	protected	InvitePopupSubmenu	getInvitePopupSubmenu() {
256 		if (invitePopupSubmenu == null) {
257 			invitePopupSubmenu = new InvitePopupSubmenu();
258 			invitePopupSubmenu.addActionListener(this);
259 		}
260 		return(invitePopupSubmenu);
261 	}
262 
263 	protected	RepBotPopupSubmenu	getRepBotPopupSubmenu() {
264 		if (repbotPopupSubmenu == null) {
265 			repbotPopupSubmenu = new RepBotPopupSubmenu();
266 			repbotPopupSubmenu.addActionListener(this);
267 		}
268 		return(repbotPopupSubmenu);
269 	}
270 
271 	protected GroupPopupSubmenu getGroupPopupSubmenu() {
272 		if (groupPopupSubmenu == null) {
273 			groupPopupSubmenu = new GroupPopupSubmenu();
274 		}
275 		return(groupPopupSubmenu);
276 	}
277 
278 	/* (non-Javadoc)
279 	 * @see javax.swing.JPopupMenu#setVisible(boolean)
280 	 */
281 	@Override
282 	public void setVisible(boolean arg0) {
283 		super.setVisible(arg0);
284 		if (DEBUG)
285 			System.out.println("PlayerListPopupMenu: setVisible(" + arg0 + ")");
286 		ActionEvent ae = new ActionEvent(this, 0, s_setVisible, arg0 ? 1 : 0);
287 		this.actionPerformed(ae);
288 	}
289 
290 	public void rebuildGroups() {
291 		this.groupPopupSubmenu.repopulate(player);
292 	}
293 }