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