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 019/** 020 * Panel to enter username and password for the "fully automatic" authorization 021 * procedure. 022 * 023 * @see AuthorizationProcedure#FULLY_AUTOMATIC 024 */ 025public class FullyAutomaticPropertiesPanel extends JPanel { 026 027 private final JosmTextField tfUserName = new JosmTextField(); 028 private final JosmPasswordField tfPassword = new JosmPasswordField(); 029 030 /** 031 * Constructs a new {@code FullyAutomaticPropertiesPanel}. 032 */ 033 public FullyAutomaticPropertiesPanel() { 034 setLayout(new GridBagLayout()); 035 GridBagConstraints gc = new GridBagConstraints(); 036 setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); 037 038 gc.anchor = GridBagConstraints.NORTHWEST; 039 gc.fill = GridBagConstraints.HORIZONTAL; 040 gc.weightx = 1.0; 041 add(buildUserNamePasswordPanel(), gc); 042 043 gc.gridy = 1; 044 gc.weighty = 1.0; 045 gc.fill = GridBagConstraints.BOTH; 046 add(new JPanel(), gc); 047 } 048 049 protected final JPanel buildUserNamePasswordPanel() { 050 JPanel pnl = new JPanel(new GridBagLayout()); 051 GridBagConstraints gc = new GridBagConstraints(); 052 053 gc.anchor = GridBagConstraints.NORTHWEST; 054 gc.fill = GridBagConstraints.HORIZONTAL; 055 gc.weightx = 0.0; 056 gc.insets = new Insets(0, 0, 3, 3); 057 pnl.add(new JLabel(tr("Username: ")), gc); 058 059 gc.gridx = 1; 060 gc.weightx = 1.0; 061 pnl.add(tfUserName, gc); 062 SelectAllOnFocusGainedDecorator.decorate(tfUserName); 063 UserNameValidator valUserName = new UserNameValidator(tfUserName); 064 valUserName.validate(); 065 066 gc.anchor = GridBagConstraints.NORTHWEST; 067 gc.fill = GridBagConstraints.HORIZONTAL; 068 gc.gridy = 1; 069 gc.gridx = 0; 070 gc.weightx = 0.0; 071 pnl.add(new JLabel(tr("Password: ")), gc); 072 073 gc.gridx = 1; 074 gc.weightx = 1.0; 075 pnl.add(tfPassword, gc); 076 SelectAllOnFocusGainedDecorator.decorate(tfPassword); 077 078 return pnl; 079 } 080}