View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/PostalAddressPanel.java,v 1.12 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 PostalAddress 16 * 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class PostalAddressPanel extends JBPanel { 20 21 JTextField streetNumText = null; 22 JTextField streetText = null; 23 JTextField cityText = null; 24 JTextField stateText = null; 25 JTextField postalCodeText = null; 26 JTextField countryText = null; 27 28 String[] addressTypes = { 29 "Home", 30 "Office", 31 "Vacation", 32 "Temporary" 33 }; 34 JComboBox typeCombo = null; 35 JTextField postalSchemeText = null; 36 37 38 /*** 39 * Used for displaying objects 40 */ 41 public PostalAddressPanel() { 42 GridBagLayout gbl = new GridBagLayout(); 43 GridBagConstraints c = new GridBagConstraints(); 44 setLayout(gbl); 45 46 JLabel streetNumLabel = new JLabel("Street Number:", 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(streetNumLabel, c); 57 add(streetNumLabel); 58 59 streetNumText = new JTextField(); 60 streetNumText.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(streetNumText, c); 71 add(streetNumText); 72 73 JLabel streetLabel = new JLabel("Street:", 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(streetLabel, c); 84 add(streetLabel); 85 86 streetText = new JTextField(); 87 streetText.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(streetText, c); 98 add(streetText); 99 100 JLabel cityLabel = new JLabel("City:", 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(cityLabel, c); 111 add(cityLabel); 112 113 cityText = new JTextField(); 114 cityText.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(cityText, c); 125 add(cityText); 126 127 JLabel stateLabel = new JLabel("State/Province:", 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(stateLabel, c); 138 add(stateLabel); 139 140 stateText = new JTextField(); 141 stateText.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(stateText, c); 152 add(stateText); 153 154 JLabel postalCodeLabel = new JLabel("Postal Code:", 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(postalCodeLabel, c); 165 add(postalCodeLabel); 166 167 postalCodeText = new JTextField(); 168 postalCodeText.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(postalCodeText, c); 179 add(postalCodeText); 180 181 JLabel countryLabel = new JLabel("Country:", SwingConstants.LEFT); 182 c.gridx = 1; 183 c.gridy = 4; 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(countryLabel, c); 192 add(countryLabel); 193 194 countryText = new JTextField(); 195 countryText.setEditable(editable); 196 c.gridx = 1; 197 c.gridy = 5; 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(countryText, c); 206 add(countryText); 207 208 JLabel typeLabel = new JLabel("Address Type:", SwingConstants.LEFT); 209 c.gridx = 0; 210 c.gridy = 6; 211 c.gridwidth = 1; 212 c.gridheight = 1; 213 c.weightx = 0.0; 214 c.weighty = 0.0; 215 c.fill = GridBagConstraints.NONE; 216 c.anchor = GridBagConstraints.WEST; 217 c.insets = new Insets(4, 4, 0, 4); 218 gbl.setConstraints(typeLabel, c); 219 //add(typeLabel); 220 221 typeCombo = new JComboBox(addressTypes); 222 typeCombo.setEditable(true); 223 c.gridx = 0; 224 c.gridy = 7; 225 c.gridwidth = 1; 226 c.gridheight = 1; 227 c.weightx = 0.5; 228 c.weighty = 0.0; 229 c.fill = GridBagConstraints.HORIZONTAL; 230 c.anchor = GridBagConstraints.WEST; 231 c.insets = new Insets(4, 4, 0, 4); 232 gbl.setConstraints(typeCombo, c); 233 //add(typeCombo); 234 235 JLabel postalSchemeLabel = new JLabel("Postal Address Scheme:", SwingConstants.LEFT); 236 c.gridx = 1; 237 c.gridy = 6; 238 c.gridwidth = 1; 239 c.gridheight = 1; 240 c.weightx = 0.0; 241 c.weighty = 0.0; 242 c.fill = GridBagConstraints.NONE; 243 c.anchor = GridBagConstraints.WEST; 244 c.insets = new Insets(4, 4, 0, 4); 245 gbl.setConstraints(postalSchemeLabel, c); 246 //add(postalSchemeLabel); 247 248 /* 249 postalSchemeText = new JTextField(); 250 countryText.setInputVerifier(new InputVerifier() { 251 public boolean verify(JComponent comp) { 252 try { 253 String text = countryText.getText(); 254 postalAddress.setCountry(text); 255 RegistryBrowser.getInstance().getRootPane().updateUI(); 256 } 257 catch (JAXRException e) { 258 RegistryBrowser.displayError(e); 259 } 260 return true; 261 } 262 }); 263 c.gridx = 1; 264 c.gridy = 7; 265 c.gridwidth = 1; 266 c.gridheight = 1; 267 c.weightx = 0.5; 268 c.weighty = 0.0; 269 c.fill = GridBagConstraints.HORIZONTAL; 270 c.anchor = GridBagConstraints.WEST; 271 c.insets = new Insets(4, 4, 0, 4); 272 gbl.setConstraints(postalSchemeText, c); 273 add(postalSchemeText); 274 */ 275 } 276 277 public PostalAddress getPostalAddress() throws JAXRException { 278 PostalAddress postalAddress = null; 279 280 if (model != null) { 281 postalAddress = (PostalAddress)getModel(); 282 } 283 return postalAddress; 284 } 285 286 public void setPostalAddress(PostalAddress addr) throws JAXRException { 287 setModel(addr); 288 } 289 290 public void setModel(Object obj) throws JAXRException { 291 if (!(obj instanceof PostalAddress)) { 292 throw new InvalidRequestException("Expecting a PostalAddress. Got a " + obj.getClass().getName()); 293 } 294 super.setModel(obj); 295 296 PostalAddress addr = (PostalAddress)obj; 297 298 299 try { 300 if (addr != null) { 301 streetNumText.setText(addr.getStreetNumber()); 302 streetText.setText(addr.getStreet()); 303 cityText.setText(addr.getCity()); 304 stateText.setText(addr.getStateOrProvince()); 305 postalCodeText.setText(addr.getPostalCode()); 306 countryText.setText(addr.getCountry()); 307 //typeCombo.setText(addr.getType()); 308 309 ClassificationScheme scheme = addr.getPostalScheme(); 310 if (scheme != null) { 311 String schemeName = RegistryBrowser.getName(scheme); 312 if (schemeName != null && schemeName.length() > 0) { 313 postalSchemeText.setText(schemeName); 314 } 315 } 316 } 317 } 318 catch (JAXRException e) { 319 RegistryBrowser.displayError(e); 320 } 321 322 } 323 324 public Object getModel() throws JAXRException { 325 super.getModel(); 326 327 if (model != null) { 328 PostalAddress postalAddress = (PostalAddress)model; 329 330 postalAddress.setStreetNumber(streetNumText.getText()); 331 postalAddress.setStreet(streetText.getText()); 332 postalAddress.setCity(cityText.getText()); 333 postalAddress.setStateOrProvince(stateText.getText()); 334 postalAddress.setPostalCode(postalCodeText.getText()); 335 postalAddress.setCountry(countryText.getText()); 336 postalAddress.setType((String)(typeCombo.getSelectedItem())); 337 338 RegistryBrowser.getInstance().getRootPane().updateUI(); 339 } 340 341 return model; 342 } 343 344 protected void validateInput() throws JAXRException { 345 super.validateInput(); 346 PostalAddress postalAddress = (PostalAddress)model; 347 } 348 349 public void clear() throws JAXRException { 350 super.clear(); 351 streetNumText.setText(""); 352 streetText.setText(""); 353 cityText.setText(""); 354 stateText.setText(""); 355 postalCodeText.setText(""); 356 countryText.setText(""); 357 //typeCombo.setText("Office"); 358 if (postalSchemeText != null) { 359 postalSchemeText.setText(""); 360 } 361 } 362 363 /*** 364 * Sets whether this dialog is read-only or editable. 365 */ 366 public void setEditable(boolean editable) { 367 super.setEditable(editable); 368 369 streetNumText.setEditable(editable); 370 streetText.setEditable(editable); 371 cityText.setEditable(editable); 372 stateText.setEditable(editable); 373 postalCodeText.setEditable(editable); 374 countryText.setEditable(editable); 375 } 376 377 378 }

This page was automatically generated by Maven