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.JCheckBox;
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 | import javax.swing.JPasswordField;
|
---|
15 | import javax.swing.JTextField;
|
---|
16 | import javax.swing.text.JTextComponent;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
|
---|
19 | import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
|
---|
20 |
|
---|
21 | public class FullyAutomaticPropertiesPanel extends JPanel {
|
---|
22 |
|
---|
23 | private JTextField tfUserName;
|
---|
24 | private JPasswordField tfPassword;
|
---|
25 | private UserNameValidator valUserName;
|
---|
26 |
|
---|
27 | private JCheckBox cbWriteMapData;
|
---|
28 | private JCheckBox cbWriteGpsTraces;
|
---|
29 | private JCheckBox cbReadGpsTraces;
|
---|
30 |
|
---|
31 |
|
---|
32 | protected JPanel buildUserNamePasswordPanel() {
|
---|
33 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
34 | GridBagConstraints gc = new GridBagConstraints();
|
---|
35 |
|
---|
36 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
37 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
38 | gc.weightx = 0.0;
|
---|
39 | gc.insets = new Insets(0,0,3,3);
|
---|
40 | pnl.add(new JLabel(tr("Username: ")), gc);
|
---|
41 |
|
---|
42 | gc.gridx = 1;
|
---|
43 | gc.weightx = 1.0;
|
---|
44 | pnl.add(tfUserName = new JTextField(), gc);
|
---|
45 | SelectAllOnFocusGainedDecorator.decorate(tfUserName);
|
---|
46 | valUserName = new UserNameValidator(tfUserName);
|
---|
47 | valUserName.validate();
|
---|
48 |
|
---|
49 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
50 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
51 | gc.gridy = 1;
|
---|
52 | gc.gridx = 0;
|
---|
53 | gc.weightx = 0.0;
|
---|
54 | pnl.add(new JLabel(tr("Password: ")), gc);
|
---|
55 |
|
---|
56 | gc.gridx = 1;
|
---|
57 | gc.weightx = 1.0;
|
---|
58 | pnl.add(tfPassword = new JPasswordField(), gc);
|
---|
59 | SelectAllOnFocusGainedDecorator.decorate(tfPassword);
|
---|
60 |
|
---|
61 | return pnl;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | public FullyAutomaticPropertiesPanel() {
|
---|
66 | setLayout(new GridBagLayout());
|
---|
67 | GridBagConstraints gc = new GridBagConstraints();
|
---|
68 | setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
|
---|
69 |
|
---|
70 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
71 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
72 | gc.weightx = 1.0;
|
---|
73 | add(buildUserNamePasswordPanel(), gc);
|
---|
74 |
|
---|
75 | gc.gridy = 1;
|
---|
76 | gc.weighty = 1.0;
|
---|
77 | gc.fill = GridBagConstraints.BOTH;
|
---|
78 | add(new JPanel(), gc);
|
---|
79 | }
|
---|
80 |
|
---|
81 | static private class UserNameValidator extends AbstractTextComponentValidator {
|
---|
82 |
|
---|
83 | public UserNameValidator(JTextComponent tc) {
|
---|
84 | super(tc);
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public boolean isValid() {
|
---|
89 | return getComponent().getText().trim().length() > 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public void validate() {
|
---|
94 | if (isValid()) {
|
---|
95 | feedbackValid(tr("Please enter your OSM user name"));
|
---|
96 | } else {
|
---|
97 | feedbackInvalid(tr("The user name cannot be empty. Please enter your OSM user name"));
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|