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 | |
package com.buckosoft.fibs.BuckoFIBS.gui; |
51 | |
|
52 | |
import java.awt.BorderLayout; |
53 | |
import java.awt.Dimension; |
54 | |
import java.awt.Frame; |
55 | |
import java.awt.GridBagConstraints; |
56 | |
import java.awt.GridBagLayout; |
57 | |
import java.awt.Insets; |
58 | |
|
59 | |
import javax.swing.ButtonGroup; |
60 | |
import javax.swing.JButton; |
61 | |
import javax.swing.JDialog; |
62 | |
import javax.swing.JFrame; |
63 | |
import javax.swing.JPanel; |
64 | |
import javax.swing.JRadioButton; |
65 | |
import javax.swing.JTextField; |
66 | |
import javax.swing.event.DocumentEvent; |
67 | |
import javax.swing.event.DocumentListener; |
68 | |
|
69 | |
import com.buckosoft.fibs.BuckoFIBS.BFProperties; |
70 | |
import com.buckosoft.fibs.BuckoFIBS.CommandDispatcher; |
71 | |
import com.buckosoft.fibs.domain.config.RatingGraphConfig; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 0 | public class RatingGraphPanelConfigureDialog extends JDialog implements DocumentListener { |
85 | |
private final static boolean DEBUG = false; |
86 | |
private CommandDispatcher commandDispatcher; |
87 | |
private BFProperties properties; |
88 | |
|
89 | |
private static final long serialVersionUID = 1L; |
90 | 0 | private JPanel jContentPane = null; |
91 | 0 | private JPanel jPanelGraphType = null; |
92 | 0 | private JRadioButton jRadioButtonAllMatches = null; |
93 | 0 | private JRadioButton jRadioButtonLastXMatches = null; |
94 | 0 | private JTextField jTextFieldNumberOfMatches = null; |
95 | 0 | private JRadioButton jRadioButtonFromDate = null; |
96 | 0 | private JPanel jPanelOKCancel = null; |
97 | 0 | private JButton jButtonOK = null; |
98 | 0 | private JButton jButtonCancel = null; |
99 | |
private RatingGraphConfig ratingGraphConfig; |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public RatingGraphPanelConfigureDialog(Frame owner) { |
105 | 0 | super(owner); |
106 | 0 | initialize(); |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public RatingGraphPanelConfigureDialog(JFrame owner, CommandDispatcher commandDispatcher) { |
115 | 0 | super(owner, true); |
116 | 0 | this.commandDispatcher = commandDispatcher; |
117 | 0 | this.properties = commandDispatcher.getProperties(); |
118 | 0 | initialize(); |
119 | 0 | this.setLocationRelativeTo(owner); |
120 | |
|
121 | 0 | BFProperties props = this.commandDispatcher.getProperties(); |
122 | 0 | ratingGraphConfig = props.getRatingGraphConfig().clone(); |
123 | 0 | switch (ratingGraphConfig.getTypeAsInt()) { |
124 | |
case 0: |
125 | 0 | this.jRadioButtonAllMatches.getModel().setSelected(true); |
126 | 0 | break; |
127 | |
case 1: |
128 | 0 | this.jRadioButtonLastXMatches.getModel().setSelected(true); |
129 | 0 | break; |
130 | |
case 2: |
131 | 0 | this.jRadioButtonFromDate.getModel().setSelected(true); |
132 | |
break; |
133 | |
} |
134 | 0 | this.jTextFieldNumberOfMatches.setText("" + props.getRatingGraphConfig().getMatchCount()); |
135 | 0 | this.jTextFieldNumberOfMatches.setEnabled(ratingGraphConfig.getType() == RatingGraphConfig.Type.displayLastXMatches); |
136 | 0 | } |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
private void initialize() { |
142 | 0 | this.setSize(300, 200); |
143 | 0 | this.setTitle("Configure the Rating Graph"); |
144 | 0 | this.setContentPane(getJContentPane()); |
145 | 0 | } |
146 | |
|
147 | |
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { |
148 | 0 | setVisible(false); |
149 | 0 | RatingGraphConfig rgc = this.commandDispatcher.getProperties().getRatingGraphConfig(); |
150 | 0 | if (this.jRadioButtonAllMatches.getModel().isSelected()) |
151 | 0 | rgc.setTypeAsInt(0); |
152 | 0 | if (this.jRadioButtonLastXMatches.getModel().isSelected()) |
153 | 0 | rgc.setTypeAsInt(1); |
154 | 0 | if (this.jRadioButtonFromDate.getModel().isSelected()) |
155 | 0 | rgc.setTypeAsInt(2); |
156 | |
|
157 | 0 | int i = -1; |
158 | |
try { |
159 | 0 | i = Integer.parseInt(this.jTextFieldNumberOfMatches.getText()); |
160 | 0 | } catch (NumberFormatException e) { |
161 | 0 | i = -1; |
162 | 0 | } |
163 | 0 | if (i < 1) |
164 | 0 | i = 1; |
165 | 0 | rgc.setMatchCount(i); |
166 | 0 | this.properties.setRatingGraphConfig(rgc); |
167 | 0 | dispose(); |
168 | 0 | } |
169 | |
|
170 | |
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { |
171 | 0 | setVisible(false); |
172 | 0 | dispose(); |
173 | 0 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
private JPanel getJContentPane() { |
180 | 0 | if (jContentPane == null) { |
181 | 0 | BorderLayout borderLayout = new BorderLayout(); |
182 | 0 | borderLayout.setHgap(15); |
183 | 0 | borderLayout.setVgap(11); |
184 | 0 | jContentPane = new JPanel(); |
185 | 0 | jContentPane.setLayout(borderLayout); |
186 | 0 | jContentPane.add(getJPanelGraphType(), BorderLayout.CENTER); |
187 | 0 | jContentPane.add(getJPanelOKCancel(), BorderLayout.SOUTH); |
188 | |
} |
189 | 0 | return jContentPane; |
190 | |
} |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
private JPanel getJPanelGraphType() { |
197 | 0 | if (jPanelGraphType == null) { |
198 | 0 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
199 | 0 | gridBagConstraints4.gridx = 0; |
200 | 0 | gridBagConstraints4.gridy = 4; |
201 | 0 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
202 | 0 | gridBagConstraints3.gridx = 0; |
203 | 0 | gridBagConstraints3.anchor = GridBagConstraints.WEST; |
204 | 0 | gridBagConstraints3.gridy = 3; |
205 | 0 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
206 | 0 | gridBagConstraints2.fill = GridBagConstraints.VERTICAL; |
207 | 0 | gridBagConstraints2.gridy = 2; |
208 | 0 | gridBagConstraints2.weightx = 1.0; |
209 | 0 | gridBagConstraints2.anchor = GridBagConstraints.WEST; |
210 | 0 | gridBagConstraints2.ipadx = 0; |
211 | 0 | gridBagConstraints2.insets = new Insets(0, 22, 0, 0); |
212 | 0 | gridBagConstraints2.gridx = 0; |
213 | 0 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
214 | 0 | gridBagConstraints1.gridx = 0; |
215 | 0 | gridBagConstraints1.anchor = GridBagConstraints.WEST; |
216 | 0 | gridBagConstraints1.gridy = 1; |
217 | 0 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
218 | 0 | gridBagConstraints.gridx = 0; |
219 | 0 | gridBagConstraints.anchor = GridBagConstraints.WEST; |
220 | 0 | gridBagConstraints.gridy = 0; |
221 | 0 | jPanelGraphType = new JPanel(); |
222 | 0 | jPanelGraphType.setLayout(new GridBagLayout()); |
223 | 0 | jPanelGraphType.add(getJRadioButtonAllMatches(), gridBagConstraints); |
224 | 0 | jPanelGraphType.add(getJRadioButtonLastXMatches(), gridBagConstraints1); |
225 | 0 | jPanelGraphType.add(getJTextFieldNumberOfMatches(), gridBagConstraints2); |
226 | 0 | jPanelGraphType.add(getJRadioButtonFromDate(), gridBagConstraints3); |
227 | 0 | ButtonGroup group = new ButtonGroup(); |
228 | 0 | group.add(getJRadioButtonAllMatches()); |
229 | 0 | group.add(getJRadioButtonLastXMatches()); |
230 | 0 | group.add(getJRadioButtonFromDate()); |
231 | |
} |
232 | 0 | return jPanelGraphType; |
233 | |
} |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
private JRadioButton getJRadioButtonAllMatches() { |
240 | 0 | if (jRadioButtonAllMatches == null) { |
241 | 0 | jRadioButtonAllMatches = new JRadioButton(); |
242 | 0 | jRadioButtonAllMatches.setText("All Matches"); |
243 | 0 | jRadioButtonAllMatches.addActionListener(new java.awt.event.ActionListener() { |
244 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
245 | 0 | ratingGraphConfig.setType(RatingGraphConfig.Type.displayAllMatches); |
246 | 0 | commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig); |
247 | 0 | } |
248 | |
}); |
249 | |
} |
250 | 0 | return jRadioButtonAllMatches; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
private JRadioButton getJRadioButtonLastXMatches() { |
258 | 0 | if (jRadioButtonLastXMatches == null) { |
259 | 0 | jRadioButtonLastXMatches = new JRadioButton(); |
260 | 0 | jRadioButtonLastXMatches.setText("Last X Matches"); |
261 | 0 | jRadioButtonLastXMatches.addActionListener(new java.awt.event.ActionListener() { |
262 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
263 | 0 | ratingGraphConfig.setType(RatingGraphConfig.Type.displayLastXMatches); |
264 | 0 | commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig); |
265 | 0 | } |
266 | |
}); |
267 | 0 | jRadioButtonLastXMatches |
268 | 0 | .addChangeListener(new javax.swing.event.ChangeListener() { |
269 | |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
270 | 0 | getJTextFieldNumberOfMatches().setEnabled(jRadioButtonLastXMatches.getModel().isSelected()); |
271 | 0 | } |
272 | |
}); |
273 | |
} |
274 | 0 | return jRadioButtonLastXMatches; |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
private JTextField getJTextFieldNumberOfMatches() { |
282 | 0 | if (jTextFieldNumberOfMatches == null) { |
283 | 0 | jTextFieldNumberOfMatches = new JTextField(); |
284 | 0 | jTextFieldNumberOfMatches.setPreferredSize(new Dimension(60, 20)); |
285 | 0 | jTextFieldNumberOfMatches.addKeyListener(new java.awt.event.KeyAdapter() { |
286 | |
public void keyTyped(java.awt.event.KeyEvent e) { |
287 | |
|
288 | 0 | } |
289 | |
}); |
290 | 0 | jTextFieldNumberOfMatches.getDocument().addDocumentListener(this); |
291 | |
} |
292 | 0 | return jTextFieldNumberOfMatches; |
293 | |
} |
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
@Override |
299 | |
public void changedUpdate(DocumentEvent arg0) { |
300 | 0 | updateFromTextChanged(arg0); |
301 | |
|
302 | 0 | } |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
@Override |
308 | |
public void insertUpdate(DocumentEvent arg0) { |
309 | 0 | updateFromTextChanged(arg0); |
310 | 0 | } |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
@Override |
316 | |
public void removeUpdate(DocumentEvent arg0) { |
317 | 0 | updateFromTextChanged(arg0); |
318 | 0 | } |
319 | |
|
320 | |
private void updateFromTextChanged(DocumentEvent documentEvent) { |
321 | 0 | int i = -1; |
322 | |
try { |
323 | 0 | i = Integer.parseInt(jTextFieldNumberOfMatches.getText()); |
324 | 0 | } catch (NumberFormatException e1) { |
325 | 0 | i = -1; |
326 | 0 | } |
327 | 0 | if (i < 1) |
328 | 0 | i = 1; |
329 | |
if (DEBUG) |
330 | |
System.out.println("docChanged(" + i + ")"); |
331 | 0 | ratingGraphConfig.setMatchCount(i); |
332 | 0 | commandDispatcher.dispatch(CommandDispatcher.Command.SET_RATING_GRAPH_CONFIG, ratingGraphConfig); |
333 | |
|
334 | 0 | } |
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
private JRadioButton getJRadioButtonFromDate() { |
342 | 0 | if (jRadioButtonFromDate == null) { |
343 | 0 | jRadioButtonFromDate = new JRadioButton(); |
344 | 0 | jRadioButtonFromDate.setText("From Date"); |
345 | 0 | jRadioButtonFromDate.setEnabled(false); |
346 | 0 | jRadioButtonFromDate.addActionListener(new java.awt.event.ActionListener() { |
347 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
348 | 0 | System.out.println("actionPerformed()"); |
349 | 0 | } |
350 | |
}); |
351 | |
} |
352 | 0 | return jRadioButtonFromDate; |
353 | |
} |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
private JPanel getJPanelOKCancel() { |
361 | 0 | if (jPanelOKCancel == null) { |
362 | 0 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
363 | 0 | gridBagConstraints6.gridx = 1; |
364 | 0 | gridBagConstraints6.anchor = GridBagConstraints.EAST; |
365 | 0 | gridBagConstraints6.insets = new Insets(0, 30, 0, 0); |
366 | 0 | gridBagConstraints6.gridy = 5; |
367 | 0 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
368 | 0 | gridBagConstraints5.gridx = 0; |
369 | 0 | gridBagConstraints5.weighty = 0.5; |
370 | 0 | gridBagConstraints5.fill = GridBagConstraints.BOTH; |
371 | 0 | gridBagConstraints5.anchor = GridBagConstraints.CENTER; |
372 | 0 | gridBagConstraints5.insets = new Insets(0, 0, 0, 20); |
373 | 0 | gridBagConstraints5.weightx = 0.0; |
374 | 0 | gridBagConstraints5.gridy = 5; |
375 | 0 | jPanelOKCancel = new JPanel(); |
376 | 0 | jPanelOKCancel.setLayout(new GridBagLayout()); |
377 | 0 | jPanelOKCancel.add(getJButtonOK(), gridBagConstraints5); |
378 | 0 | jPanelOKCancel.add(getJButtonCancel(), gridBagConstraints6); |
379 | |
} |
380 | 0 | return jPanelOKCancel; |
381 | |
} |
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
private JButton getJButtonOK() { |
389 | 0 | if (jButtonOK == null) { |
390 | 0 | jButtonOK = new JButton(); |
391 | 0 | jButtonOK.setText("OK"); |
392 | 0 | jButtonOK.addActionListener(new java.awt.event.ActionListener() { |
393 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
394 | 0 | okButtonActionPerformed(e); |
395 | 0 | } |
396 | |
}); |
397 | |
} |
398 | 0 | return jButtonOK; |
399 | |
} |
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
private JButton getJButtonCancel() { |
407 | 0 | if (jButtonCancel == null) { |
408 | 0 | jButtonCancel = new JButton(); |
409 | 0 | jButtonCancel.setText("Cancel"); |
410 | 0 | jButtonCancel.addActionListener(new java.awt.event.ActionListener() { |
411 | |
public void actionPerformed(java.awt.event.ActionEvent e) { |
412 | 0 | cancelButtonActionPerformed(e); |
413 | 0 | } |
414 | |
}); |
415 | |
} |
416 | 0 | return jButtonCancel; |
417 | |
} |
418 | |
|
419 | |
} |