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

Last change on this file since 4147 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

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