source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/DefaultTextComponentValidator.java@ 11921

Last change on this file since 11921 was 10073, checked in by Don-vip, 8 years ago

refactor duplicated code

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import javax.swing.text.JTextComponent;
5
6/**
7 * Default text component validator that only checks that an input field is not empty.
8 * @since 10073
9 */
10public class DefaultTextComponentValidator extends AbstractTextComponentValidator {
11
12 private final String validFeedback;
13 private final String invalidFeedback;
14
15 /**
16 * Constructs a new {@code DefaultTextComponentValidator}.
17 * @param tc he text component. Must not be null.
18 * @param validFeedback text displayed for valid feedback
19 * @param invalidFeedback text displayed for invalid feedback
20 */
21 public DefaultTextComponentValidator(JTextComponent tc, String validFeedback, String invalidFeedback) {
22 super(tc);
23 this.validFeedback = validFeedback;
24 this.invalidFeedback = invalidFeedback;
25 }
26
27 @Override
28 public boolean isValid() {
29 return !getComponent().getText().trim().isEmpty();
30 }
31
32 @Override
33 public void validate() {
34 if (isValid()) {
35 feedbackValid(validFeedback);
36 } else {
37 feedbackInvalid(invalidFeedback);
38 }
39 }
40}
Note: See TracBrowser for help on using the repository browser.