View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/EmailAddressPanel.java,v 1.9 2003/08/24 22:14:58 farrukh_najmi Exp $ 3 */ 4 package com.sun.xml.registry.client.browser; 5 6 import java.awt.*; 7 import java.awt.event.*; 8 import java.util.*; 9 import javax.xml.registry.*; 10 import javax.xml.registry.infomodel.*; 11 import javax.swing.*; 12 import javax.swing.event.*; 13 14 /*** 15 * Panel for EmailAddress 16 * 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class EmailAddressPanel extends JBPanel { 20 21 JTextField addressText = null; 22 23 String[] emailTypes = { 24 "Office email", 25 "Home email", 26 }; 27 JComboBox typeCombo = null; 28 29 /*** 30 * Used for displaying objects 31 */ 32 public EmailAddressPanel() { 33 GridBagLayout gbl = new GridBagLayout(); 34 GridBagConstraints c = new GridBagConstraints(); 35 setLayout(gbl); 36 37 JLabel addressLabel = new JLabel("Email Address:", SwingConstants.LEFT); 38 c.gridx = 0; 39 c.gridy = 0; 40 c.gridwidth = 1; 41 c.gridheight = 1; 42 c.weightx = 0.0; 43 c.weighty = 0.0; 44 c.fill = GridBagConstraints.NONE; 45 c.anchor = GridBagConstraints.WEST; 46 c.insets = new Insets(4, 4, 0, 4); 47 gbl.setConstraints(addressLabel, c); 48 add(addressLabel); 49 50 addressText = new JTextField(); 51 addressText.setEditable(editable); 52 c.gridx = 0; 53 c.gridy = 1; 54 c.gridwidth = 1; 55 c.gridheight = 1; 56 c.weightx = 0.5; 57 c.weighty = 0.0; 58 c.fill = GridBagConstraints.BOTH; 59 c.anchor = GridBagConstraints.WEST; 60 c.insets = new Insets(4, 4, 0, 4); 61 gbl.setConstraints(addressText, c); 62 add(addressText); 63 64 JLabel typeLabel = new JLabel("Address Type:", SwingConstants.LEFT); 65 c.gridx = 1; 66 c.gridy = 0; 67 c.gridwidth = 1; 68 c.gridheight = 1; 69 c.weightx = 0.0; 70 c.weighty = 0.0; 71 c.fill = GridBagConstraints.NONE; 72 c.anchor = GridBagConstraints.WEST; 73 c.insets = new Insets(4, 4, 0, 4); 74 gbl.setConstraints(typeLabel, c); 75 add(typeLabel); 76 77 typeCombo = new JComboBox(emailTypes); 78 typeCombo.setEditable(true); 79 typeCombo.setEnabled(editable); 80 c.gridx = 1; 81 c.gridy = 1; 82 c.gridwidth = 1; 83 c.gridheight = 1; 84 c.weightx = 0.5; 85 c.weighty = 0.0; 86 c.fill = GridBagConstraints.HORIZONTAL; 87 c.anchor = GridBagConstraints.WEST; 88 c.insets = new Insets(4, 4, 0, 4); 89 gbl.setConstraints(typeCombo, c); 90 add(typeCombo); 91 92 } 93 94 public EmailAddress getEmailAddress() throws JAXRException { 95 EmailAddress email = null; 96 97 if (model != null) { 98 email = (EmailAddress)getModel(); 99 } 100 return email; 101 } 102 103 public void setEmailAddress(EmailAddress email) throws JAXRException { 104 setModel(email); 105 } 106 107 public void setModel(Object obj) throws JAXRException { 108 if (!(obj instanceof EmailAddress)) { 109 throw new InvalidRequestException("Expecting a EmailAddress. Got a " + obj.getClass().getName()); 110 } 111 super.setModel(obj); 112 EmailAddress email = (EmailAddress)obj; 113 114 try { 115 if (email != null) { 116 addressText.setText(email.getAddress()); 117 typeCombo.setSelectedItem((String) email.getType()); 118 } 119 } 120 catch (JAXRException e) { 121 RegistryBrowser.displayError(e); 122 } 123 124 } 125 126 public void setEmailAddress(Object obj) throws JAXRException { 127 if (!(obj instanceof EmailAddress)) { 128 throw new InvalidRequestException("Expecting a EmailAddress. Got a " + obj.getClass().getName()); 129 } 130 super.setModel(obj); 131 132 EmailAddress email = (EmailAddress)obj; 133 134 135 try { 136 if (email != null) { 137 addressText.setText(email.getAddress()); 138 typeCombo.setSelectedItem((String) email.getType()); 139 } 140 } 141 catch (JAXRException e) { 142 RegistryBrowser.displayError(e); 143 } 144 145 } 146 147 public Object getModel() throws JAXRException { 148 super.getModel(); 149 150 if (model != null) { 151 EmailAddress emailAddress = (EmailAddress)model; 152 153 emailAddress.setAddress(addressText.getText()); 154 155 emailAddress.setType((String)(typeCombo.getSelectedItem())); 156 RegistryBrowser.getInstance().getRootPane().updateUI(); 157 } 158 159 return model; 160 } 161 162 protected void validateInput() throws JAXRException { 163 super.validateInput(); 164 EmailAddress emailAddress = (EmailAddress)model; 165 } 166 167 public void clear() throws JAXRException { 168 super.clear(); 169 addressText.setText(""); 170 typeCombo.setSelectedIndex(0); 171 } 172 173 /*** 174 * Sets whether this dialog is read-only or editable. 175 */ 176 public void setEditable(boolean editable) { 177 super.setEditable(editable); 178 179 addressText.setEditable(editable); 180 typeCombo.setEnabled(editable); 181 } 182 183 184 }

This page was automatically generated by Maven