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

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

Sonar/Findbugs - Unused Private Fields

  • Property svn:eol-style set to native
File size: 2.9 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 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 public FullyAutomaticPropertiesPanel() {
59 setLayout(new GridBagLayout());
60 GridBagConstraints gc = new GridBagConstraints();
61 setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
62
63 gc.anchor = GridBagConstraints.NORTHWEST;
64 gc.fill = GridBagConstraints.HORIZONTAL;
65 gc.weightx = 1.0;
66 add(buildUserNamePasswordPanel(), gc);
67
68 gc.gridy = 1;
69 gc.weighty = 1.0;
70 gc.fill = GridBagConstraints.BOTH;
71 add(new JPanel(), gc);
72 }
73
74 static private class UserNameValidator extends AbstractTextComponentValidator {
75
76 public UserNameValidator(JTextComponent tc) {
77 super(tc);
78 }
79
80 @Override
81 public boolean isValid() {
82 return getComponent().getText().trim().length() > 0;
83 }
84
85 @Override
86 public void validate() {
87 if (isValid()) {
88 feedbackValid(tr("Please enter your OSM user name"));
89 } else {
90 feedbackInvalid(tr("The user name cannot be empty. Please enter your OSM user name"));
91 }
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.