001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.gui.oauth;
003
004 import static org.openstreetmap.josm.tools.I18n.tr;
005
006 import java.awt.GridBagConstraints;
007 import java.awt.GridBagLayout;
008 import java.awt.Insets;
009
010 import javax.swing.BorderFactory;
011 import javax.swing.JCheckBox;
012 import javax.swing.JLabel;
013 import javax.swing.JPanel;
014 import javax.swing.JPasswordField;
015 import javax.swing.JTextField;
016 import javax.swing.text.JTextComponent;
017
018 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
019 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
020
021 public class FullyAutomaticPropertiesPanel extends JPanel {
022
023 private JTextField tfUserName;
024 private JPasswordField tfPassword;
025 private UserNameValidator valUserName;
026
027 private JCheckBox cbWriteMapData;
028 private JCheckBox cbWriteGpsTraces;
029 private JCheckBox cbReadGpsTraces;
030
031
032 protected JPanel buildUserNamePasswordPanel() {
033 JPanel pnl = new JPanel(new GridBagLayout());
034 GridBagConstraints gc = new GridBagConstraints();
035
036 gc.anchor = GridBagConstraints.NORTHWEST;
037 gc.fill = GridBagConstraints.HORIZONTAL;
038 gc.weightx = 0.0;
039 gc.insets = new Insets(0,0,3,3);
040 pnl.add(new JLabel(tr("Username: ")), gc);
041
042 gc.gridx = 1;
043 gc.weightx = 1.0;
044 pnl.add(tfUserName = new JTextField(), gc);
045 SelectAllOnFocusGainedDecorator.decorate(tfUserName);
046 valUserName = new UserNameValidator(tfUserName);
047 valUserName.validate();
048
049 gc.anchor = GridBagConstraints.NORTHWEST;
050 gc.fill = GridBagConstraints.HORIZONTAL;
051 gc.gridy = 1;
052 gc.gridx = 0;
053 gc.weightx = 0.0;
054 pnl.add(new JLabel(tr("Password: ")), gc);
055
056 gc.gridx = 1;
057 gc.weightx = 1.0;
058 pnl.add(tfPassword = new JPasswordField(), gc);
059 SelectAllOnFocusGainedDecorator.decorate(tfPassword);
060
061 return pnl;
062 }
063
064
065 public FullyAutomaticPropertiesPanel() {
066 setLayout(new GridBagLayout());
067 GridBagConstraints gc = new GridBagConstraints();
068 setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
069
070 gc.anchor = GridBagConstraints.NORTHWEST;
071 gc.fill = GridBagConstraints.HORIZONTAL;
072 gc.weightx = 1.0;
073 add(buildUserNamePasswordPanel(), gc);
074
075 gc.gridy = 1;
076 gc.weighty = 1.0;
077 gc.fill = GridBagConstraints.BOTH;
078 add(new JPanel(), gc);
079 }
080
081 static private class UserNameValidator extends AbstractTextComponentValidator {
082
083 public UserNameValidator(JTextComponent tc) {
084 super(tc);
085 }
086
087 @Override
088 public boolean isValid() {
089 return getComponent().getText().trim().length() > 0;
090 }
091
092 @Override
093 public void validate() {
094 if (isValid()) {
095 feedbackValid(tr("Please enter your OSM user name"));
096 } else {
097 feedbackInvalid(tr("The user name cannot be empty. Please enter your OSM user name"));
098 }
099 }
100 }
101 }