001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.oauth; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.GridBagConstraints; 007import java.awt.GridBagLayout; 008import java.awt.Insets; 009 010import javax.swing.BorderFactory; 011import javax.swing.JLabel; 012import javax.swing.JPanel; 013 014import org.openstreetmap.josm.gui.preferences.server.UserNameValidator; 015import org.openstreetmap.josm.gui.widgets.JosmPasswordField; 016import org.openstreetmap.josm.gui.widgets.JosmTextField; 017import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 018 019public class FullyAutomaticPropertiesPanel extends JPanel { 020 021 private final JosmTextField tfUserName = new JosmTextField(); 022 private final JosmPasswordField tfPassword = new JosmPasswordField(); 023 024 /** 025 * Constructs a new {@code FullyAutomaticPropertiesPanel}. 026 */ 027 public FullyAutomaticPropertiesPanel() { 028 setLayout(new GridBagLayout()); 029 GridBagConstraints gc = new GridBagConstraints(); 030 setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); 031 032 gc.anchor = GridBagConstraints.NORTHWEST; 033 gc.fill = GridBagConstraints.HORIZONTAL; 034 gc.weightx = 1.0; 035 add(buildUserNamePasswordPanel(), gc); 036 037 gc.gridy = 1; 038 gc.weighty = 1.0; 039 gc.fill = GridBagConstraints.BOTH; 040 add(new JPanel(), gc); 041 } 042 043 protected final JPanel buildUserNamePasswordPanel() { 044 JPanel pnl = new JPanel(new GridBagLayout()); 045 GridBagConstraints gc = new GridBagConstraints(); 046 047 gc.anchor = GridBagConstraints.NORTHWEST; 048 gc.fill = GridBagConstraints.HORIZONTAL; 049 gc.weightx = 0.0; 050 gc.insets = new Insets(0, 0, 3, 3); 051 pnl.add(new JLabel(tr("Username: ")), gc); 052 053 gc.gridx = 1; 054 gc.weightx = 1.0; 055 pnl.add(tfUserName, gc); 056 SelectAllOnFocusGainedDecorator.decorate(tfUserName); 057 UserNameValidator valUserName = new UserNameValidator(tfUserName); 058 valUserName.validate(); 059 060 gc.anchor = GridBagConstraints.NORTHWEST; 061 gc.fill = GridBagConstraints.HORIZONTAL; 062 gc.gridy = 1; 063 gc.gridx = 0; 064 gc.weightx = 0.0; 065 pnl.add(new JLabel(tr("Password: ")), gc); 066 067 gc.gridx = 1; 068 gc.weightx = 1.0; 069 pnl.add(tfPassword, gc); 070 SelectAllOnFocusGainedDecorator.decorate(tfPassword); 071 072 return pnl; 073 } 074}