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.TelephoneNumber; 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 TelephoneNumber 29 * 30 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 31 * @author Fabian Ritzmann 32 */ 33 public class TelephoneNumberPanel extends RegistryMappedPanel { 34 35 private final TelephoneNumberModel model; 36 37 private final JTextField countryCodeText = new JTextField(); 38 private final JTextField areaCodeText = new JTextField(); 39 private final JTextField numberText = new JTextField(); 40 private final JTextField extensionText = new JTextField(); 41 private final JTextField urlText = new JTextField(); 42 43 44 TelephoneNumberPanel(TelephoneNumberModel number) { 45 46 super(number, "Can not display telephone number: "); 47 this.model = number; 48 49 GridBagLayout gbl = new GridBagLayout(); 50 GridBagConstraints c = new GridBagConstraints(); 51 setLayout(gbl); 52 53 JLabel countryCodeLabel = new JLabel("Country code:", SwingConstants.LEFT); 54 setConstraints(countryCodeLabel, c, gbl, 0, 0, 1, 0.0, 55 GridBagConstraints.NONE, GridBagConstraints.WEST); 56 add(countryCodeLabel); 57 58 countryCodeText.getDocument().addDocumentListener(new CountryCodeListener()); 59 setConstraints(countryCodeText, c, gbl, 0, 1, 1, 0.5, 60 GridBagConstraints.BOTH, GridBagConstraints.WEST); 61 addTextField(new TextField() { 62 public JTextField getTextField() { 63 return countryCodeText; 64 } 65 public String getText() throws JAXRException { 66 TelephoneNumber number = getTelephoneNumberModel().getNumber(); 67 if (number != null) { 68 return number.getCountryCode(); 69 } 70 return null; 71 } 72 }); 73 74 JLabel areaCodeLabel = new JLabel("Area code:", SwingConstants.LEFT); 75 setConstraints(areaCodeLabel, c, gbl, 1, 0, 1, 0.0, 76 GridBagConstraints.NONE, GridBagConstraints.WEST); 77 add(areaCodeLabel); 78 79 areaCodeText.getDocument().addDocumentListener(new AreaCodeListener()); 80 setConstraints(areaCodeText, c, gbl, 1, 1, 1, 0.5, 81 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 82 addTextField(new TextField() { 83 public JTextField getTextField() { 84 return areaCodeText; 85 } 86 public String getText() throws JAXRException { 87 TelephoneNumber number = getTelephoneNumberModel().getNumber(); 88 if (number != null) { 89 return number.getAreaCode(); 90 } 91 return null; 92 } 93 }); 94 95 JLabel numberLabel = new JLabel("Number:", SwingConstants.LEFT); 96 setConstraints(numberLabel, c, gbl, 0, 2, 1, 0.0, 97 GridBagConstraints.NONE, GridBagConstraints.WEST); 98 add(numberLabel); 99 100 numberText.getDocument().addDocumentListener(new NumberListener()); 101 setConstraints(numberText, c, gbl, 0, 3, 1, 0.5, 102 GridBagConstraints.BOTH, GridBagConstraints.WEST); 103 addTextField(new TextField() { 104 public JTextField getTextField() { 105 return numberText; 106 } 107 public String getText() throws JAXRException { 108 TelephoneNumber number = getTelephoneNumberModel().getNumber(); 109 if (number != null) { 110 return number.getNumber(); 111 } 112 return null; 113 } 114 }); 115 116 JLabel extensionLabel = new JLabel("Extension:", SwingConstants.LEFT); 117 setConstraints(extensionLabel, c, gbl, 1, 2, 1, 0.0, 118 GridBagConstraints.NONE, GridBagConstraints.WEST); 119 add(extensionLabel); 120 121 extensionText.getDocument().addDocumentListener(new ExtensionListener()); 122 setConstraints(extensionText, c, gbl, 1, 3, 1, 0.5, 123 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 124 addTextField(new TextField() { 125 public JTextField getTextField() { 126 return extensionText; 127 } 128 public String getText() throws JAXRException { 129 TelephoneNumber number = getTelephoneNumberModel().getNumber(); 130 if (number != null) { 131 return number.getExtension(); 132 } 133 return null; 134 } 135 }); 136 137 JLabel urlLabel = new JLabel("URL:", SwingConstants.LEFT); 138 setConstraints(urlLabel, c, gbl, 0, 4, 1, 0.0, 139 GridBagConstraints.NONE, GridBagConstraints.WEST); 140 add(urlLabel); 141 142 urlText.getDocument().addDocumentListener(new URLListener()); 143 setConstraints(urlText, c, gbl, 0, 5, 1, 0.5, 144 GridBagConstraints.BOTH, GridBagConstraints.WEST); 145 addTextField(new TextField() { 146 public JTextField getTextField() { 147 return urlText; 148 } 149 public String getText() throws JAXRException { 150 TelephoneNumber number = getTelephoneNumberModel().getNumber(); 151 if (number != null) { 152 return number.getUrl(); 153 } 154 return null; 155 } 156 }); 157 158 JLabel typeLabel = new JLabel("Phone Type:", SwingConstants.LEFT); 159 setConstraints(typeLabel, c, gbl, 0, 6, 1, 0.0, 160 GridBagConstraints.NONE, GridBagConstraints.WEST); 161 add(typeLabel); 162 163 JComboBox typeCombo = new JComboBox(TelephoneNumberModel.PHONE_TYPES); 164 typeCombo.addActionListener(new PhoneTypeListener()); 165 typeCombo.setEditable(true); 166 setConstraints(typeCombo, c, gbl, 0, 7, 1, 0.5, 167 GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); 168 add(typeCombo); 169 } 170 171 172 public TelephoneNumberModel getTelephoneNumberModel() { 173 return this.model; 174 } 175 176 177 class CountryCodeListener extends MappedDocumentListener { 178 179 public CountryCodeListener() { 180 super(getRegistryMappedPanel(), "Could not set country code: "); 181 } 182 183 protected void setText(String text) throws JAXRException { 184 getTelephoneNumberModel().setCountryCode(text); 185 } 186 } 187 188 189 class AreaCodeListener extends MappedDocumentListener { 190 191 public AreaCodeListener() { 192 super(getRegistryMappedPanel(), "Could not set area code: "); 193 } 194 195 protected void setText(String text) throws JAXRException { 196 getTelephoneNumberModel().setAreaCode(text); 197 } 198 } 199 200 201 class NumberListener extends MappedDocumentListener { 202 203 public NumberListener() { 204 super(getRegistryMappedPanel(), "Could not set number: "); 205 } 206 207 protected void setText(String text) throws JAXRException { 208 getTelephoneNumberModel().setNumber(text); 209 } 210 } 211 212 213 class ExtensionListener extends MappedDocumentListener { 214 215 public ExtensionListener() { 216 super(getRegistryMappedPanel(), "Could not set extension: "); 217 } 218 219 protected void setText(String text) throws JAXRException { 220 getTelephoneNumberModel().setExtension(text); 221 } 222 } 223 224 225 class URLListener extends MappedDocumentListener { 226 227 public URLListener() { 228 super(getRegistryMappedPanel(), "Could not set URL: "); 229 } 230 231 protected void setText(String text) throws JAXRException { 232 getTelephoneNumberModel().setURL(text); 233 } 234 } 235 236 237 class PhoneTypeListener extends RegistryComboBoxListener { 238 239 public PhoneTypeListener() { 240 super(getTelephoneNumberModel(), getRegistryMappedPanel()); 241 } 242 } 243 244 }

This page was automatically generated by Maven