Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ReplayToolbar |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$1 |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$2 |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$3 |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$4 |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$5 |
|
| 1.411764705882353;1.412 | ||||
ReplayToolbar$6 |
|
| 1.411764705882353;1.412 |
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 | 0 | public class ReplayToolbar extends JToolBar implements ReplayToolbarI { |
81 | private static final long serialVersionUID = 1L; | |
82 | private final static boolean DEBUG = true; | |
83 | 0 | private Logger logger = LoggerFactory.getLogger(getClass()); |
84 | ||
85 | 0 | private boolean playPause = true; |
86 | 0 | private JJButton jButtonFirst = null; |
87 | 0 | private JJButton jButtonBack = null; |
88 | 0 | private JJButton jButtonNext = null; |
89 | 0 | private JJButton jButtonEnd = null; |
90 | ||
91 | private ToolbarHandler toolbarHandler; // @jve:decl-index=0: | |
92 | 0 | private JRadioButton jButtonPause = null; |
93 | 0 | private JRadioButton jButtonPlay = null; |
94 | 0 | private ButtonGroup buttonGroup = new ButtonGroup(); |
95 | /** Create and initialize the ReplayToolbar | |
96 | */ | |
97 | public ReplayToolbar() { | |
98 | 0 | super(); |
99 | 0 | initialize(); |
100 | 0 | buttonGroup.add(jButtonPause); |
101 | 0 | buttonGroup.add(jButtonPlay); |
102 | 0 | buttonGroup.setSelected(jButtonPlay.getModel(), true); |
103 | 0 | setPlayPause(true); |
104 | 0 | } |
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 | 0 | this.toolbarHandler = toolbarHandler; |
111 | 0 | } |
112 | ||
113 | /* (non-Javadoc) | |
114 | * @see com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ReplayToolbarI#getPlayPause() | |
115 | */ | |
116 | @Override | |
117 | public boolean isPlayPause() { | |
118 | 0 | 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 | 0 | this.playPause = playPause; |
127 | 0 | this.jButtonPlay.getModel().setPressed(playPause); |
128 | 0 | this.jButtonPause.getModel().setPressed(!playPause); |
129 | // this.jButtonPlay.setPressed(playPause); | |
130 | // this.jButtonPause.setSelected(playPause); | |
131 | if (DEBUG) | |
132 | 0 | logger.info("playPause = " + playPause); |
133 | 0 | } |
134 | ||
135 | /** | |
136 | * This method initializes this | |
137 | */ | |
138 | private void initialize() { | |
139 | 0 | this.setFloatable(false); |
140 | 0 | this.add(getJButtonFirst()); |
141 | 0 | this.add(getJButtonBack()); |
142 | 0 | this.add(getJButtonNext()); |
143 | 0 | this.add(getJButtonEnd()); |
144 | 0 | this.add(new JToolBar.Separator()); |
145 | 0 | this.add(getJButtonPause()); |
146 | 0 | this.add(getJButtonPlay()); |
147 | 0 | } |
148 | ||
149 | /** | |
150 | * This method initializes jButtonFirst | |
151 | * | |
152 | * @return javax.swing.JButton | |
153 | */ | |
154 | public JJButton getJButtonFirst() { | |
155 | 0 | if (jButtonFirst == null) { |
156 | 0 | jButtonFirst = new JJButton(); |
157 | 0 | jButtonFirst.setIcon(new ImageIcon(getClass().getResource("/g/begin.png"))); |
158 | 0 | jButtonFirst.setToolTipText("Show the first move of the game."); |
159 | 0 | jButtonFirst.setPreferredSize(new Dimension(18, 18)); |
160 | 0 | jButtonFirst.addActionListener(new java.awt.event.ActionListener() { |
161 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
162 | 0 | toolbarHandler.buttonPressed(Button.First); |
163 | 0 | } |
164 | }); | |
165 | } | |
166 | 0 | return jButtonFirst; |
167 | } | |
168 | ||
169 | /** | |
170 | * This method initializes jButtonBack | |
171 | * | |
172 | * @return javax.swing.JButton | |
173 | */ | |
174 | public JJButton getJButtonBack() { | |
175 | 0 | if (jButtonBack == null) { |
176 | 0 | jButtonBack = new JJButton(); |
177 | 0 | jButtonBack.setIcon(new ImageIcon(getClass().getResource("/g/left.png"))); |
178 | 0 | jButtonBack.setToolTipText("Show the previous move in the game."); |
179 | 0 | jButtonBack.setPreferredSize(new Dimension(18, 18)); |
180 | 0 | jButtonBack.addActionListener(new java.awt.event.ActionListener() { |
181 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
182 | 0 | toolbarHandler.buttonPressed(Button.Prev); |
183 | 0 | } |
184 | }); | |
185 | } | |
186 | 0 | return jButtonBack; |
187 | } | |
188 | ||
189 | /** | |
190 | * This method initializes jButtonNext | |
191 | * | |
192 | * @return javax.swing.JButton | |
193 | */ | |
194 | public JJButton getJButtonNext() { | |
195 | 0 | if (jButtonNext == null) { |
196 | 0 | jButtonNext = new JJButton(); |
197 | 0 | jButtonNext.setIcon(new ImageIcon(getClass().getResource("/g/right.png"))); |
198 | 0 | jButtonNext.setToolTipText("Show the next move in the game."); |
199 | 0 | jButtonNext.setPreferredSize(new Dimension(18, 18)); |
200 | 0 | jButtonNext.addActionListener(new java.awt.event.ActionListener() { |
201 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
202 | 0 | toolbarHandler.buttonPressed(Button.Next); |
203 | 0 | } |
204 | }); | |
205 | } | |
206 | 0 | return jButtonNext; |
207 | } | |
208 | ||
209 | /** | |
210 | * This method initializes jButtonEnd | |
211 | * | |
212 | * @return javax.swing.JButton | |
213 | */ | |
214 | public JJButton getJButtonEnd() { | |
215 | 0 | if (jButtonEnd == null) { |
216 | 0 | jButtonEnd = new JJButton(); |
217 | 0 | jButtonEnd.setIcon(new ImageIcon(getClass().getResource("/g/end.png"))); |
218 | 0 | jButtonEnd.setToolTipText("Show the last or current move in the game."); |
219 | 0 | jButtonEnd.setPreferredSize(new Dimension(18, 18)); |
220 | 0 | jButtonEnd.addActionListener(new java.awt.event.ActionListener() { |
221 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
222 | 0 | toolbarHandler.buttonPressed(Button.Last); |
223 | 0 | } |
224 | }); | |
225 | } | |
226 | 0 | return jButtonEnd; |
227 | } | |
228 | ||
229 | /** | |
230 | * This method initializes jButtonPause | |
231 | * | |
232 | * @return javax.swing.JButton | |
233 | */ | |
234 | private JRadioButton getJButtonPause() { | |
235 | 0 | if (jButtonPause == null) { |
236 | 0 | jButtonPause = new JRadioButton(new ImageIcon(getClass().getResource("/g/pause18.png"))); |
237 | 0 | jButtonPause.setSelectedIcon(new ImageIcon(getClass().getResource("/g/pause18-selected.png"))); |
238 | 0 | jButtonPause.setPreferredSize(new Dimension(24, 20)); |
239 | 0 | jButtonPause.addActionListener(new java.awt.event.ActionListener() { |
240 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
241 | 0 | setPlayPause(false); |
242 | 0 | toolbarHandler.buttonPressed(Button.PlayPaused); |
243 | 0 | } |
244 | }); | |
245 | } | |
246 | 0 | return jButtonPause; |
247 | } | |
248 | ||
249 | /** | |
250 | * This method initializes jButtonPlay | |
251 | * | |
252 | * @return javax.swing.JButton | |
253 | */ | |
254 | private JRadioButton getJButtonPlay() { | |
255 | 0 | if (jButtonPlay == null) { |
256 | 0 | jButtonPlay = new JRadioButton(new ImageIcon(getClass().getResource("/g/play18.png"))); |
257 | 0 | jButtonPlay.setSelectedIcon(new ImageIcon(getClass().getResource("/g/play18-selected.png"))); |
258 | //jButtonPlay.setIcon(); | |
259 | 0 | jButtonPlay.setPreferredSize(new Dimension(22, 20)); |
260 | 0 | jButtonPlay.addActionListener(new java.awt.event.ActionListener() { |
261 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
262 | 0 | setPlayPause(true); |
263 | 0 | toolbarHandler.buttonPressed(Button.PlayPaused); |
264 | 0 | } |
265 | }); | |
266 | } | |
267 | 0 | return jButtonPlay; |
268 | } | |
269 | } |