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

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

Sonar/FindBugs - Replace singular fields by local variables

  • 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.JCheckBox;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
14import javax.swing.text.JTextComponent;
15
16import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
17import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
18import org.openstreetmap.josm.gui.widgets.JosmTextField;
19import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.