source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/AdvancedChangesetQueryPanel.java@ 2689

Last change on this file since 2689 was 2689, checked in by Gubaer, 16 years ago

new: Changeset Cache Manager for querying, downloading, browsing, and managing changesets within JOSM. See also Changeset Manager and Changeset Query Dialog

File size: 48.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.changeset.query;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.Color;
8import java.awt.Dimension;
9import java.awt.GridBagConstraints;
10import java.awt.GridBagLayout;
11import java.awt.Insets;
12import java.awt.Rectangle;
13import java.awt.event.ItemEvent;
14import java.awt.event.ItemListener;
15import java.text.DateFormat;
16import java.text.ParseException;
17import java.util.Date;
18import java.util.GregorianCalendar;
19import java.util.Locale;
20
21import javax.swing.BorderFactory;
22import javax.swing.ButtonGroup;
23import javax.swing.JCheckBox;
24import javax.swing.JLabel;
25import javax.swing.JOptionPane;
26import javax.swing.JPanel;
27import javax.swing.JRadioButton;
28import javax.swing.JScrollPane;
29import javax.swing.JTextField;
30import javax.swing.Scrollable;
31import javax.swing.text.JTextComponent;
32
33import org.openstreetmap.josm.Main;
34import org.openstreetmap.josm.gui.HelpAwareOptionPane;
35import org.openstreetmap.josm.gui.JMultilineLabel;
36import org.openstreetmap.josm.gui.JosmUserIdentityManager;
37import org.openstreetmap.josm.gui.help.HelpUtil;
38import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
39import org.openstreetmap.josm.gui.widgets.BoundingBoxSelectionPanel;
40import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
41import org.openstreetmap.josm.io.ChangesetQuery;
42import org.openstreetmap.josm.tools.CheckParameterUtil;
43
44/**
45 * This panel allows to specify a changeset query
46 *
47 */
48public class AdvancedChangesetQueryPanel extends JPanel {
49
50 private JCheckBox cbUserRestriction;
51 private JCheckBox cbOpenAndCloseRestrictions;
52 private JCheckBox cbTimeRestrictions;
53 private JCheckBox cbBoundingBoxRestriction;
54 private UserRestrictionPanel pnlUserRestriction;
55 private OpenAndCloseStateRestrictionPanel pnlOpenAndCloseRestriction;
56 private TimeRestrictionPanel pnlTimeRestriction;
57 private BBoxRestrictionPanel pnlBoundingBoxRestriction;
58
59 protected JPanel buildQueryPanel() {
60 ItemListener stateChangeHandler = new RestrictionGroupStateChangeHandler();
61 JPanel pnl = new QuerySpecificationPanel();
62 pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
63 pnl.setLayout(new GridBagLayout());
64 GridBagConstraints gc = new GridBagConstraints();
65
66 // -- select changesets by a specific user
67 //
68 gc.anchor = GridBagConstraints.NORTHWEST;
69 gc.weightx = 0.0;
70 gc.fill = GridBagConstraints.HORIZONTAL;
71 pnl.add(cbUserRestriction = new JCheckBox(), gc);
72 cbUserRestriction.addItemListener(stateChangeHandler);
73
74 gc.gridx = 1;
75 gc.weightx = 1.0;
76 pnl.add(new JMultilineLabel(tr("Select changesets owned by specific users")),gc);
77
78 gc.gridy = 1;
79 gc.gridx = 1;
80 gc.weightx = 1.0;
81 pnl.add(pnlUserRestriction = new UserRestrictionPanel(), gc);
82
83 // -- restricting the query to open and closed changesets
84 //
85 gc.gridy = 2;
86 gc.gridx = 0;
87 gc.anchor = GridBagConstraints.NORTHWEST;
88 gc.weightx = 0.0;
89 gc.fill = GridBagConstraints.HORIZONTAL;
90 pnl.add(cbOpenAndCloseRestrictions = new JCheckBox(), gc);
91 cbOpenAndCloseRestrictions.addItemListener(stateChangeHandler);
92
93 gc.gridx = 1;
94 gc.weightx = 1.0;
95 pnl.add(new JMultilineLabel(tr("Select changesets depending on whether they are open or closed")),gc);
96
97 gc.gridy = 3;
98 gc.gridx = 1;
99 gc.weightx = 1.0;
100 pnl.add(pnlOpenAndCloseRestriction = new OpenAndCloseStateRestrictionPanel(), gc);
101
102 // -- restricting the query to a specific time
103 //
104 gc.gridy = 4;
105 gc.gridx = 0;
106 gc.anchor = GridBagConstraints.NORTHWEST;
107 gc.weightx = 0.0;
108 gc.fill = GridBagConstraints.HORIZONTAL;
109 pnl.add(cbTimeRestrictions = new JCheckBox(), gc);
110 cbTimeRestrictions.addItemListener(stateChangeHandler);
111
112 gc.gridx = 1;
113 gc.weightx = 1.0;
114 pnl.add(new JMultilineLabel(tr("Select changesets based on the date/time they have been created or closed")),gc);
115
116 gc.gridy = 5;
117 gc.gridx = 1;
118 gc.weightx = 1.0;
119 pnl.add(pnlTimeRestriction = new TimeRestrictionPanel(), gc);
120
121
122 // -- restricting the query to a specific bounding box
123 //
124 gc.gridy = 6;
125 gc.gridx = 0;
126 gc.anchor = GridBagConstraints.NORTHWEST;
127 gc.weightx = 0.0;
128 gc.fill = GridBagConstraints.HORIZONTAL;
129 pnl.add(cbBoundingBoxRestriction = new JCheckBox(), gc);
130 cbBoundingBoxRestriction.addItemListener(stateChangeHandler);
131
132 gc.gridx = 1;
133 gc.weightx = 1.0;
134 pnl.add(new JMultilineLabel(tr("Select only changesets related to a specific bounding box")),gc);
135
136 gc.gridy = 7;
137 gc.gridx = 1;
138 gc.weightx = 1.0;
139 pnl.add(pnlBoundingBoxRestriction = new BBoxRestrictionPanel(), gc);
140
141
142 gc.gridy = 8;
143 gc.gridx = 0;
144 gc.gridwidth = 2;
145 gc.fill =GridBagConstraints.BOTH;
146 gc.weightx = 1.0;
147 gc.weighty = 1.0;
148 pnl.add(new JPanel(), gc);
149
150 return pnl;
151 }
152
153 protected void build() {
154 setLayout(new BorderLayout());
155 JScrollPane spQueryPanel = new JScrollPane(buildQueryPanel());
156 add(spQueryPanel, BorderLayout.CENTER);
157 spQueryPanel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
158 spQueryPanel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
159
160 }
161
162 public AdvancedChangesetQueryPanel() {
163 build();
164 }
165
166 public void startUserInput() {
167 restoreFromSettings();
168 pnlBoundingBoxRestriction.setVisible(cbBoundingBoxRestriction.isSelected());
169 pnlOpenAndCloseRestriction.setVisible(cbOpenAndCloseRestrictions.isSelected());
170 pnlTimeRestriction.setVisible(cbTimeRestrictions.isSelected());
171 pnlUserRestriction.setVisible(cbUserRestriction.isSelected());
172 pnlOpenAndCloseRestriction.startUserInput();
173 pnlUserRestriction.startUserInput();
174 pnlTimeRestriction.startUserInput();
175 }
176
177 public void displayMessageIfInvalid() {
178 if (cbUserRestriction.isSelected()) {
179 if (! pnlUserRestriction.isValidChangesetQuery()) {
180 pnlUserRestriction.displayMessageIfInvalid();
181 }
182 } else if (cbTimeRestrictions.isSelected()) {
183 if (!pnlTimeRestriction.isValidChangesetQuery()) {
184 pnlTimeRestriction.displayMessageIfInvalid();
185 }
186 } else if (cbBoundingBoxRestriction.isSelected()) {
187 if (!pnlBoundingBoxRestriction.isValidChangesetQuery()) {
188 pnlBoundingBoxRestriction.displayMessageIfInvalid();
189 }
190 }
191 }
192
193 /**
194 * Builds the changeset query based on the data entered in the form.
195 *
196 * @return the changeset query. null, if the data entered doesn't represent
197 * a valid changeset query.
198 */
199 public ChangesetQuery buildChangesetQuery() {
200 ChangesetQuery query = new ChangesetQuery();
201 if (cbUserRestriction.isSelected()) {
202 if (! pnlUserRestriction.isValidChangesetQuery())
203 return null;
204 pnlUserRestriction.fillInQuery(query);
205 }
206 if (cbOpenAndCloseRestrictions.isSelected()) {
207 // don't have to check whether it's valid. It always is.
208 pnlOpenAndCloseRestriction.fillInQuery(query);
209 }
210 if (cbBoundingBoxRestriction.isSelected()) {
211 if (!pnlBoundingBoxRestriction.isValidChangesetQuery())
212 return null;
213 pnlBoundingBoxRestriction.fillInQuery(query);
214 }
215 if (cbTimeRestrictions.isSelected()) {
216 if (!pnlTimeRestriction.isValidChangesetQuery())
217 return null;
218 pnlTimeRestriction.fillInQuery(query);
219 }
220 return query;
221 }
222
223 public void rememberSettings() {
224 Main.pref.put("changeset-query.advanced.user-restrictions", cbUserRestriction.isSelected());
225 Main.pref.put("changeset-query.advanced.open-restrictions", cbOpenAndCloseRestrictions.isSelected());
226 Main.pref.put("changeset-query.advanced.time-restrictions", cbTimeRestrictions.isSelected());
227 Main.pref.put("changeset-query.advanced.bbox-restrictions", cbBoundingBoxRestriction.isSelected());
228
229 pnlUserRestriction.rememberSettings();
230 pnlOpenAndCloseRestriction.rememberSettings();
231 pnlTimeRestriction.rememberSettings();
232 }
233
234 public void restoreFromSettings() {
235 cbUserRestriction.setSelected(Main.pref.getBoolean("changeset-query.advanced.user-restrictions", false));
236 cbOpenAndCloseRestrictions.setSelected(Main.pref.getBoolean("changeset-query.advanced.open-restrictions", false));
237 cbTimeRestrictions.setSelected(Main.pref.getBoolean("changeset-query.advanced.time-restrictions", false));
238 cbBoundingBoxRestriction.setSelected(Main.pref.getBoolean("changeset-query.advanced.bbox-restrictions", false));
239 }
240
241 class RestrictionGroupStateChangeHandler implements ItemListener {
242 protected void userRestrictionStateChanged() {
243 if (pnlUserRestriction == null) return;
244 pnlUserRestriction.setVisible(cbUserRestriction.isSelected());
245 }
246
247 protected void openCloseRestrictionStateChanged() {
248 if (pnlOpenAndCloseRestriction == null) return;
249 pnlOpenAndCloseRestriction.setVisible(cbOpenAndCloseRestrictions.isSelected());
250 }
251
252 protected void timeRestrictionsStateChanged() {
253 if (pnlTimeRestriction == null) return;
254 pnlTimeRestriction.setVisible(cbTimeRestrictions.isSelected());
255 }
256
257 protected void boundingBoxRestrictionChanged() {
258 if (pnlBoundingBoxRestriction == null) return;
259 pnlBoundingBoxRestriction.setVisible(cbBoundingBoxRestriction.isSelected());
260 }
261
262 public void itemStateChanged(ItemEvent e) {
263 if (e.getSource() == cbUserRestriction) {
264 userRestrictionStateChanged();
265 } else if (e.getSource() == cbOpenAndCloseRestrictions) {
266 openCloseRestrictionStateChanged();
267 } else if (e.getSource() == cbTimeRestrictions) {
268 timeRestrictionsStateChanged();
269 } else if (e.getSource() == cbBoundingBoxRestriction) {
270 boundingBoxRestrictionChanged();
271 }
272 validate();
273 repaint();
274 }
275 }
276
277 /**
278 * This is the panel for selecting whether the changeset query should be restricted to
279 * open or closed changesets
280 */
281 static private class OpenAndCloseStateRestrictionPanel extends JPanel {
282
283 private JRadioButton rbOpenOnly;
284 private JRadioButton rbClosedOnly;
285 private JRadioButton rbBoth;
286
287 protected void build() {
288 setLayout(new GridBagLayout());
289 setBorder(BorderFactory.createCompoundBorder(
290 BorderFactory.createEmptyBorder(3,3,3,3),
291 BorderFactory.createCompoundBorder(
292 BorderFactory.createLineBorder(Color.GRAY),
293 BorderFactory.createEmptyBorder(5,5,5,5)
294 )
295 ));
296 GridBagConstraints gc = new GridBagConstraints();
297 gc.anchor = GridBagConstraints.NORTHWEST;
298 gc.fill = GridBagConstraints.HORIZONTAL;
299 gc.weightx = 0.0;
300 add(rbOpenOnly = new JRadioButton(), gc);
301
302 gc.gridx = 1;
303 gc.weightx = 1.0;
304 add(new JMultilineLabel(tr("Query open changesets only")), gc);
305
306 gc.gridy = 1;
307 gc.gridx = 0;
308 gc.weightx = 0.0;
309 add(rbClosedOnly = new JRadioButton(), gc);
310
311 gc.gridx = 1;
312 gc.weightx = 1.0;
313 add(new JMultilineLabel(tr("Query closed changesets only")), gc);
314
315 gc.gridy = 2;
316 gc.gridx = 0;
317 gc.weightx = 0.0;
318 add(rbBoth = new JRadioButton(), gc);
319
320 gc.gridx = 1;
321 gc.weightx = 1.0;
322 add(new JMultilineLabel(tr("Query both open and closed changesets")), gc);
323
324 ButtonGroup bgRestrictions = new ButtonGroup();
325 bgRestrictions.add(rbBoth);
326 bgRestrictions.add(rbClosedOnly);
327 bgRestrictions.add(rbOpenOnly);
328 }
329
330 public OpenAndCloseStateRestrictionPanel() {
331 build();
332 }
333
334 public void startUserInput() {
335 restoreFromSettings();
336 }
337
338 public void fillInQuery(ChangesetQuery query) {
339 if (rbBoth.isSelected()) {
340 query.beingClosed(true);
341 query.beingOpen(true);
342 } else if (rbOpenOnly.isSelected()) {
343 query.beingOpen(true);
344 } else if (rbClosedOnly.isSelected()) {
345 query.beingClosed(true);
346 }
347 }
348
349 public void rememberSettings() {
350 String prefRoot = "changeset-query.advanced.open-restrictions";
351 if (rbBoth.isSelected()) {
352 Main.pref.put(prefRoot + ".query-type", "both");
353 } else if (rbOpenOnly.isSelected()) {
354 Main.pref.put(prefRoot + ".query-type", "open");
355 } else if (rbClosedOnly.isSelected()) {
356 Main.pref.put(prefRoot + ".query-type", "closed");
357 }
358 }
359
360 public void restoreFromSettings() {
361 String prefRoot = "changeset-query.advanced.open-restrictions";
362 String v = Main.pref.get(prefRoot + ".query-type", "open");
363 rbBoth.setSelected(v.equals("both"));
364 rbOpenOnly.setSelected(v.equals("open"));
365 rbClosedOnly.setSelected(v.equals("closed"));
366 }
367 }
368
369 /**
370 * This is the panel for selecting whether the query should be restricted to a specific
371 * user
372 *
373 */
374 static private class UserRestrictionPanel extends JPanel {
375 private ButtonGroup bgUserRestrictions;
376 private JRadioButton rbRestrictToMyself;
377 private JRadioButton rbRestrictToUid;
378 private JRadioButton rbRestrictToUserName;
379 private JTextField tfUid;
380 private UidInputFieldValidator valUid;
381 private JTextField tfUserName;
382 private UserNameInputValidator valUserName;
383 private JMultilineLabel lblRestrictedToMyself;
384
385 protected JPanel buildUidInputPanel() {
386 JPanel pnl = new JPanel(new GridBagLayout());
387 GridBagConstraints gc = new GridBagConstraints();
388 gc.fill = GridBagConstraints.HORIZONTAL;
389 gc.weightx = 0.0;
390 gc.insets = new Insets(0,0,0,3);
391 pnl.add(new JLabel(tr("User ID: ")), gc);
392
393 gc.gridx = 1;
394 pnl.add(tfUid = new JTextField(10),gc);
395 SelectAllOnFocusGainedDecorator.decorate(tfUid);
396 valUid = UidInputFieldValidator.decorate(tfUid);
397
398 // grab remaining space
399 gc.gridx = 2;
400 gc.weightx = 1.0;
401 pnl.add(new JPanel(), gc);
402 return pnl;
403 }
404
405 protected JPanel buildUserNameInputPanel() {
406 JPanel pnl = new JPanel(new GridBagLayout());
407 GridBagConstraints gc = new GridBagConstraints();
408 gc.fill = GridBagConstraints.HORIZONTAL;
409 gc.weightx = 0.0;
410 gc.insets = new Insets(0,0,0,3);
411 pnl.add(new JLabel(tr("User name: ")), gc);
412
413 gc.gridx = 1;
414 pnl.add(tfUserName = new JTextField(10),gc);
415 SelectAllOnFocusGainedDecorator.decorate(tfUserName);
416 valUserName = UserNameInputValidator.decorate(tfUserName);
417
418 // grab remaining space
419 gc.gridx = 2;
420 gc.weightx = 1.0;
421 pnl.add(new JPanel(), gc);
422 return pnl;
423 }
424
425 protected void build() {
426 setLayout(new GridBagLayout());
427 setBorder(BorderFactory.createCompoundBorder(
428 BorderFactory.createEmptyBorder(3,3,3,3),
429 BorderFactory.createCompoundBorder(
430 BorderFactory.createLineBorder(Color.GRAY),
431 BorderFactory.createEmptyBorder(5,5,5,5)
432 )
433 ));
434
435 ItemListener userRestrictionChangeHandler = new UserRestrictionChangedHandler();
436 GridBagConstraints gc = new GridBagConstraints();
437 gc.anchor = GridBagConstraints.NORTHWEST;
438 gc.gridx = 0;
439 gc.fill= GridBagConstraints.HORIZONTAL;
440 gc.weightx = 0.0;
441 add(rbRestrictToMyself = new JRadioButton(), gc);
442 rbRestrictToMyself.addItemListener(userRestrictionChangeHandler);
443
444 gc.gridx = 1;
445 gc.fill = GridBagConstraints.HORIZONTAL;
446 gc.weightx = 1.0;
447 add(lblRestrictedToMyself = new JMultilineLabel(tr("Only changesets owned by myself")), gc);
448
449 gc.gridx = 0;
450 gc.gridy = 1;
451 gc.fill= GridBagConstraints.HORIZONTAL;
452 gc.weightx = 0.0;
453 add(rbRestrictToUid = new JRadioButton(), gc);
454 rbRestrictToUid.addItemListener(userRestrictionChangeHandler);
455
456 gc.gridx = 1;
457 gc.fill = GridBagConstraints.HORIZONTAL;
458 gc.weightx = 1.0;
459 add(new JMultilineLabel(tr("Only changesets owned by the user with the following user ID")),gc);
460
461 gc.gridx = 1;
462 gc.gridy = 2;
463 gc.fill = GridBagConstraints.HORIZONTAL;
464 gc.weightx = 1.0;
465 add(buildUidInputPanel(),gc);
466
467 gc.gridx = 0;
468 gc.gridy = 3;
469 gc.fill= GridBagConstraints.HORIZONTAL;
470 gc.weightx = 0.0;
471 add(rbRestrictToUserName = new JRadioButton(), gc);
472 rbRestrictToUserName.addItemListener(userRestrictionChangeHandler);
473
474 gc.gridx = 1;
475 gc.fill = GridBagConstraints.HORIZONTAL;
476 gc.weightx = 1.0;
477 add(new JMultilineLabel(tr("Only changesets owned by the user with the following user name")),gc);
478
479 gc.gridx = 1;
480 gc.gridy = 4;
481 gc.fill = GridBagConstraints.HORIZONTAL;
482 gc.weightx = 1.0;
483 add(buildUserNameInputPanel(),gc);
484
485 bgUserRestrictions = new ButtonGroup();
486 bgUserRestrictions.add(rbRestrictToMyself);
487 bgUserRestrictions.add(rbRestrictToUid);
488 bgUserRestrictions.add(rbRestrictToUserName);
489 }
490
491 public UserRestrictionPanel() {
492 build();
493 }
494
495 public void startUserInput() {
496 if (JosmUserIdentityManager.getInstance().isAnonymous()) {
497 lblRestrictedToMyself.setText("Only changesets owned by myself (disabled. JOSM is currently run by an anonymous user)");
498 rbRestrictToMyself.setEnabled(false);
499 if (rbRestrictToMyself.isSelected()) {
500 rbRestrictToUid.setSelected(true);
501 }
502 } else {
503 lblRestrictedToMyself.setText("Only changesets owned by myself");
504 rbRestrictToMyself.setEnabled(true);
505 rbRestrictToMyself.setSelected(true);
506 }
507 restoreFromSettings();
508 }
509
510 /**
511 * Sets the query restrictions on <code>query</code> for changeset owner based
512 * restrictions.
513 *
514 * @param query the query. Must not be null.
515 * @throws IllegalArgumentException thrown if query is null
516 * @throws IllegalStateException thrown if one of the available values for query parameters in
517 * this panel isn't valid
518 *
519 */
520 public void fillInQuery(ChangesetQuery query) throws IllegalStateException, IllegalArgumentException {
521 CheckParameterUtil.ensureParameterNotNull(query, "query");
522 if (rbRestrictToMyself.isSelected()) {
523 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
524 if (im.isPartiallyIdentified()) {
525 query.forUser(im.getUserName());
526 } else if (im.isFullyIdentified()) {
527 query.forUser(im.getUserId());
528 } else
529 throw new IllegalStateException(tr("Can't restrict changeset query to the current user because the current user is anonymous"));
530 } else if (rbRestrictToUid.isSelected()) {
531 int uid = valUid.getUid();
532 if (uid > 0) {
533 query.forUser(uid);
534 } else
535 throw new IllegalStateException(tr("Current value ''{0}'' for user ID isn''t valid", tfUid.getText()));
536 } else if (rbRestrictToUserName.isSelected()) {
537 if (! valUserName.isValid())
538 throw new IllegalStateException(tr("Can''t restrict the changeset query to the user name ''{0}''", tfUserName.getText()));
539 query.forUser(tfUserName.getText());
540 }
541 }
542
543
544 public boolean isValidChangesetQuery() {
545 if (rbRestrictToUid.isSelected())
546 return valUid.isValid();
547 else if (rbRestrictToUserName.isSelected())
548 return valUserName.isValid();
549 return true;
550 }
551
552 protected void alertInvalidUid() {
553 HelpAwareOptionPane.showOptionDialog(
554 this,
555 tr("Please enter a valid user ID"),
556 tr("Invalid user ID"),
557 JOptionPane.ERROR_MESSAGE,
558 HelpUtil.ht("/Dialog/ChangesetQueryDialog#InvalidUserId")
559 );
560 }
561
562 protected void alertInvalidUserName() {
563 HelpAwareOptionPane.showOptionDialog(
564 this,
565 tr("Please enter a non-empty user name"),
566 tr("Invalid user name"),
567 JOptionPane.ERROR_MESSAGE,
568 HelpUtil.ht("/Dialog/ChangesetQueryDialog#InvalidUserName")
569 );
570 }
571
572 public void displayMessageIfInvalid() {
573 if (rbRestrictToUid.isSelected()) {
574 if (!valUid.isValid()) {
575 alertInvalidUid();
576 }
577 } else if (rbRestrictToUserName.isSelected()) {
578 if (!valUserName.isValid()) {
579 alertInvalidUserName();
580 }
581 }
582 }
583
584 public void rememberSettings() {
585 String prefRoot = "changeset-query.advanced.user-restrictions";
586 if (rbRestrictToMyself.isSelected()) {
587 Main.pref.put(prefRoot + ".query-type", "mine");
588 } else if (rbRestrictToUid.isSelected()) {
589 Main.pref.put(prefRoot + ".query-type", "uid");
590 } else if (rbRestrictToUserName.isSelected()) {
591 Main.pref.put(prefRoot + ".query-type", "username");
592 }
593 Main.pref.put(prefRoot + ".uid", tfUid.getText());
594 Main.pref.put(prefRoot + ".username", tfUserName.getText());
595 }
596
597 public void restoreFromSettings() {
598 String prefRoot = "changeset-query.advanced.user-restrictions";
599 String v = Main.pref.get(prefRoot + ".query-type", "mine");
600 if (v.equals("mine")) {
601 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
602 if (im.isAnonymous()) {
603 rbRestrictToUid.setSelected(true);
604 } else {
605 rbRestrictToMyself.setSelected(true);
606 }
607 } else if (v.equals("uid")) {
608 rbRestrictToUid.setSelected(true);
609 } else if (v.equals("username")) {
610 rbRestrictToUserName.setSelected(true);
611 }
612 tfUid.setText(Main.pref.get(prefRoot + ".uid", ""));
613 if (!valUid.isValid()) {
614 tfUid.setText("");
615 }
616 tfUserName.setText(Main.pref.get(prefRoot + ".username", ""));
617 }
618
619 class UserRestrictionChangedHandler implements ItemListener {
620 public void itemStateChanged(ItemEvent e) {
621 tfUid.setEnabled(rbRestrictToUid.isSelected());
622 tfUserName.setEnabled(rbRestrictToUserName.isSelected());
623 if (rbRestrictToUid.isSelected()) {
624 tfUid.requestFocusInWindow();
625 } else if (rbRestrictToUserName.isSelected()) {
626 tfUserName.requestFocusInWindow();
627 }
628 }
629 }
630 }
631
632 /**
633 * This is the panel to apply a time restriction to the changeset query
634 */
635 static private class TimeRestrictionPanel extends JPanel {
636
637 private JRadioButton rbClosedAfter;
638 private JRadioButton rbClosedAfterAndCreatedBefore;
639 private JTextField tfClosedAfterDate1;
640 private DateValidator valClosedAfterDate1;
641 private JTextField tfClosedAfterTime1;
642 private TimeValidator valClosedAfterTime1;
643 private JTextField tfClosedAfterDate2;
644 private DateValidator valClosedAfterDate2;
645 private JTextField tfClosedAfterTime2;
646 private TimeValidator valClosedAfterTime2;
647 private JTextField tfCreatedBeforeDate;
648 private DateValidator valCreatedBeforeDate;
649 private JTextField tfCreatedBeforeTime;
650 private TimeValidator valCreatedBeforeTime;
651
652 protected JPanel buildClosedAfterInputPanel() {
653 JPanel pnl = new JPanel(new GridBagLayout());
654 GridBagConstraints gc = new GridBagConstraints();
655 gc.fill = GridBagConstraints.HORIZONTAL;
656 gc.weightx = 0.0;
657 gc.insets = new Insets(0,0,0,3);
658 pnl.add(new JLabel(tr("Date: ")), gc);
659
660 gc.gridx = 1;
661 gc.weightx = 0.7;
662 pnl.add(tfClosedAfterDate1 = new JTextField(),gc);
663 SelectAllOnFocusGainedDecorator.decorate(tfClosedAfterDate1);
664 valClosedAfterDate1 = DateValidator.decorate(tfClosedAfterDate1);
665 tfClosedAfterDate1.setToolTipText(valClosedAfterDate1.getStandardTooltipTextAsHtml());
666
667 gc.gridx = 2;
668 gc.weightx = 0.0;
669 pnl.add(new JLabel("Time: "),gc);
670
671 gc.gridx = 3;
672 gc.weightx = 0.3;
673 pnl.add(tfClosedAfterTime1 = new JTextField(),gc);
674 SelectAllOnFocusGainedDecorator.decorate(tfClosedAfterTime1);
675 valClosedAfterTime1 = TimeValidator.decorate(tfClosedAfterTime1);
676 tfClosedAfterTime1.setToolTipText(valClosedAfterTime1.getStandardTooltipTextAsHtml());
677 return pnl;
678 }
679
680 protected JPanel buildClosedAfterAndCreatedBeforeInputPanel() {
681 JPanel pnl = new JPanel(new GridBagLayout());
682 GridBagConstraints gc = new GridBagConstraints();
683 gc.fill = GridBagConstraints.HORIZONTAL;
684 gc.weightx = 0.0;
685 gc.insets = new Insets(0,0,0,3);
686 pnl.add(new JLabel(tr("Closed after - ")), gc);
687
688 gc.gridx = 1;
689 gc.fill = GridBagConstraints.HORIZONTAL;
690 gc.weightx = 0.0;
691 gc.insets = new Insets(0,0,0,3);
692 pnl.add(new JLabel(tr("Date: ")), gc);
693
694 gc.gridx = 2;
695 gc.weightx = 0.7;
696 pnl.add(tfClosedAfterDate2 = new JTextField(),gc);
697 SelectAllOnFocusGainedDecorator.decorate(tfClosedAfterDate2);
698 valClosedAfterDate2 = DateValidator.decorate(tfClosedAfterDate2);
699 tfClosedAfterDate2.setToolTipText(valClosedAfterDate2.getStandardTooltipTextAsHtml());
700 gc.gridx = 3;
701 gc.weightx = 0.0;
702 pnl.add(new JLabel("Time: "),gc);
703
704 gc.gridx = 4;
705 gc.weightx = 0.3;
706 pnl.add(tfClosedAfterTime2 = new JTextField(),gc);
707 SelectAllOnFocusGainedDecorator.decorate(tfClosedAfterTime2);
708 valClosedAfterTime2 = TimeValidator.decorate(tfClosedAfterTime2);
709 tfClosedAfterTime2.setToolTipText(valClosedAfterTime2.getStandardTooltipTextAsHtml());
710
711 gc.gridy = 1;
712 gc.gridx = 0;
713 gc.fill = GridBagConstraints.HORIZONTAL;
714 gc.weightx = 0.0;
715 gc.insets = new Insets(0,0,0,3);
716 pnl.add(new JLabel(tr("Created before - ")), gc);
717
718 gc.gridx = 1;
719 gc.fill = GridBagConstraints.HORIZONTAL;
720 gc.weightx = 0.0;
721 gc.insets = new Insets(0,0,0,3);
722 pnl.add(new JLabel(tr("Date: ")), gc);
723
724 gc.gridx = 2;
725 gc.weightx = 0.7;
726 pnl.add(tfCreatedBeforeDate = new JTextField(),gc);
727 SelectAllOnFocusGainedDecorator.decorate(tfCreatedBeforeDate);
728 valCreatedBeforeDate = DateValidator.decorate(tfCreatedBeforeDate);
729 tfCreatedBeforeDate.setToolTipText(valCreatedBeforeDate.getStandardTooltipTextAsHtml());
730
731 gc.gridx = 3;
732 gc.weightx = 0.0;
733 pnl.add(new JLabel("Time: "),gc);
734
735 gc.gridx = 4;
736 gc.weightx = 0.3;
737 pnl.add(tfCreatedBeforeTime = new JTextField(),gc);
738 SelectAllOnFocusGainedDecorator.decorate(tfCreatedBeforeTime);
739 valCreatedBeforeTime = TimeValidator.decorate(tfCreatedBeforeTime);
740 tfCreatedBeforeTime.setToolTipText(valCreatedBeforeDate.getStandardTooltipTextAsHtml());
741
742 return pnl;
743 }
744
745 protected void build() {
746 setLayout(new GridBagLayout());
747 setBorder(BorderFactory.createCompoundBorder(
748 BorderFactory.createEmptyBorder(3,3,3,3),
749 BorderFactory.createCompoundBorder(
750 BorderFactory.createLineBorder(Color.GRAY),
751 BorderFactory.createEmptyBorder(5,5,5,5)
752 )
753 ));
754
755 // -- changesets closed after a specific date/time
756 //
757 GridBagConstraints gc = new GridBagConstraints();
758 gc.anchor = GridBagConstraints.NORTHWEST;
759 gc.gridx = 0;
760 gc.fill= GridBagConstraints.HORIZONTAL;
761 gc.weightx = 0.0;
762 add(rbClosedAfter = new JRadioButton(), gc);
763
764 gc.gridx = 1;
765 gc.fill = GridBagConstraints.HORIZONTAL;
766 gc.weightx = 1.0;
767 add(new JMultilineLabel(tr("Only changesets closed after the following date/time")), gc);
768
769 gc.gridx = 1;
770 gc.gridy = 1;
771 gc.fill = GridBagConstraints.HORIZONTAL;
772 gc.weightx = 1.0;
773 add(buildClosedAfterInputPanel(),gc);
774
775 // -- changesets closed after a specific date/time and created before a specific date time
776 //
777 gc = new GridBagConstraints();
778 gc.anchor = GridBagConstraints.NORTHWEST;
779 gc.gridy = 2;
780 gc.gridx = 0;
781 gc.fill= GridBagConstraints.HORIZONTAL;
782 gc.weightx = 0.0;
783 add(rbClosedAfterAndCreatedBefore = new JRadioButton(), gc);
784
785 gc.gridx = 1;
786 gc.fill = GridBagConstraints.HORIZONTAL;
787 gc.weightx = 1.0;
788 add(new JMultilineLabel(tr("Only changesets closed after and created before a specific date/time")), gc);
789
790 gc.gridx = 1;
791 gc.gridy = 3;
792 gc.fill = GridBagConstraints.HORIZONTAL;
793 gc.weightx = 1.0;
794 add(buildClosedAfterAndCreatedBeforeInputPanel(),gc);
795
796 ButtonGroup bg = new ButtonGroup();
797 bg.add(rbClosedAfter);
798 bg.add(rbClosedAfterAndCreatedBefore);
799
800 ItemListener restrictionChangeHandler = new TimeRestrictionChangedHandler();
801 rbClosedAfter.addItemListener(restrictionChangeHandler);
802 rbClosedAfterAndCreatedBefore.addItemListener(restrictionChangeHandler);
803
804 rbClosedAfter.setSelected(true);
805 }
806
807 public TimeRestrictionPanel() {
808 build();
809 }
810
811 public boolean isValidChangesetQuery() {
812 if (rbClosedAfter.isSelected())
813 return valClosedAfterDate1.isValid() && valClosedAfterTime1.isValid();
814 else if (rbClosedAfterAndCreatedBefore.isSelected())
815 return valClosedAfterDate2.isValid() && valClosedAfterTime2.isValid()
816 && valCreatedBeforeDate.isValid() && valCreatedBeforeTime.isValid();
817 // should not happen
818 return true;
819 }
820
821 class TimeRestrictionChangedHandler implements ItemListener {
822 public void itemStateChanged(ItemEvent e) {
823 tfClosedAfterDate1.setEnabled(rbClosedAfter.isSelected());
824 tfClosedAfterTime1.setEnabled(rbClosedAfter.isSelected());
825
826 tfClosedAfterDate2.setEnabled(rbClosedAfterAndCreatedBefore.isSelected());
827 tfClosedAfterTime2.setEnabled(rbClosedAfterAndCreatedBefore.isSelected());
828 tfCreatedBeforeDate.setEnabled(rbClosedAfterAndCreatedBefore.isSelected());
829 tfCreatedBeforeTime.setEnabled(rbClosedAfterAndCreatedBefore.isSelected());
830 }
831 }
832
833 public void startUserInput() {
834 restoreFromSettings();
835 }
836
837 public void fillInQuery(ChangesetQuery query) throws IllegalStateException{
838 if (!isValidChangesetQuery())
839 throw new IllegalStateException(tr("Can't build changeset query with time based restrictions. Input isn't valid."));
840 if (rbClosedAfter.isSelected()) {
841 GregorianCalendar cal = new GregorianCalendar();
842 Date d1 = valClosedAfterDate1.getDate();
843 Date d2 = valClosedAfterTime1.getDate();
844 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime()));
845 query.closedAfter(cal.getTime());
846 } else if (rbClosedAfterAndCreatedBefore.isSelected()) {
847 GregorianCalendar cal = new GregorianCalendar();
848 Date d1 = valClosedAfterDate2.getDate();
849 Date d2 = valClosedAfterTime2.getDate();
850 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime()));
851 Date d3 = cal.getTime();
852
853 d1 = valCreatedBeforeDate.getDate();
854 d2 = valCreatedBeforeTime.getDate();
855 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime()));
856 Date d4 = cal.getTime();
857
858 query.closedAfterAndCreatedBefore(d3, d4);
859 }
860 }
861
862 public void displayMessageIfInvalid() {
863 if (isValidChangesetQuery()) return;
864 HelpAwareOptionPane.showOptionDialog(
865 this,
866 tr(
867 "<html>Please enter valid date/time values to restrict<br>"
868 + "the query to a specific time range.</html>"
869 ),
870 tr("Invalid date/time values"),
871 JOptionPane.ERROR_MESSAGE,
872 HelpUtil.ht("/Dialog/ChangesetQueryDialog#InvalidDateTimeValues")
873 );
874 }
875
876
877 public void rememberSettings() {
878 String prefRoot = "changeset-query.advanced.time-restrictions";
879 if (rbClosedAfter.isSelected()) {
880 Main.pref.put(prefRoot + ".query-type", "closed-after");
881 } else if (rbClosedAfterAndCreatedBefore.isSelected()) {
882 Main.pref.put(prefRoot + ".query-type", "closed-after-created-before");
883 }
884 Main.pref.put(prefRoot + ".closed-after.date", tfClosedAfterDate1.getText());
885 Main.pref.put(prefRoot + ".closed-after.time", tfClosedAfterTime1.getText());
886 Main.pref.put(prefRoot + ".closed-created.closed.date", tfClosedAfterDate2.getText());
887 Main.pref.put(prefRoot + ".closed-created.closed.time", tfClosedAfterTime2.getText());
888 Main.pref.put(prefRoot + ".closed-created.created.date", tfCreatedBeforeDate.getText());
889 Main.pref.put(prefRoot + ".closed-created.created.time", tfCreatedBeforeTime.getText());
890 }
891
892 public void restoreFromSettings() {
893 String prefRoot = "changeset-query.advanced.open-restrictions";
894 String v = Main.pref.get(prefRoot + ".query-type", "closed-after");
895 rbClosedAfter.setSelected(v.equals("closed-after"));
896 rbClosedAfterAndCreatedBefore.setSelected(v.equals("closed-after-created-before"));
897 if (!rbClosedAfter.isSelected() && !rbClosedAfterAndCreatedBefore.isSelected()) {
898 rbClosedAfter.setSelected(true);
899 }
900 tfClosedAfterDate1.setText(Main.pref.get(prefRoot + ".closed-after.date", ""));
901 tfClosedAfterTime1.setText(Main.pref.get(prefRoot + ".closed-after.time", ""));
902 tfClosedAfterDate2.setText(Main.pref.get(prefRoot + ".closed-created.closed.date", ""));
903 tfClosedAfterTime2.setText(Main.pref.get(prefRoot + ".closed-created.closed.time", ""));
904 tfCreatedBeforeDate.setText(Main.pref.get(prefRoot + ".closed-created.created.date", ""));
905 tfCreatedBeforeTime.setText(Main.pref.get(prefRoot + ".closed-created.created.time", ""));
906 if (!valClosedAfterDate1.isValid()) {
907 tfClosedAfterDate1.setText("");
908 }
909 if (!valClosedAfterTime1.isValid()) {
910 tfClosedAfterTime1.setText("");
911 }
912 if (!valClosedAfterDate2.isValid()) {
913 tfClosedAfterDate2.setText("");
914 }
915 if (!valClosedAfterTime2.isValid()) {
916 tfClosedAfterTime2.setText("");
917 }
918 if (!valCreatedBeforeDate.isValid()) {
919 tfCreatedBeforeDate.setText("");
920 }
921 if (!valCreatedBeforeTime.isValid()) {
922 tfCreatedBeforeTime.setText("");
923 }
924 }
925 }
926
927 static private class BBoxRestrictionPanel extends BoundingBoxSelectionPanel {
928 public BBoxRestrictionPanel() {
929 setBorder(BorderFactory.createCompoundBorder(
930 BorderFactory.createEmptyBorder(3,3,3,3),
931 BorderFactory.createCompoundBorder(
932 BorderFactory.createLineBorder(Color.GRAY),
933 BorderFactory.createEmptyBorder(5,5,5,5)
934 )
935 ));
936 }
937
938 public boolean isValidChangesetQuery() {
939 return getBoundingBox() != null;
940 }
941
942 public void fillInQuery(ChangesetQuery query) {
943 if (!isValidChangesetQuery())
944 throw new IllegalStateException(tr("Can''t restrict the changeset query to a specific bounding box. The input is invalid."));
945 query.inBbox(getBoundingBox());
946 }
947
948 public void displayMessageIfInvalid() {
949 if (isValidChangesetQuery()) return;
950 HelpAwareOptionPane.showOptionDialog(
951 this,
952 tr(
953 "<html>Please enter valid longitude/latitude values to restrict<br>" +
954 "the changeset query to a specific bounding box.</html>"
955 ),
956 tr("Invalid bounding box"),
957 JOptionPane.ERROR_MESSAGE,
958 HelpUtil.ht("/Dialog/ChangesetQueryDialog#InvalidBoundingBox")
959 );
960 }
961 }
962
963 static private class QuerySpecificationPanel extends JPanel implements Scrollable {
964 public Dimension getPreferredScrollableViewportSize() {
965 return getPreferredSize();
966 }
967
968 public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2) {
969 return 20;
970 }
971
972 public boolean getScrollableTracksViewportHeight() {
973 return false;
974 }
975
976 public boolean getScrollableTracksViewportWidth() {
977 return true;
978 }
979
980 public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2) {
981 return 10;
982 }
983 }
984
985 /**
986 * Validator for user ids entered in in a {@see JTextComponent}.
987 *
988 */
989 static private class UidInputFieldValidator extends AbstractTextComponentValidator {
990 static public UidInputFieldValidator decorate(JTextComponent tc) {
991 return new UidInputFieldValidator(tc);
992 }
993
994 public UidInputFieldValidator(JTextComponent tc) {
995 super(tc);
996 }
997
998 @Override
999 public boolean isValid() {
1000 return getUid() > 0;
1001 }
1002
1003 @Override
1004 public void validate() {
1005 String value = getComponent().getText();
1006 if (value == null || value.trim().length() == 0) {
1007 feedbackInvalid("");
1008 return;
1009 }
1010 try {
1011 int uid = Integer.parseInt(value);
1012 if (uid <= 0) {
1013 feedbackInvalid(tr("The current value isn't a valid user ID. Please enter an integer value > 0"));
1014 return;
1015 }
1016 } catch(NumberFormatException e) {
1017 feedbackInvalid(tr("The current value isn't a valid user ID. Please enter an integer value > 0"));
1018 return;
1019 }
1020 feedbackValid(tr("Please enter an integer value > 0"));
1021 }
1022
1023 public int getUid() {
1024 String value = getComponent().getText();
1025 if (value == null || value.trim().length() == 0) return 0;
1026 try {
1027 int uid = Integer.parseInt(value.trim());
1028 if (uid > 0) return uid;
1029 return 0;
1030 } catch(NumberFormatException e) {
1031 return 0;
1032 }
1033 }
1034 }
1035
1036 static private class UserNameInputValidator extends AbstractTextComponentValidator {
1037 static public UserNameInputValidator decorate(JTextComponent tc) {
1038 return new UserNameInputValidator(tc);
1039 }
1040
1041 public UserNameInputValidator(JTextComponent tc) {
1042 super(tc);
1043 }
1044
1045 @Override
1046 public boolean isValid() {
1047 return getComponent().getText().trim().length() > 0;
1048 }
1049
1050 @Override
1051 public void validate() {
1052 String value = getComponent().getText();
1053 if (value.trim().length() == 0) {
1054 feedbackInvalid(tr("<html>The current value isn't a valid user name.<br>Please enter an non-empty user name.</html>"));
1055 return;
1056 }
1057 feedbackValid(tr("Please enter an non-empty user name"));
1058 }
1059 }
1060
1061 /**
1062 * Validates dates entered as text in in a {@see JTextComponent}. Validates the input
1063 * on the fly and gives feedback about whether the date is valid or not.
1064 *
1065 * Dates can be entered in one of four standard formats defined for the current locale.
1066 */
1067 static private class DateValidator extends AbstractTextComponentValidator {
1068 static public DateValidator decorate(JTextComponent tc) {
1069 return new DateValidator(tc);
1070 }
1071
1072 public DateValidator(JTextComponent tc) {
1073 super(tc);
1074 }
1075
1076 @Override
1077 public boolean isValid() {
1078 return getDate() != null;
1079 }
1080
1081 public String getStandardTooltipTextAsHtml() {
1082 return "<html>" + getStandardTooltipText() + "</html>";
1083 }
1084
1085 public String getStandardTooltipText() {
1086 return tr(
1087 "Please enter a date in the usual format for your locale.<br>"
1088 + "Example: {0}<br>"
1089 + "Example: {1}<br>"
1090 + "Example: {2}<br>"
1091 + "Example: {3}<br>",
1092 DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(new Date()),
1093 DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()),
1094 DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(new Date()),
1095 DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()).format(new Date())
1096 );
1097 }
1098
1099 @Override
1100 public void validate() {
1101 if (!isValid()) {
1102 String msg = "<html>The current value isn't a valid date.<br>" + getStandardTooltipText()+ "</html>";
1103 feedbackInvalid(msg);
1104 return;
1105 } else {
1106 String msg = "<html>" + getStandardTooltipText() + "</html>";
1107 feedbackValid(msg);
1108 }
1109 }
1110
1111 public Date getDate() {
1112 for (int i = 0; i< 4; i++) {
1113 try {
1114 DateFormat df = null;
1115 switch(i) {
1116 case 0: df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); break;
1117 case 1: df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()); break;
1118 case 2: df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()); break;
1119 case 3: df = DateFormat.getDateInstance(DateFormat.FULL,Locale.getDefault()); break;
1120 }
1121 return df.parse(getComponent().getText());
1122 } catch(ParseException e) {
1123 continue;
1124 }
1125 }
1126 return null;
1127 }
1128 }
1129
1130 /**
1131 * Validates time values entered as text in in a {@see JTextComponent}. Validates the input
1132 * on the fly and gives feedback about whether the time value is valid or not.
1133 *
1134 * Time values can be entered in one of four standard formats defined for the current locale.
1135 */
1136 static private class TimeValidator extends AbstractTextComponentValidator {
1137 static public TimeValidator decorate(JTextComponent tc) {
1138 return new TimeValidator(tc);
1139 }
1140
1141 public TimeValidator(JTextComponent tc) {
1142 super(tc);
1143 }
1144
1145 @Override
1146 public boolean isValid() {
1147 if (getComponent().getText().trim().length() == 0) return true;
1148 return getDate() != null;
1149 }
1150
1151 public String getStandardTooltipTextAsHtml() {
1152 return "<html>" + getStandardTooltipText() + "</html>";
1153 }
1154
1155 public String getStandardTooltipText() {
1156 return tr(
1157 "Please enter a valid time in the usual format for your locale.<br>"
1158 + "Example: {0}<br>"
1159 + "Example: {1}<br>"
1160 + "Example: {2}<br>"
1161 + "Example: {3}<br>",
1162 DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(new Date()),
1163 DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()),
1164 DateFormat.getTimeInstance(DateFormat.LONG, Locale.getDefault()).format(new Date()),
1165 DateFormat.getTimeInstance(DateFormat.FULL, Locale.getDefault()).format(new Date())
1166 );
1167 }
1168
1169 @Override
1170 public void validate() {
1171
1172 if (!isValid()) {
1173 String msg = "<html>The current value isn't a valid time.<br>" + getStandardTooltipText() + "</html>";
1174 feedbackInvalid(msg);
1175 return;
1176 } else {
1177 String msg = "<html>" + getStandardTooltipText() + "</html>";
1178 feedbackValid(msg);
1179 }
1180 }
1181
1182 public Date getDate() {
1183 if (getComponent().getText().trim().length() == 0)
1184 return null;
1185
1186 for (int i = 0; i< 4; i++) {
1187 try {
1188 DateFormat df = null;
1189 switch(i) {
1190 case 0: df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()); break;
1191 case 1: df = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.getDefault()); break;
1192 case 2: df = DateFormat.getTimeInstance(DateFormat.LONG, Locale.getDefault()); break;
1193 case 3: df = DateFormat.getTimeInstance(DateFormat.FULL,Locale.getDefault()); break;
1194 }
1195 Date d = df.parse(getComponent().getText());
1196 return d;
1197 } catch(ParseException e) {
1198 continue;
1199 }
1200 }
1201 return null;
1202 }
1203 }
1204}
Note: See TracBrowser for help on using the repository browser.