View Javadoc
1   /******************************************************************************
2    * ReplayToolbar.java - Be the Replay Toolbar above the board
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.3  2011/06/10 05:58:40  dick
10   * Make Play/Pause be radio buttons.
11   * Use separate icons for the selected state so we get some differentiation.  -- The selected icons still need work.
12   *
13   * Revision 1.2  2011/05/23 03:25:53  dick
14   * Add Play and Pause.
15   *
16   * Revision 1.1  2011/05/15 02:17:33  dick
17   * c.b.f.B.gui.board becomes c.b.f.B.gui.boardTab.
18   *
19   * Revision 1.4  2011/05/11 22:21:44  dick
20   * Extract ReplayToolbar's public api to an Interface.
21   *
22   * Revision 1.3  2010/03/03 13:12:21  inim
23   * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8
24   *
25   * Revision 1.2  2010/03/03 12:19:49  inim
26   * 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.
27   *
28   * Revision 1.1  2010/02/04 05:57:53  inim
29   * Mavenized project folder layout
30   *
31   * Revision 1.3  2009/02/14 15:28:49  dick
32   * BuckoFIBS is released under the GNU license.
33   *
34   * Revision 1.2  2009/01/31 06:05:25  dick
35   * Do something when the buttons are pressed.
36   *
37   * Revision 1.1  2009/01/28 22:10:33  dick
38   * Be the Replay Toolbar above the board.
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.boardTab;
60  
61  import java.awt.Dimension;
62  
63  import javax.swing.ButtonGroup;
64  import javax.swing.ImageIcon;
65  import javax.swing.JRadioButton;
66  import javax.swing.JToolBar;
67  
68  import org.slf4j.Logger;
69  import org.slf4j.LoggerFactory;
70  
71  import com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ToolbarHandler.Button;
72  import com.buckosoft.swing.JJButton;
73  
74  /** Be the Replay Toolbar above the board
75   * @author Dick Balaska
76   * @since 2009/01/28
77   * @version $Revision$ <br> $Date$
78   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/board/ReplayToolbar.java">cvs ReplayToolbar.java</a>
79   */
80  public class ReplayToolbar extends JToolBar implements ReplayToolbarI {
81  	private static final long serialVersionUID = 1L;
82  	private	final static boolean DEBUG = true;
83      private Logger logger = LoggerFactory.getLogger(getClass());
84  
85      private	boolean		playPause = true;
86  	private JJButton	jButtonFirst = null;
87  	private JJButton	jButtonBack = null;
88  	private JJButton	jButtonNext = null;
89  	private JJButton	jButtonEnd = null;
90  
91  	private	ToolbarHandler	toolbarHandler;  //  @jve:decl-index=0:
92  	private JRadioButton		jButtonPause = null;
93  	private JRadioButton		jButtonPlay = null;
94  	private	ButtonGroup		buttonGroup = new ButtonGroup();
95  	/** Create and initialize the ReplayToolbar
96  	 */
97  	public ReplayToolbar() {
98  		super();
99  		initialize();
100 		buttonGroup.add(jButtonPause);
101 		buttonGroup.add(jButtonPlay);
102 		buttonGroup.setSelected(jButtonPlay.getModel(), true);
103 		setPlayPause(true);
104 	}
105 	
106 	/** Set the object that will receive our button presses.
107 	 * @param toolbarHandler the toolbarHandler to set
108 	 */
109 	public void setToolbarHandler(ToolbarHandler toolbarHandler) {
110 		this.toolbarHandler = toolbarHandler;
111 	}
112 
113 	/* (non-Javadoc)
114 	 * @see com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ReplayToolbarI#getPlayPause()
115 	 */
116 	@Override
117 	public boolean isPlayPause() {
118 		return playPause;
119 	}
120 
121 	/* (non-Javadoc)
122 	 * @see com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ReplayToolbarI#setPlayPause(boolean)
123 	 */
124 	@Override
125 	public void setPlayPause(boolean playPause) {
126 		this.playPause = playPause;
127 		this.jButtonPlay.getModel().setPressed(playPause);
128 		this.jButtonPause.getModel().setPressed(!playPause);
129 //		this.jButtonPlay.setPressed(playPause);
130 //		this.jButtonPause.setSelected(playPause);
131 		if (DEBUG)
132 			logger.info("playPause = " + playPause);
133 	}
134 
135 	/**
136 	 * This method initializes this
137 	 */
138 	private void initialize() {
139         this.setFloatable(false);
140         this.add(getJButtonFirst());
141         this.add(getJButtonBack());
142         this.add(getJButtonNext());
143         this.add(getJButtonEnd());	
144         this.add(new JToolBar.Separator());
145         this.add(getJButtonPause());
146         this.add(getJButtonPlay());
147 	}
148 
149 	/**
150 	 * This method initializes jButtonFirst	
151 	 * 	
152 	 * @return javax.swing.JButton	
153 	 */
154 	public JJButton getJButtonFirst() {
155 		if (jButtonFirst == null) {
156 			jButtonFirst = new JJButton();
157 			jButtonFirst.setIcon(new ImageIcon(getClass().getResource("/g/begin.png")));
158 			jButtonFirst.setToolTipText("Show the first move of the game.");
159 			jButtonFirst.setPreferredSize(new Dimension(18, 18));
160 			jButtonFirst.addActionListener(new java.awt.event.ActionListener() {
161 				public void actionPerformed(java.awt.event.ActionEvent e) {
162 					toolbarHandler.buttonPressed(Button.First);
163 				}
164 			});
165 		}
166 		return jButtonFirst;
167 	}
168 
169 	/**
170 	 * This method initializes jButtonBack
171 	 *
172 	 * @return javax.swing.JButton
173 	 */
174 	public JJButton getJButtonBack() {
175 		if (jButtonBack == null) {
176 			jButtonBack = new JJButton();
177 			jButtonBack.setIcon(new ImageIcon(getClass().getResource("/g/left.png")));
178 			jButtonBack.setToolTipText("Show the previous move in the game.");
179 			jButtonBack.setPreferredSize(new Dimension(18, 18));
180 			jButtonBack.addActionListener(new java.awt.event.ActionListener() {
181 				public void actionPerformed(java.awt.event.ActionEvent e) {
182 					toolbarHandler.buttonPressed(Button.Prev);
183 				}
184 			});
185 		}
186 		return jButtonBack;
187 	}
188 
189 	/**
190 	 * This method initializes jButtonNext	
191 	 *
192 	 * @return javax.swing.JButton
193 	 */
194 	public JJButton getJButtonNext() {
195 		if (jButtonNext == null) {
196 			jButtonNext = new JJButton();
197 			jButtonNext.setIcon(new ImageIcon(getClass().getResource("/g/right.png")));
198 			jButtonNext.setToolTipText("Show the next move in the game.");
199 			jButtonNext.setPreferredSize(new Dimension(18, 18));
200 			jButtonNext.addActionListener(new java.awt.event.ActionListener() {
201 				public void actionPerformed(java.awt.event.ActionEvent e) {
202 					toolbarHandler.buttonPressed(Button.Next);
203 				}
204 			});
205 		}
206 		return jButtonNext;
207 	}
208 
209 	/**
210 	 * This method initializes jButtonEnd
211 	 *
212 	 * @return javax.swing.JButton
213 	 */
214 	public JJButton getJButtonEnd() {
215 		if (jButtonEnd == null) {
216 			jButtonEnd = new JJButton();
217 			jButtonEnd.setIcon(new ImageIcon(getClass().getResource("/g/end.png")));
218 			jButtonEnd.setToolTipText("Show the last or current move in the game.");
219 			jButtonEnd.setPreferredSize(new Dimension(18, 18));
220 			jButtonEnd.addActionListener(new java.awt.event.ActionListener() {
221 				public void actionPerformed(java.awt.event.ActionEvent e) {
222 					toolbarHandler.buttonPressed(Button.Last);
223 				}
224 			});
225 		}
226 		return jButtonEnd;
227 	}
228 
229 	/**
230 	 * This method initializes jButtonPause	
231 	 * 	
232 	 * @return javax.swing.JButton	
233 	 */
234 	private JRadioButton getJButtonPause() {
235 		if (jButtonPause == null) {
236 			jButtonPause = new JRadioButton(new ImageIcon(getClass().getResource("/g/pause18.png")));
237 			jButtonPause.setSelectedIcon(new ImageIcon(getClass().getResource("/g/pause18-selected.png")));
238 			jButtonPause.setPreferredSize(new Dimension(24, 20));
239 			jButtonPause.addActionListener(new java.awt.event.ActionListener() {
240 				public void actionPerformed(java.awt.event.ActionEvent e) {
241 					setPlayPause(false);
242 					toolbarHandler.buttonPressed(Button.PlayPaused);
243 				}
244 			});
245 		}
246 		return jButtonPause;
247 	}
248 
249 	/**
250 	 * This method initializes jButtonPlay	
251 	 * 	
252 	 * @return javax.swing.JButton	
253 	 */
254 	private JRadioButton getJButtonPlay() {
255 		if (jButtonPlay == null) {
256 			jButtonPlay = new JRadioButton(new ImageIcon(getClass().getResource("/g/play18.png")));
257 			jButtonPlay.setSelectedIcon(new ImageIcon(getClass().getResource("/g/play18-selected.png")));
258 			//jButtonPlay.setIcon();
259 			jButtonPlay.setPreferredSize(new Dimension(22, 20));
260 			jButtonPlay.addActionListener(new java.awt.event.ActionListener() {
261 				public void actionPerformed(java.awt.event.ActionEvent e) {
262 					setPlayPause(true);
263 					toolbarHandler.buttonPressed(Button.PlayPaused);
264 				}
265 			});
266 		}
267 		return jButtonPlay;
268 	}
269 }