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