View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/TelephoneNumberPanel.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 TelephoneNumber 16 * 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class TelephoneNumberPanel extends JBPanel { 20 21 JTextField countryCodeText = null; 22 JTextField areaCodeText = null; 23 JTextField numberText = null; 24 JTextField extensionText = null; 25 JTextField urlText = null; 26 27 String[] phoneTypes = { 28 "Office Phone", 29 "Home Phone", 30 "Mobile Phone", 31 "Beeper", 32 "FAX" 33 }; 34 JComboBox typeCombo = null; 35 JTextField postalSchemeText = null; 36 37 38 /*** 39 * Used for displaying objects 40 */ 41 public TelephoneNumberPanel() { 42 GridBagLayout gbl = new GridBagLayout(); 43 GridBagConstraints c = new GridBagConstraints(); 44 setLayout(gbl); 45 46 JLabel countryCodeLabel = new JLabel("Country code:", SwingConstants.LEFT); 47 c.gridx = 0; 48 c.gridy = 0; 49 c.gridwidth = 1; 50 c.gridheight = 1; 51 c.weightx = 0.0; 52 c.weighty = 0.0; 53 c.fill = GridBagConstraints.NONE; 54 c.anchor = GridBagConstraints.WEST; 55 c.insets = new Insets(4, 4, 0, 4); 56 gbl.setConstraints(countryCodeLabel, c); 57 add(countryCodeLabel); 58 59 countryCodeText = new JTextField(); 60 countryCodeText.setEditable(editable); 61 c.gridx = 0; 62 c.gridy = 1; 63 c.gridwidth = 1; 64 c.gridheight = 1; 65 c.weightx = 0.5; 66 c.weighty = 0.0; 67 c.fill = GridBagConstraints.BOTH; 68 c.anchor = GridBagConstraints.WEST; 69 c.insets = new Insets(4, 4, 0, 4); 70 gbl.setConstraints(countryCodeText, c); 71 add(countryCodeText); 72 73 JLabel areaCodeLabel = new JLabel("Area code:", SwingConstants.LEFT); 74 c.gridx = 1; 75 c.gridy = 0; 76 c.gridwidth = 1; 77 c.gridheight = 1; 78 c.weightx = 0.0; 79 c.weighty = 0.0; 80 c.fill = GridBagConstraints.NONE; 81 c.anchor = GridBagConstraints.WEST; 82 c.insets = new Insets(4, 4, 0, 4); 83 gbl.setConstraints(areaCodeLabel, c); 84 add(areaCodeLabel); 85 86 areaCodeText = new JTextField(); 87 areaCodeText.setEditable(editable); 88 c.gridx = 1; 89 c.gridy = 1; 90 c.gridwidth = 1; 91 c.gridheight = 1; 92 c.weightx = 0.5; 93 c.weighty = 0.0; 94 c.fill = GridBagConstraints.HORIZONTAL; 95 c.anchor = GridBagConstraints.WEST; 96 c.insets = new Insets(4, 4, 0, 4); 97 gbl.setConstraints(areaCodeText, c); 98 add(areaCodeText); 99 100 JLabel numberLabel = new JLabel("Number:", SwingConstants.LEFT); 101 c.gridx = 0; 102 c.gridy = 2; 103 c.gridwidth = 1; 104 c.gridheight = 1; 105 c.weightx = 0.0; 106 c.weighty = 0.0; 107 c.fill = GridBagConstraints.NONE; 108 c.anchor = GridBagConstraints.WEST; 109 c.insets = new Insets(4, 4, 0, 4); 110 gbl.setConstraints(numberLabel, c); 111 add(numberLabel); 112 113 numberText = new JTextField(); 114 numberText.setEditable(editable); 115 c.gridx = 0; 116 c.gridy = 3; 117 c.gridwidth = 1; 118 c.gridheight = 1; 119 c.weightx = 0.5; 120 c.weighty = 0.0; 121 c.fill = GridBagConstraints.BOTH; 122 c.anchor = GridBagConstraints.WEST; 123 c.insets = new Insets(4, 4, 0, 4); 124 gbl.setConstraints(numberText, c); 125 add(numberText); 126 127 JLabel extensionLabel = new JLabel("Extension:", SwingConstants.LEFT); 128 c.gridx = 1; 129 c.gridy = 2; 130 c.gridwidth = 1; 131 c.gridheight = 1; 132 c.weightx = 0.0; 133 c.weighty = 0.0; 134 c.fill = GridBagConstraints.NONE; 135 c.anchor = GridBagConstraints.WEST; 136 c.insets = new Insets(4, 4, 0, 4); 137 gbl.setConstraints(extensionLabel, c); 138 add(extensionLabel); 139 140 extensionText = new JTextField(); 141 extensionText.setEditable(editable); 142 c.gridx = 1; 143 c.gridy = 3; 144 c.gridwidth = 1; 145 c.gridheight = 1; 146 c.weightx = 0.5; 147 c.weighty = 0.0; 148 c.fill = GridBagConstraints.HORIZONTAL; 149 c.anchor = GridBagConstraints.WEST; 150 c.insets = new Insets(4, 4, 0, 4); 151 gbl.setConstraints(extensionText, c); 152 add(extensionText); 153 154 JLabel urlLabel = new JLabel("URL:", SwingConstants.LEFT); 155 c.gridx = 0; 156 c.gridy = 4; 157 c.gridwidth = 1; 158 c.gridheight = 1; 159 c.weightx = 0.0; 160 c.weighty = 0.0; 161 c.fill = GridBagConstraints.NONE; 162 c.anchor = GridBagConstraints.WEST; 163 c.insets = new Insets(4, 4, 0, 4); 164 gbl.setConstraints(urlLabel, c); 165 add(urlLabel); 166 167 urlText = new JTextField(); 168 urlText.setEditable(editable); 169 c.gridx = 0; 170 c.gridy = 5; 171 c.gridwidth = 1; 172 c.gridheight = 1; 173 c.weightx = 0.5; 174 c.weighty = 0.0; 175 c.fill = GridBagConstraints.BOTH; 176 c.anchor = GridBagConstraints.WEST; 177 c.insets = new Insets(4, 4, 0, 4); 178 gbl.setConstraints(urlText, c); 179 add(urlText); 180 181 JLabel typeLabel = new JLabel("Phone Type:", SwingConstants.LEFT); 182 c.gridx = 0; 183 c.gridy = 6; 184 c.gridwidth = 1; 185 c.gridheight = 1; 186 c.weightx = 0.0; 187 c.weighty = 0.0; 188 c.fill = GridBagConstraints.NONE; 189 c.anchor = GridBagConstraints.WEST; 190 c.insets = new Insets(4, 4, 0, 4); 191 gbl.setConstraints(typeLabel, c); 192 add(typeLabel); 193 194 typeCombo = new JComboBox(phoneTypes); 195 typeCombo.setEditable(true); 196 c.gridx = 0; 197 c.gridy = 7; 198 c.gridwidth = 1; 199 c.gridheight = 1; 200 c.weightx = 0.5; 201 c.weighty = 0.0; 202 c.fill = GridBagConstraints.HORIZONTAL; 203 c.anchor = GridBagConstraints.WEST; 204 c.insets = new Insets(4, 4, 0, 4); 205 gbl.setConstraints(typeCombo, c); 206 add(typeCombo); 207 208 } 209 210 public TelephoneNumber getTelephoneNumber() throws JAXRException { 211 TelephoneNumber telephoneNumber = null; 212 213 if (model != null) { 214 telephoneNumber = (TelephoneNumber)getModel(); 215 } 216 return telephoneNumber; 217 } 218 219 public void setTelephoneNumber(TelephoneNumber phone) throws JAXRException { 220 setModel(phone); 221 } 222 223 public void setModel(Object obj) throws JAXRException { 224 if (!(obj instanceof TelephoneNumber)) { 225 throw new InvalidRequestException("Expecting a TelephoneNumber. Got a " + obj.getClass().getName()); 226 } 227 super.setModel(obj); 228 229 TelephoneNumber phone = (TelephoneNumber)obj; 230 231 try { 232 if (phone != null) { 233 countryCodeText.setText(phone.getCountryCode()); 234 areaCodeText.setText(phone.getAreaCode()); 235 numberText.setText(phone.getNumber()); 236 extensionText.setText(phone.getExtension()); 237 urlText.setText(phone.getUrl()); 238 } 239 } 240 catch (JAXRException e) { 241 RegistryBrowser.displayError(e); 242 } 243 244 } 245 246 public Object getModel() throws JAXRException { 247 super.getModel(); 248 249 if (model != null) { 250 TelephoneNumber telephoneNumber = (TelephoneNumber)model; 251 252 telephoneNumber.setCountryCode(countryCodeText.getText()); 253 telephoneNumber.setAreaCode(areaCodeText.getText()); 254 telephoneNumber.setNumber(numberText.getText()); 255 telephoneNumber.setExtension(extensionText.getText()); 256 telephoneNumber.setUrl(urlText.getText()); 257 telephoneNumber.setType((String)(typeCombo.getSelectedItem())); 258 RegistryBrowser.getInstance().getRootPane().updateUI(); 259 } 260 261 return model; 262 } 263 264 protected void validateInput() throws JAXRException { 265 super.validateInput(); 266 TelephoneNumber telephoneNumber = (TelephoneNumber)model; 267 268 } 269 270 public void clear() throws JAXRException { 271 super.clear(); 272 countryCodeText.setText(""); 273 areaCodeText.setText(""); 274 numberText.setText(""); 275 extensionText.setText(""); 276 urlText.setText(""); 277 } 278 279 /*** 280 * Sets whether this dialog is read-only or editable. 281 */ 282 public void setEditable(boolean editable) { 283 super.setEditable(editable); 284 285 countryCodeText.setEditable(editable); 286 areaCodeText.setEditable(editable); 287 areaCodeText.setEditable(editable); 288 numberText.setEditable(editable); 289 extensionText.setEditable(editable); 290 urlText.setEditable(editable); 291 } 292 293 294 }

This page was automatically generated by Maven