View Javadoc
1   /******************************************************************************
2    * Toolbar.java - The BuckoFIBS main toolbar
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.4  2011/05/23 03:37:09  dick
10   * Purposefully broken to test the build script.
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.14  2010/01/29 23:10:44  dick
22   * Double-click the graph to bring up the config dialog.
23   *
24   * Revision 1.13  2010/01/27 02:10:39  dick
25   * ratingGraphPanel.mouseClick.
26   *
27   * Revision 1.12  2009/03/04 19:05:03  dick
28   * Javadoc.
29   *
30   * Revision 1.11  2009/02/21 17:59:05  dick
31   * Add the RatingGraphPanel.
32   *
33   * Revision 1.10  2009/02/14 12:25:22  dick
34   * Unused button becomes About button.
35   *
36   * Revision 1.9  2009/01/28 19:13:24  dick
37   * Use the notes.png icon.
38   *
39   * Revision 1.8  2009/01/13 18:27:39  dick
40   * Handle Ready To Play
41   *
42   * Revision 1.7  2009/01/09 07:16:51  dick
43   * Add the Prefs4Messages button.
44   *
45   * Revision 1.6  2008/12/17 04:38:00  dick
46   * Connect button work.
47   *
48   * Revision 1.5  2008/12/15 01:53:57  dick
49   * Cleanup.
50   *
51   * Revision 1.4  2008/12/13 06:29:09  dick
52   * Add ReadyToPlay and some funky icons.
53   *
54   * Revision 1.3  2008/12/11 08:49:26  dick
55   * Add the tools (preferences) button.
56   *
57   * Revision 1.2  2008/03/30 05:44:12  dick
58   * Execute a command when the connection button is clicked.
59   *
60   * Revision 1.1  2008/03/29 08:57:43  dick
61   * BuckoFIBS skeleton checkin.
62   *
63   */
64  
65  /* 
66   * This program is free software: you can redistribute it and/or modify
67   * it under the terms of the GNU General Public License as published by
68   * the Free Software Foundation, either version 3 of the License, or
69   * (at your option) any later version.
70   *
71   * This program is distributed in the hope that it will be useful,
72   * but WITHOUT ANY WARRANTY; without even the implied warranty of
73   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
74   * GNU General Public License for more details.
75   *
76   * You should have received a copy of the GNU General Public License
77   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
78   *
79   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
80   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
81   * 
82   */
83  package com.buckosoft.fibs.BuckoFIBS.gui;
84  
85  import java.awt.Color;
86  import java.awt.Dimension;
87  import java.awt.GridBagLayout;
88  
89  import javax.swing.ImageIcon;
90  import javax.swing.JButton;
91  import javax.swing.JCheckBox;
92  import javax.swing.JToolBar;
93  
94  import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher;
95  
96  /** The BuckoFIBS main toolbar.
97   * @author Dick Balaska
98   * @since 2008/03/29
99   * @version $Revision$ <br> $Date$
100  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/ToolBar.java">cvs ToolBar.java</a>
101  */
102 public class ToolBar extends JToolBar {
103 	private static final long serialVersionUID = 1L;
104 
105 	private JButton jButtonConnect = null;
106 
107 	private	CommandDispatcher commandDispatcher;  //  @jve:decl-index=0:
108 
109 	private JButton jButtonTools = null;
110 
111 	private JButton jButtonReadyToPlay = null;
112 
113 	private JCheckBox jCheckBox = null;
114 
115 	private	ImageIcon connectedIcon;  //  @jve:decl-index=0:
116 	private	ImageIcon notConnectedIcon;  //  @jve:decl-index=0:
117 	private	ImageIcon readyIcon;
118 	private ImageIcon notReadyIcon;
119 	
120 	private JButton jButtonMessages = null;
121 
122 	private RatingGraphPanel ratingGraphPanel = null;
123 
124 	/**
125 	 * Instantiate the ToolBar for BuckoFIBS 
126 	 * 
127 	 */
128 	public ToolBar() {
129 		super();
130 		initialize();
131 	}
132 
133 	/** Set the reference to the command dispatcher
134 	 * @param commandDispatcher Our system CommandDispatcher
135 	 */
136 	public	void	setCommandDispatcher(CommandDispatcher commandDispatcher) {
137 		this.commandDispatcher = commandDispatcher;
138 	}
139 
140 	public void setConnected(boolean b) {
141 		this.getJButtonConnect().setIcon(b ? connectedIcon : notConnectedIcon);
142 		this.getJButtonReadyToPlay().setEnabled(b);
143 	}
144 
145 	private void handleConnectButton() {
146 		if (this.getJButtonConnect().getIcon() == connectedIcon)
147 			commandDispatcher.dispatch(CommandDispatcher.Command.DISCONNECT_FROM_NETWORK);
148 		else
149 			commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_CONNECTION_DIALOG);
150 	}
151 
152 	public void setReadyToPlay(boolean b) {
153 		this.getJButtonReadyToPlay().setIcon(b? readyIcon : notReadyIcon);
154 	}
155 	/**
156 	 * This method initializes this
157 	 * 
158 	 */
159 	private void initialize() {
160 		notConnectedIcon = new ImageIcon(getClass().getResource("/g/connectTelnet.png"));
161 		connectedIcon = new ImageIcon(getClass().getResource("/g/telnet.png"));
162 		readyIcon = new ImageIcon(getClass().getResource("/g/accept32.png"));
163 		notReadyIcon = new ImageIcon(getClass().getResource("/g/pause32.png"));
164 
165 		this.add(getJButtonConnect());
166 		this.add(getJButtonTools());
167 		this.add(getJButtonMessages());
168 		this.add(getJButtonReadyToPlay());
169         this.add(new JToolBar.Separator());
170 		this.add(getJCheckBox());
171         this.add(new JToolBar.Separator());
172         this.add(new JToolBar.Separator());
173 		this.add(getRatingGraphPanel());
174 	}
175 	
176 	/**
177 	 * This method initializes jButtonUp
178 	 * 	
179 	 * @return javax.swing.JButton	
180 	 */
181 	public JButton getJButtonConnect() {
182 		if (jButtonConnect == null) {
183 			jButtonConnect = new JButton();
184 			jButtonConnect.setIcon(new ImageIcon(getClass().getResource("/g/connectTelnet.png")));
185 			jButtonConnect.setMnemonic(java.awt.event.KeyEvent.VK_U);
186 			jButtonConnect.setPreferredSize(new Dimension(44, 44));
187 			jButtonConnect.setToolTipText("Connect to the Server");
188 			jButtonConnect.addActionListener(new java.awt.event.ActionListener() {
189 				public void actionPerformed(java.awt.event.ActionEvent e) {
190 					handleConnectButton();
191 				}
192 			});
193 		}
194 		return jButtonConnect;
195 	}
196 
197 	/**
198 	 * This method initializes jButtonTools	
199 	 * 	
200 	 * @return javax.swing.JButton	
201 	 */
202 	private JButton getJButtonTools() {
203 		if (jButtonTools == null) {
204 			jButtonTools = new JButton();
205 			jButtonTools.setIcon(new ImageIcon(getClass().getResource("/g/tools.png")));
206 			jButtonTools.setToolTipText("Configure options");
207 			jButtonTools.addActionListener(new java.awt.event.ActionListener() {
208 				public void actionPerformed(java.awt.event.ActionEvent e) {
209 					commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_PREFERENCES_DIALOG);
210 				}
211 			});
212 		}
213 		return jButtonTools;
214 	}
215 
216 	/**
217 	 * This method initializes jButtonReadyToPlay	
218 	 * 	
219 	 * @return javax.swing.JButton	
220 	 */
221 	private JButton getJButtonReadyToPlay() {
222 		if (jButtonReadyToPlay == null) {
223 			jButtonReadyToPlay = new JButton();
224 			jButtonReadyToPlay.setIcon(notReadyIcon);
225 			jButtonReadyToPlay.setToolTipText("Toggle \"Ready to play\"");
226 			jButtonReadyToPlay.addActionListener(new java.awt.event.ActionListener() {
227 				public void actionPerformed(java.awt.event.ActionEvent e) {
228 					commandDispatcher.dispatch(CommandDispatcher.Command.TOGGLE_READY_TO_PLAY);
229 				}
230 			});
231 		}
232 		return jButtonReadyToPlay;
233 	}
234 
235 	/**
236 	 * This method initializes jCheckBox	
237 	 * 	
238 	 * @return javax.swing.JCheckBox	
239 	 */
240 	private JCheckBox getJCheckBox() {
241 		if (jCheckBox == null) {
242 			jCheckBox = new JCheckBox();
243 			jCheckBox.setIcon(new ImageIcon(getClass().getResource("/g/choo.png")));
244 			jCheckBox.setToolTipText("Display the about box");
245 			jCheckBox.setPressedIcon(new ImageIcon(getClass().getResource("/g/choo1.png")));
246 			jCheckBox.addActionListener(new java.awt.event.ActionListener() {
247 				public void actionPerformed(java.awt.event.ActionEvent e) {
248 					commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_ABOUT_DIALOG);
249 				}
250 			});
251 		}
252 		return jCheckBox;
253 	}
254 
255 	/**
256 	 * This method initializes jButtonMessages	
257 	 * 	
258 	 * @return javax.swing.JButton	
259 	 */
260 	private JButton getJButtonMessages() {
261 		if (jButtonMessages == null) {
262 			jButtonMessages = new JButton();
263 			jButtonMessages.setIcon(new ImageIcon(getClass().getResource("/g/notes.png")));
264 			jButtonMessages.setToolTipText("Configure message routing and display");
265 			jButtonMessages.addActionListener(new java.awt.event.ActionListener() {
266 				public void actionPerformed(java.awt.event.ActionEvent e) {
267 					commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_PREFS4MSGS_DIALOG);
268 				}
269 			});
270 		}
271 		return jButtonMessages;
272 	}
273 
274 	/**
275 	 * This method initializes jPanelRating	
276 	 * 	
277 	 * @return javax.swing.JPanel	
278 	 */
279 	public RatingGraphPanel getRatingGraphPanel() {
280 		if (ratingGraphPanel == null) {
281 			ratingGraphPanel = new RatingGraphPanel();
282 			ratingGraphPanel.setLayout(new GridBagLayout());
283 			ratingGraphPanel.setPreferredSize(new Dimension(100, 40));
284 			ratingGraphPanel.setBackground(Color.black);
285 			ratingGraphPanel.addMouseListener(new java.awt.event.MouseAdapter() {
286 				public void mouseClicked(java.awt.event.MouseEvent e) {
287 					if (e.getClickCount() == 2)
288 						commandDispatcher.dispatch(CommandDispatcher.Command.SHOW_RATINGS_GRAPH_DIALOG);
289 				}
290 			});
291 		}
292 		return ratingGraphPanel;
293 	}
294 }