1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.beans.PropertyChangeEvent ; 22 23 import org.netbeans.tax.TreeDTD; 24 import org.netbeans.tax.TreeException; 25 26 import org.netbeans.modules.xml.tax.beans.editor.VersionEditor; 27 import org.netbeans.modules.xml.tax.beans.editor.EncodingEditor; 28 import org.netbeans.modules.xml.tax.util.TAXUtil; 29 30 35 public class TreeDTDCustomizer extends AbstractTreeCustomizer { 36 37 38 private static final long serialVersionUID = -6359067211795222437L; 39 40 41 45 46 public TreeDTDCustomizer () { 47 super (); 48 49 initComponents (); 50 versionLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtd_version")); encodingLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtd_encoding")); 53 initAccessibility (); 54 } 55 56 57 61 63 protected final TreeDTD getDTD () { 64 return (TreeDTD)getTreeObject (); 65 } 66 67 69 protected final void safePropertyChange (PropertyChangeEvent pche) { 70 super.safePropertyChange (pche); 71 72 if (pche.getPropertyName ().equals (TreeDTD.PROP_VERSION)) { 73 updateVersionComponent (); 74 } else if (pche.getPropertyName ().equals (TreeDTD.PROP_ENCODING)) { 75 updateEncodingComponent (); 76 } 77 } 78 79 81 protected final void updateDTDVersion () { 82 if ( cbVersion.getSelectedItem () == null ) { 83 return; 84 } 85 86 try { 87 getDTD ().setVersion (text2null ((String ) cbVersion.getSelectedItem ())); 88 } catch (TreeException exc) { 89 updateVersionComponent (); 90 TAXUtil.notifyTreeException (exc); 91 } 92 } 93 94 96 protected final void updateVersionComponent () { 97 cbVersion.setSelectedItem (null2text (getDTD ().getVersion ())); 98 } 99 100 102 protected final void updateDTDEncoding () { 103 if ( cbEncoding.getSelectedItem () == null ) { 104 return; 105 } 106 107 try { 108 getDTD ().setEncoding (text2null ((String ) cbEncoding.getSelectedItem ())); 109 } catch (TreeException exc) { 110 updateEncodingComponent (); 111 TAXUtil.notifyTreeException (exc); 112 } 113 } 114 115 117 protected final void updateEncodingComponent () { 118 cbEncoding.setSelectedItem (null2text (getDTD ().getEncoding ())); 119 } 120 121 123 protected void initComponentValues () { 124 updateVersionComponent (); 125 updateEncodingComponent (); 126 } 127 128 129 131 protected void updateReadOnlyStatus (boolean editable) { 132 cbVersion.setEnabled (editable); 133 cbEncoding.setEnabled (editable); 134 } 135 136 137 142 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 144 145 versionLabel = new javax.swing.JLabel (); 146 cbVersion = new javax.swing.JComboBox (); 147 encodingLabel = new javax.swing.JLabel (); 148 cbEncoding = new javax.swing.JComboBox (); 149 fillPanel = new javax.swing.JPanel (); 150 151 setLayout(new java.awt.GridBagLayout ()); 152 153 versionLabel.setText(Util.THIS.getString ("PROP_dtd_version")); 154 versionLabel.setLabelFor(cbVersion); 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 158 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 159 add(versionLabel, gridBagConstraints); 160 161 cbVersion.setModel(new javax.swing.DefaultComboBoxModel (VersionEditor.getItems())); 162 cbVersion.addActionListener(new java.awt.event.ActionListener () { 163 public void actionPerformed(java.awt.event.ActionEvent evt) { 164 cbVersionActionPerformed(evt); 165 } 166 }); 167 168 cbVersion.addFocusListener(new java.awt.event.FocusAdapter () { 169 public void focusLost(java.awt.event.FocusEvent evt) { 170 cbVersionFocusLost(evt); 171 } 172 }); 173 174 gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 1; 176 gridBagConstraints.gridy = 0; 177 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 178 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 179 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 180 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 181 add(cbVersion, gridBagConstraints); 182 183 encodingLabel.setText(Util.THIS.getString ("PROP_dtd_encoding")); 184 encodingLabel.setLabelFor(cbEncoding); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridx = 0; 187 gridBagConstraints.gridy = 1; 188 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 189 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 190 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 191 add(encodingLabel, gridBagConstraints); 192 193 cbEncoding.setModel(new javax.swing.DefaultComboBoxModel (EncodingEditor.getItems())); 194 cbEncoding.setEditable(true); 195 cbEncoding.addActionListener(new java.awt.event.ActionListener () { 196 public void actionPerformed(java.awt.event.ActionEvent evt) { 197 cbEncodingActionPerformed(evt); 198 } 199 }); 200 201 cbEncoding.addFocusListener(new java.awt.event.FocusAdapter () { 202 public void focusLost(java.awt.event.FocusEvent evt) { 203 cbEncodingFocusLost(evt); 204 } 205 }); 206 207 gridBagConstraints = new java.awt.GridBagConstraints (); 208 gridBagConstraints.gridx = 1; 209 gridBagConstraints.gridy = 1; 210 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 211 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 212 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 213 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 214 add(cbEncoding, gridBagConstraints); 215 216 fillPanel.setPreferredSize(new java.awt.Dimension (0, 0)); 217 gridBagConstraints = new java.awt.GridBagConstraints (); 218 gridBagConstraints.gridx = 0; 219 gridBagConstraints.gridy = 2; 220 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 221 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 222 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 223 gridBagConstraints.weightx = 1.0; 224 gridBagConstraints.weighty = 1.0; 225 add(fillPanel, gridBagConstraints); 226 227 } 229 private void cbEncodingFocusLost(java.awt.event.FocusEvent evt) { updateDTDEncoding (); 232 } 234 private void cbEncodingActionPerformed(java.awt.event.ActionEvent evt) { updateDTDEncoding (); 237 } 239 private void cbVersionFocusLost(java.awt.event.FocusEvent evt) { updateDTDVersion (); 242 } 244 private void cbVersionActionPerformed(java.awt.event.ActionEvent evt) { updateDTDVersion (); 247 } 249 private javax.swing.JComboBox cbVersion; 251 private javax.swing.JLabel versionLabel; 252 private javax.swing.JComboBox cbEncoding; 253 private javax.swing.JLabel encodingLabel; 254 private javax.swing.JPanel fillPanel; 255 257 259 public void initAccessibility (){ 260 261 cbVersion.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbVersion")); 262 cbEncoding.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbEncoding")); 263 264 this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeDTDCustomizer")); 265 } 266 } 267 | Popular Tags |