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.JComboBox; 16 import javax.swing.JLabel; 17 import javax.swing.JTextField; 18 import javax.swing.SwingConstants; 19 import javax.xml.registry.JAXRException; 20 import javax.xml.registry.infomodel.PostalAddress; 21 22 import com.sun.xml.registry.client.browser.swing.RegistryComboBoxListener; 23 import com.sun.xml.registry.client.browser.swing.MappedDocumentListener; 24 import com.sun.xml.registry.client.browser.swing.RegistryMappedPanel; 25 import com.sun.xml.registry.client.browser.swing.TextField; 26 27 /*** 28 * Panel for PostalAddress 29 * 30 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 31 * @author Fabian Ritzmann 32 */ 33 public class PostalAddressPanel extends RegistryMappedPanel { 34 35 private final PostalAddressModel model; 36 37 private final JTextField streetNumText = new JTextField(); 38 private final JTextField streetText = new JTextField(); 39 private final JTextField cityText = new JTextField(); 40 private final JTextField stateText = new JTextField(); 41 private final JTextField postalCodeText = new JTextField(); 42 private final JTextField countryText = new JTextField(); 43 44 45 PostalAddressPanel(PostalAddressModel address) { 46 47 super(address, "Can not display postal address: "); 48 this.model = address; 49 this.model.addObserver(this); 50 51 GridBagLayout gbl = new GridBagLayout(); 52 GridBagConstraints c = new GridBagConstraints(); 53 setLayout(gbl); 54 55 JLabel streetNumLabel = new JLabel("Street Number:", SwingConstants.LEFT); 56 setConstraints(streetNumLabel, c, gbl, 0, 0, 1, 0.0, 57 GridBagConstraints.NONE, GridBagConstraints.WEST); 58 add(streetNumLabel); 59 60 streetNumText.getDocument().addDocumentListener(new StreetNumListener()); 61 setConstraints(streetNumText, c, gbl, 0, 1, 1, 0.5, 62 GridBagConstraints.BOTH, GridBagConstraints.WEST); 63 addTextField(new TextField() { 64 public JTextField getTextField() { 65 return streetNumText; 66 } 67 public String getText() throws JAXRException { 68 PostalAddress address = getPostalAddressModel().getAddress(); 69 if (address != null) { 70 return address.getStreetNumber(); 71 } 72 return null; 73 } 74 }); 75 76 JLabel streetLabel = new JLabel("Street:", SwingConstants.LEFT); 77 setConstraints(streetLabel, c, gbl, 1, 0, 1, 0.0, 78 GridBagConstraints.NONE, GridBagConstraints.WEST); 79 add(streetLabel); 80 81 streetText.getDocument().addDocumentListener(new StreetListener()); 82 setConstraints(streetText, c, gbl, 1, 1, 1, 0.5, 83 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 84 addTextField(new TextField() { 85 public JTextField getTextField() { 86 return streetText; 87 } 88 public String getText() throws JAXRException { 89 PostalAddress address = getPostalAddressModel().getAddress(); 90 if (address != null) { 91 return address.getStreet(); 92 } 93 return null; 94 } 95 }); 96 97 JLabel cityLabel = new JLabel("City:", SwingConstants.LEFT); 98 setConstraints(cityLabel, c, gbl, 0, 2, 1, 0.0, 99 GridBagConstraints.NONE, GridBagConstraints.WEST); 100 add(cityLabel); 101 102 cityText.getDocument().addDocumentListener(new CityListener()); 103 setConstraints(cityText, c, gbl, 0, 3, 1, 0.5, 104 GridBagConstraints.BOTH, GridBagConstraints.WEST); 105 addTextField(new TextField() { 106 public JTextField getTextField() { 107 return cityText; 108 } 109 public String getText() throws JAXRException { 110 PostalAddress address = getPostalAddressModel().getAddress(); 111 if (address != null) { 112 return address.getCity(); 113 } 114 return null; 115 } 116 }); 117 118 JLabel stateLabel = new JLabel("State/Province:", SwingConstants.LEFT); 119 setConstraints(stateLabel, c, gbl, 1, 2, 1, 0.0, 120 GridBagConstraints.NONE, GridBagConstraints.WEST); 121 add(stateLabel); 122 123 stateText.getDocument().addDocumentListener(new StateListener()); 124 setConstraints(stateText, c, gbl, 1, 3, 1, 0.5, 125 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 126 addTextField(new TextField() { 127 public JTextField getTextField() { 128 return stateText; 129 } 130 public String getText() throws JAXRException { 131 PostalAddress address = getPostalAddressModel().getAddress(); 132 if (address != null) { 133 return address.getStateOrProvince(); 134 } 135 return null; 136 } 137 }); 138 139 JLabel postalCodeLabel = new JLabel("Postal Code:", SwingConstants.LEFT); 140 setConstraints(postalCodeLabel, c, gbl, 0, 4, 1, 0.0, 141 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 142 add(postalCodeLabel); 143 144 postalCodeText.getDocument().addDocumentListener(new PostalCodeListener()); 145 setConstraints(postalCodeText, c, gbl, 0, 5, 1, 0.5, 146 GridBagConstraints.BOTH, GridBagConstraints.WEST); 147 addTextField(new TextField() { 148 public JTextField getTextField() { 149 return postalCodeText; 150 } 151 public String getText() throws JAXRException { 152 PostalAddress address = getPostalAddressModel().getAddress(); 153 if (address != null) { 154 return address.getPostalCode(); 155 } 156 return null; 157 } 158 }); 159 160 JLabel countryLabel = new JLabel("Country:", SwingConstants.LEFT); 161 setConstraints(countryLabel, c, gbl, 1, 4, 1, 0.0, 162 GridBagConstraints.BOTH, GridBagConstraints.WEST); 163 add(countryLabel); 164 165 countryText.getDocument().addDocumentListener(new CountryListener()); 166 setConstraints(countryText, c, gbl, 1, 5, 1, 0.5, 167 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 168 addTextField(new TextField() { 169 public JTextField getTextField() { 170 return countryText; 171 } 172 public String getText() throws JAXRException { 173 PostalAddress address = getPostalAddressModel().getAddress(); 174 if (address != null) { 175 return address.getCountry(); 176 } 177 return null; 178 } 179 }); 180 181 JLabel typeLabel = new JLabel("Address Type:", SwingConstants.LEFT); 182 setConstraints(typeLabel, c, gbl, 0, 6, 1, 0.0, 183 GridBagConstraints.NONE, GridBagConstraints.WEST); 184 add(typeLabel); 185 186 JComboBox typeCombo = new JComboBox(PostalAddressModel.ADDRESS_TYPES); 187 typeCombo.setEditable(true); 188 typeCombo.addActionListener(new AddressTypeListener()); 189 setConstraints(typeCombo, c, gbl, 0, 7, 1, 0.5, 190 GridBagConstraints.NONE, GridBagConstraints.WEST); 191 add(typeCombo); 192 193 JLabel postalSchemeLabel = new JLabel("Postal Address Scheme:", SwingConstants.LEFT); 194 RegistryMappedPanel.setConstraints(postalSchemeLabel, c, gbl, 195 1, 6, 1, 0.0, 196 GridBagConstraints.NONE, 197 GridBagConstraints.WEST); 198 add(postalSchemeLabel); 199 } 200 201 202 public PostalAddressModel getPostalAddressModel() { 203 return this.model; 204 } 205 206 207 class StreetNumListener extends MappedDocumentListener { 208 209 public StreetNumListener() { 210 super(getRegistryMappedPanel(), "Could not set street number: "); 211 } 212 213 protected void setText(String text) throws JAXRException { 214 getPostalAddressModel().setStreetNum(text); 215 } 216 } 217 218 219 class StreetListener extends MappedDocumentListener { 220 221 public StreetListener() { 222 super(getRegistryMappedPanel(), "Could not set street: "); 223 } 224 225 protected void setText(String text) throws JAXRException { 226 getPostalAddressModel().setStreet(text); 227 } 228 } 229 230 231 class CityListener extends MappedDocumentListener { 232 233 public CityListener() { 234 super(getRegistryMappedPanel(), "Could not set city: "); 235 } 236 237 protected void setText(String text) throws JAXRException { 238 getPostalAddressModel().setCity(text); 239 } 240 } 241 242 243 class StateListener extends MappedDocumentListener { 244 245 public StateListener() { 246 super(getRegistryMappedPanel(), "Could not set state: "); 247 } 248 249 protected void setText(String text) throws JAXRException { 250 getPostalAddressModel().setState(text); 251 } 252 } 253 254 255 class PostalCodeListener extends MappedDocumentListener { 256 257 public PostalCodeListener() { 258 super(getRegistryMappedPanel(), "Could not set postal code: "); 259 } 260 261 protected void setText(String text) throws JAXRException { 262 getPostalAddressModel().setPostalCode(text); 263 } 264 } 265 266 267 class CountryListener extends MappedDocumentListener { 268 269 public CountryListener() { 270 super(getRegistryMappedPanel(), "Could not set country: "); 271 } 272 273 protected void setText(String text) throws JAXRException { 274 getPostalAddressModel().setCountry(text); 275 } 276 } 277 278 279 class AddressTypeListener extends RegistryComboBoxListener { 280 281 AddressTypeListener() { 282 super(getPostalAddressModel(), getRegistryMappedPanel()); 283 } 284 } 285 286 }

This page was automatically generated by Maven