source: josm/trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticPropertiesPanel.java@ 8836

Last change on this file since 8836 was 8836, checked in by Don-vip, 9 years ago

fix Checkstyle issues

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.oauth;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagConstraints;
7import java.awt.GridBagLayout;
8import java.awt.Insets;
9
10import javax.swing.BorderFactory;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.text.JTextComponent;
14
15import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
16import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
17import org.openstreetmap.josm.gui.widgets.JosmTextField;
18import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
19
20public class FullyAutomaticPropertiesPanel extends JPanel {
21
22 private JosmTextField tfUserName;
23 private JosmPasswordField tfPassword;
24
25 protected final JPanel buildUserNamePasswordPanel() {
26 JPanel pnl = new JPanel(new GridBagLayout());
27 GridBagConstraints gc = new GridBagConstraints();
28
29 gc.anchor = GridBagConstraints.NORTHWEST;
30 gc.fill = GridBagConstraints.HORIZONTAL;
31 gc.weightx = 0.0;
32 gc.insets = new Insets(0, 0, 3, 3);
33 pnl.add(new JLabel(tr("Username: ")), gc);
34
35 gc.gridx = 1;
36 gc.weightx = 1.0;
37 pnl.add(tfUserName = new JosmTextField(), gc);
38 SelectAllOnFocusGainedDecorator.decorate(tfUserName);
39 UserNameValidator valUserName = new UserNameValidator(tfUserName);
40 valUserName.validate();
41
42 gc.anchor = GridBagConstraints.NORTHWEST;
43 gc.fill = GridBagConstraints.HORIZONTAL;
44 gc.gridy = 1;
45 gc.gridx = 0;
46 gc.weightx = 0.0;
47 pnl.add(new JLabel(tr("Password: ")), gc);
48
49 gc.gridx = 1;
50 gc.weightx = 1.0;
51 pnl.add(tfPassword = new JosmPasswordField(), gc);
52 SelectAllOnFocusGainedDecorator.decorate(tfPassword);
53
54 return pnl;
55 }
56
57 /**
58 * Constructs a new {@code FullyAutomaticPropertiesPanel}.
59 */
60 public FullyAutomaticPropertiesPanel() {
61 setLayout(new GridBagLayout());
62 GridBagConstraints gc = new GridBagConstraints();
63 setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
64
65 gc.anchor = GridBagConstraints.NORTHWEST;
66 gc.fill = GridBagConstraints.HORIZONTAL;
67 gc.weightx = 1.0;
68 add(buildUserNamePasswordPanel(), gc);
69
70 gc.gridy = 1;
71 gc.weighty = 1.0;
72 gc.fill = GridBagConstraints.BOTH;
73 add(new JPanel(), gc);
74 }
75
76 private static class UserNameValidator extends AbstractTextComponentValidator {
77
78 UserNameValidator(JTextComponent tc) {
79 super(tc);
80 }
81
82 @Override
83 public boolean isValid() {
84 return !getComponent().getText().trim().isEmpty();
85 }
86
87 @Override
88 public void validate() {
89 if (isValid()) {
90 feedbackValid(tr("Please enter your OSM user name"));
91 } else {
92 feedbackInvalid(tr("The user name cannot be empty. Please enter your OSM user name"));
93 }
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.