1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
75
76
77
78
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;
92 private JRadioButton jButtonPause = null;
93 private JRadioButton jButtonPlay = null;
94 private ButtonGroup buttonGroup = new ButtonGroup();
95
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
107
108
109 public void setToolbarHandler(ToolbarHandler toolbarHandler) {
110 this.toolbarHandler = toolbarHandler;
111 }
112
113
114
115
116 @Override
117 public boolean isPlayPause() {
118 return playPause;
119 }
120
121
122
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
130
131 if (DEBUG)
132 logger.info("playPause = " + playPause);
133 }
134
135
136
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
151
152
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
171
172
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
191
192
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
211
212
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
231
232
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
251
252
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
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 }