1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.beans.PropertyChangeEvent ; 22 23 import org.netbeans.tax.TreeElementDecl; 24 import org.netbeans.tax.TreeException; 25 26 import org.netbeans.modules.xml.tax.util.TAXUtil; 27 28 33 public class TreeElementDeclCustomizer extends AbstractTreeCustomizer { 34 35 36 private static final long serialVersionUID = -4904653355576437639L; 37 38 39 43 44 public TreeElementDeclCustomizer () { 45 super (); 46 47 initComponents (); 48 nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); contentLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtdContent")); 51 initAccessibility (); 52 } 53 54 55 59 61 protected final TreeElementDecl getElementDecl () { 62 return (TreeElementDecl)getTreeObject (); 63 } 64 65 67 protected final void safePropertyChange (PropertyChangeEvent pche) { 68 super.safePropertyChange (pche); 69 70 if (pche.getPropertyName ().equals (TreeElementDecl.PROP_NAME)) { 71 updateNameComponent (); 72 } else if (pche.getPropertyName ().equals (TreeElementDecl.PROP_CONTENT_TYPE)) { 73 updateContentTypeComponent (); 74 } 75 } 76 77 79 protected final void updateElementDeclName () { 80 try { 81 getElementDecl ().setName (nameField.getText ()); 82 } catch (TreeException exc) { 83 updateNameComponent (); 84 TAXUtil.notifyTreeException (exc); 85 } 86 } 87 88 90 protected final void updateNameComponent () { 91 nameField.setText (getElementDecl ().getName ()); 92 } 93 94 96 protected final void updateElementDeclContentType () { 97 try { 98 getElementDecl ().setContentType (contentField.getText ()); 99 } catch (TreeException exc) { 100 updateContentTypeComponent (); 101 TAXUtil.notifyTreeException (exc); 102 } 103 } 104 105 107 protected final void updateContentTypeComponent () { 108 contentField.setText (getElementDecl ().getContentType ().toString ()); 109 } 110 111 113 protected final void initComponentValues () { 114 updateNameComponent (); 115 updateContentTypeComponent (); 116 } 117 118 119 121 protected void updateReadOnlyStatus (boolean editable) { 122 nameField.setEditable (editable); 123 contentField.setEditable (editable); 124 } 125 126 131 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 133 134 nameLabel = new javax.swing.JLabel (); 135 nameField = new javax.swing.JTextField (); 136 contentLabel = new javax.swing.JLabel (); 137 contentField = new javax.swing.JTextField (); 138 fillPanel = new javax.swing.JPanel (); 139 140 setLayout(new java.awt.GridBagLayout ()); 141 142 nameLabel.setText(Util.THIS.getString ("PROP_xmlName")); 143 nameLabel.setLabelFor(nameField); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 0; 146 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 148 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 149 add(nameLabel, gridBagConstraints); 150 151 nameField.setColumns(20); 152 nameField.addFocusListener(new java.awt.event.FocusAdapter () { 153 public void focusGained(java.awt.event.FocusEvent evt) { 154 nameFieldFocusGained(evt); 155 } 156 }); 157 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 1; 160 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 161 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 162 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 163 gridBagConstraints.weightx = 1.0; 164 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 165 add(nameField, gridBagConstraints); 166 167 contentLabel.setText(Util.THIS.getString ("PROP_dtdContent")); 168 contentLabel.setLabelFor(contentField); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 0; 171 gridBagConstraints.gridy = 1; 172 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 173 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 174 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 175 add(contentLabel, gridBagConstraints); 176 177 contentField.setColumns(20); 178 contentField.addFocusListener(new java.awt.event.FocusAdapter () { 179 public void focusGained(java.awt.event.FocusEvent evt) { 180 contentFieldFocusGained(evt); 181 } 182 }); 183 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 1; 186 gridBagConstraints.gridy = 1; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 188 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 189 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 190 add(contentField, gridBagConstraints); 191 192 fillPanel.setPreferredSize(new java.awt.Dimension (0, 0)); 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridx = 0; 195 gridBagConstraints.gridy = 2; 196 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 197 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 198 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 199 gridBagConstraints.weightx = 1.0; 200 gridBagConstraints.weighty = 1.0; 201 add(fillPanel, gridBagConstraints); 202 203 } 205 private void contentFieldFocusGained(java.awt.event.FocusEvent evt) { contentField.selectAll (); 208 } 210 private void nameFieldFocusGained(java.awt.event.FocusEvent evt) { nameField.selectAll (); 213 } 215 private javax.swing.JLabel nameLabel; 217 private javax.swing.JLabel contentLabel; 218 private javax.swing.JTextField nameField; 219 private javax.swing.JTextField contentField; 220 private javax.swing.JPanel fillPanel; 221 223 224 226 public void initAccessibility (){ 227 228 nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField")); 229 nameField.selectAll (); 230 contentField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_contentField")); 231 contentField.selectAll (); 232 233 this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeElementDeclCustomizer")); 234 } 235 } 236 | Popular Tags |