View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.xml.registry.client.browser.registration; 11 12 import java.awt.GridBagConstraints; 13 import java.awt.GridBagLayout; 14 15 import javax.swing.BorderFactory; 16 import javax.swing.JLabel; 17 import javax.swing.JOptionPane; 18 import javax.swing.JPanel; 19 import javax.swing.JPasswordField; 20 import javax.swing.JTextField; 21 import javax.swing.SwingConstants; 22 import javax.swing.event.DocumentEvent; 23 import javax.swing.event.DocumentListener; 24 import javax.swing.text.Document; 25 import javax.xml.registry.JAXRException; 26 27 import com.sun.xml.registry.client.browser.swing.RegistryDocumentListener; 28 import com.sun.xml.registry.client.browser.swing.RegistryMappedPanel; 29 30 /*** 31 * Panel for User 32 * 33 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 34 * @author Fabian Ritzmann 35 */ 36 public class UserRegistrationPanel 37 extends JPanel { 38 39 private final JPanel panel; 40 private final UserModel model; 41 42 43 /*** 44 * Extends UserPanel to add fields to get alias and password 45 */ 46 public UserRegistrationPanel(UserModel user) throws JAXRException { 47 48 super(); 49 this.panel = this; 50 this.model = user; 51 52 GridBagLayout gbl = new GridBagLayout(); 53 GridBagConstraints c = new GridBagConstraints(); 54 setLayout(gbl); 55 56 setBorder(BorderFactory.createTitledBorder("User Details")); 57 58 //PersonNamePanel 59 PersonNamePanel personNamePanel = 60 new PersonNamePanel(user.getPersonNameModel()); 61 personNamePanel.setBorder(BorderFactory.createTitledBorder("Name")); 62 RegistryMappedPanel.setConstraints(personNamePanel, c, gbl, 63 0, 0, 1, 0.5, 64 GridBagConstraints.BOTH, 65 GridBagConstraints.WEST); 66 add(personNamePanel); 67 68 //EmailAddressPanel 69 EmailAddressPanel emailPanel = 70 new EmailAddressPanel(user.getEmailAddressModel()); 71 emailPanel.setBorder(BorderFactory.createTitledBorder("Email Address")); 72 RegistryMappedPanel.setConstraints(emailPanel, c, gbl, 73 1, 0, 1, 0.5, 74 GridBagConstraints.BOTH, 75 GridBagConstraints.WEST); 76 add(emailPanel); 77 78 //PostalAddressPanel 79 PostalAddressPanel addressPanel = 80 new PostalAddressPanel(user.getPostalAddressModel()); 81 addressPanel.setBorder(BorderFactory.createTitledBorder("Postal Address")); 82 RegistryMappedPanel.setConstraints(addressPanel, c, gbl, 83 0, 1, 1, 0.5, 84 GridBagConstraints.BOTH, 85 GridBagConstraints.WEST); 86 add(addressPanel); 87 88 //TelephoneNumberPanel 89 TelephoneNumberPanel phonePanel = 90 new TelephoneNumberPanel(user.getTelephoneNumberModel()); 91 phonePanel.setBorder(BorderFactory.createTitledBorder("Telephone Number")); 92 RegistryMappedPanel.setConstraints(phonePanel, c, gbl, 93 1, 1, 1, 0.5, 94 GridBagConstraints.BOTH, 95 GridBagConstraints.WEST); 96 add(phonePanel); 97 98 JPanel panel = new JPanel(); 99 RegistryMappedPanel.setConstraints(panel, c, gbl, 100 0, 2, 2, 0.5, 101 GridBagConstraints.HORIZONTAL, 102 GridBagConstraints.WEST); 103 add(panel); 104 105 GridBagLayout gbl2 = new GridBagLayout(); 106 GridBagConstraints c2 = new GridBagConstraints(); 107 panel.setLayout(gbl2); 108 109 //aliasLabel 110 JLabel aliasLabel = new JLabel("Keystore Alias:", SwingConstants.LEFT); 111 RegistryMappedPanel.setConstraints(aliasLabel, c2, gbl2, 112 0, 0, 1, 0.0, 113 GridBagConstraints.NONE, 114 GridBagConstraints.WEST); 115 panel.add(aliasLabel); 116 117 JTextField aliasText = new JTextField(); 118 aliasText.getDocument().addDocumentListener(new AliasListener()); 119 RegistryMappedPanel.setConstraints(aliasText, c2, gbl2, 120 0, 1, 1, 0.5, 121 GridBagConstraints.HORIZONTAL, 122 GridBagConstraints.CENTER); 123 panel.add(aliasText); 124 125 JLabel keyPassLabel = new JLabel("Private Key Password:", SwingConstants.LEFT); 126 RegistryMappedPanel.setConstraints(keyPassLabel, c2, gbl2, 127 2, 0, 1, 0.0, 128 GridBagConstraints.NONE, 129 GridBagConstraints.WEST); 130 panel.add(keyPassLabel); 131 132 JPasswordField keyPassText = new JPasswordField(); 133 keyPassText.getDocument().addDocumentListener(new KeyPassListener()); 134 RegistryMappedPanel.setConstraints(keyPassText, c2, gbl2, 135 2, 1, 1, 0.5, 136 GridBagConstraints.HORIZONTAL, 137 GridBagConstraints.CENTER); 138 panel.add(keyPassText); 139 } 140 141 142 public UserModel getUserModel() { 143 return this.model; 144 } 145 146 147 public JPanel getPanel() { 148 return this.panel; 149 } 150 151 152 class AliasListener extends RegistryDocumentListener { 153 154 public AliasListener() { 155 super(getPanel(), "Could not set keystore alias: "); 156 } 157 158 protected void setText(String text) throws JAXRException { 159 getUserModel().setAlias(text); 160 } 161 } 162 163 164 class KeyPassListener extends RegistryDocumentListener { 165 166 public KeyPassListener() { 167 super(getPanel(), "Could not set private key password: "); 168 } 169 170 /*** 171 * The Swing documentation recommends to use char[] instead of String 172 * for passwords for security reasons. That would probably mean that 173 * we have to write our own document and document listener. 174 */ 175 protected void setText(String text) throws JAXRException { 176 getUserModel().setKeyPassword(text.toCharArray()); 177 } 178 } 179 180 }

This page was automatically generated by Maven