View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/PersonNamePanel.java,v 1.10 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 PersonName 16 * 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class PersonNamePanel extends JBPanel { 20 21 JTextField firstNameText = null; 22 JTextField middleNameText = null; 23 JTextField lastNameText = null; 24 25 /*** 26 * Used for displaying objects 27 */ 28 public PersonNamePanel() { 29 GridBagLayout gbl = new GridBagLayout(); 30 GridBagConstraints c = new GridBagConstraints(); 31 setLayout(gbl); 32 33 JLabel firstNameLabel = new JLabel("First name (Given name):", SwingConstants.LEFT); 34 c.gridx = 0; 35 c.gridy = 0; 36 c.gridwidth = 1; 37 c.gridheight = 1; 38 c.weightx = 0.0; 39 c.weighty = 0.0; 40 c.fill = GridBagConstraints.NONE; 41 c.anchor = GridBagConstraints.WEST; 42 c.insets = new Insets(4, 4, 0, 4); 43 gbl.setConstraints(firstNameLabel, c); 44 add(firstNameLabel); 45 46 firstNameText = new JTextField(); 47 firstNameText.setEditable(editable); 48 c.gridx = 0; 49 c.gridy = 1; 50 c.gridwidth = 1; 51 c.gridheight = 1; 52 c.weightx = 0.75; 53 c.weighty = 0.0; 54 c.fill = GridBagConstraints.BOTH; 55 c.anchor = GridBagConstraints.WEST; 56 c.insets = new Insets(4, 4, 0, 4); 57 gbl.setConstraints(firstNameText, c); 58 add(firstNameText); 59 60 JLabel middleNameLabel = new JLabel("Middle name:", SwingConstants.LEFT); 61 c.gridx = 1; 62 c.gridy = 0; 63 c.gridwidth = 1; 64 c.gridheight = 1; 65 c.weightx = 0.0; 66 c.weighty = 0.0; 67 c.fill = GridBagConstraints.NONE; 68 c.anchor = GridBagConstraints.WEST; 69 c.insets = new Insets(4, 4, 0, 4); 70 gbl.setConstraints(middleNameLabel, c); 71 add(middleNameLabel); 72 73 middleNameText = new JTextField(); 74 middleNameText.setEditable(editable); 75 c.gridx = 1; 76 c.gridy = 1; 77 c.gridwidth = 1; 78 c.gridheight = 1; 79 c.weightx = 0.25; 80 c.weighty = 0.0; 81 c.fill = GridBagConstraints.HORIZONTAL; 82 c.anchor = GridBagConstraints.WEST; 83 c.insets = new Insets(4, 4, 0, 4); 84 gbl.setConstraints(middleNameText, c); 85 add(middleNameText); 86 87 JLabel lastNameLabel = new JLabel("Last name (Surname):", SwingConstants.LEFT); 88 c.gridx = 0; 89 c.gridy = 2; 90 c.gridwidth = 1; 91 c.gridheight = 1; 92 c.weightx = 0.0; 93 c.weighty = 0.0; 94 c.fill = GridBagConstraints.NONE; 95 c.anchor = GridBagConstraints.WEST; 96 c.insets = new Insets(4, 4, 0, 4); 97 gbl.setConstraints(lastNameLabel, c); 98 add(lastNameLabel); 99 100 lastNameText = new JTextField(); 101 lastNameText.setEditable(editable); 102 c.gridx = 0; 103 c.gridy = 3; 104 c.gridwidth = 2; 105 c.gridheight = 1; 106 c.weightx = 0.5; 107 c.weighty = 0.0; 108 c.fill = GridBagConstraints.BOTH; 109 c.anchor = GridBagConstraints.WEST; 110 c.insets = new Insets(4, 4, 0, 4); 111 gbl.setConstraints(lastNameText, c); 112 add(lastNameText); 113 } 114 115 public PersonName getPersonName() throws JAXRException { 116 PersonName personName = null; 117 118 if (model != null) { 119 personName = (PersonName)getModel(); 120 } 121 return personName; 122 } 123 124 public void setPersonName(PersonName personName) throws JAXRException { 125 setModel(personName); 126 } 127 128 public void setModel(Object obj) throws JAXRException { 129 if (!(obj instanceof PersonName)) { 130 throw new InvalidRequestException("Expecting a PersonName. Got a " + obj.getClass().getName()); 131 } 132 super.setModel(obj); 133 134 PersonName personName = (PersonName)obj; 135 136 137 try { 138 if (personName != null) { 139 firstNameText.setText(personName.getFirstName()); 140 middleNameText.setText(personName.getMiddleName()); 141 lastNameText.setText(personName.getLastName()); 142 } 143 } 144 catch (JAXRException e) { 145 RegistryBrowser.displayError(e); 146 } 147 148 } 149 150 public Object getModel() throws JAXRException { 151 super.getModel(); 152 if (model != null) { 153 PersonName personName = (PersonName)model; 154 155 personName.setFirstName(firstNameText.getText()); 156 personName.setMiddleName(middleNameText.getText()); 157 personName.setLastName(lastNameText.getText()); 158 159 RegistryBrowser.getInstance().getRootPane().updateUI(); 160 } 161 162 return model; 163 } 164 165 protected void validateInput() throws JAXRException { 166 super.validateInput(); 167 } 168 169 public void clear() throws JAXRException { 170 super.clear(); 171 firstNameText.setText(""); 172 middleNameText.setText(""); 173 lastNameText.setText(""); 174 } 175 176 /*** 177 * Sets whether this dialog is read-only or editable. 178 */ 179 public void setEditable(boolean editable) { 180 super.setEditable(editable); 181 182 firstNameText.setEditable(editable); 183 middleNameText.setEditable(editable); 184 lastNameText.setEditable(editable); 185 } 186 187 }

This page was automatically generated by Maven