1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.oauth;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagConstraints;
|
---|
7 | import java.awt.GridBagLayout;
|
---|
8 | import java.awt.Insets;
|
---|
9 |
|
---|
10 | import javax.swing.BorderFactory;
|
---|
11 | import javax.swing.JLabel;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.text.JTextComponent;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
|
---|
16 | import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
|
---|
17 | import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
---|
18 | import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
|
---|
19 |
|
---|
20 | public 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 | }
|
---|