1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.beans.PropertyChangeEvent ; 22 23 import org.netbeans.tax.TreeProcessingInstruction; 24 import org.netbeans.tax.TreeException; 25 26 import org.netbeans.modules.xml.tax.util.TAXUtil; 27 28 33 public class TreeProcessingInstructionCustomizer extends AbstractTreeCustomizer { 34 35 36 private static final long serialVersionUID = 1151841201717291218L; 37 38 39 43 44 public TreeProcessingInstructionCustomizer () { 45 super (); 46 47 initComponents (); 48 targetLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlTarget")); 50 initAccessibility (); 51 } 52 53 54 58 60 protected final TreeProcessingInstruction getProcessingInstruction () { 61 return (TreeProcessingInstruction)getTreeObject (); 62 } 63 64 66 protected final void safePropertyChange (PropertyChangeEvent pche) { 67 super.safePropertyChange (pche); 68 69 if (pche.getPropertyName ().equals (TreeProcessingInstruction.PROP_TARGET)) { 70 updateTargetComponent (); 71 } else if (pche.getPropertyName ().equals (TreeProcessingInstruction.PROP_DATA)) { 72 updateDataComponent (); 73 } 74 } 75 76 78 protected final void updateProcessingInstructionTarget () { 79 try { 80 getProcessingInstruction ().setTarget (targetField.getText ()); 81 } catch (TreeException exc) { 82 updateTargetComponent (); 83 TAXUtil.notifyTreeException (exc); 84 } 85 } 86 87 89 protected final void updateTargetComponent () { 90 targetField.setText (getProcessingInstruction ().getTarget ()); 91 } 92 93 95 protected final void updateProcessingInstructionData () { 96 try { 97 getProcessingInstruction ().setData (dataTextArea.getText ()); 98 } catch (TreeException exc) { 99 updateDataComponent (); 100 TAXUtil.notifyTreeException (exc); 101 } 102 } 103 104 106 protected final void updateDataComponent () { 107 dataTextArea.setText (getProcessingInstruction ().getData ()); 108 } 109 110 112 protected final void initComponentValues () { 113 updateTargetComponent (); 114 updateDataComponent (); 115 } 116 117 118 120 protected void updateReadOnlyStatus (boolean editable) { 121 targetField.setEditable (editable); 122 dataTextArea.setEditable (editable); 123 } 124 125 130 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 132 133 targetLabel = new javax.swing.JLabel (); 134 targetField = new javax.swing.JTextField (); 135 dataPanel = new javax.swing.JPanel (); 136 dataScroll = new javax.swing.JScrollPane (); 137 dataTextArea = new javax.swing.JTextArea (); 138 139 setLayout(new java.awt.GridBagLayout ()); 140 141 setPreferredSize(new java.awt.Dimension (350, 230)); 142 targetLabel.setText(Util.THIS.getString ("PROP_xmlTarget")); 143 targetLabel.setLabelFor(targetField); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 0; 146 gridBagConstraints.gridy = 0; 147 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 148 add(targetLabel, gridBagConstraints); 149 150 targetField.setColumns(20); 151 targetField.addActionListener(new java.awt.event.ActionListener () { 152 public void actionPerformed(java.awt.event.ActionEvent evt) { 153 targetFieldActionPerformed(evt); 154 } 155 }); 156 157 targetField.addFocusListener(new java.awt.event.FocusAdapter () { 158 public void focusGained(java.awt.event.FocusEvent evt) { 159 targetFieldFocusGained(evt); 160 } 161 public void focusLost(java.awt.event.FocusEvent evt) { 162 targetFieldFocusLost(evt); 163 } 164 }); 165 166 gridBagConstraints = new java.awt.GridBagConstraints (); 167 gridBagConstraints.gridx = 1; 168 gridBagConstraints.gridy = 0; 169 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.weightx = 1.0; 172 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 173 add(targetField, gridBagConstraints); 174 175 dataPanel.setLayout(new java.awt.BorderLayout ()); 176 177 dataPanel.setPreferredSize(new java.awt.Dimension (350, 230)); 178 dataTextArea.addFocusListener(new java.awt.event.FocusAdapter () { 179 public void focusGained(java.awt.event.FocusEvent evt) { 180 dataTextAreaFocusGained(evt); 181 } 182 public void focusLost(java.awt.event.FocusEvent evt) { 183 dataTextAreaFocusLost(evt); 184 } 185 }); 186 187 dataTextArea.addKeyListener(new java.awt.event.KeyAdapter () { 188 public void keyPressed(java.awt.event.KeyEvent evt) { 189 dataTextAreaKeyPressed(evt); 190 } 191 }); 192 193 dataScroll.setViewportView(dataTextArea); 194 195 dataPanel.add(dataScroll, java.awt.BorderLayout.CENTER); 196 197 gridBagConstraints = new java.awt.GridBagConstraints (); 198 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 199 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 200 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 201 gridBagConstraints.weighty = 1.0; 202 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 203 add(dataPanel, gridBagConstraints); 204 205 } 207 private void dataTextAreaFocusGained(java.awt.event.FocusEvent evt) { if ("new".equals(getClientProperty("xml-edit-mode"))) { dataTextArea.selectAll(); 210 } 211 } 213 private void targetFieldFocusGained(java.awt.event.FocusEvent evt) { if ("new".equals(getClientProperty("xml-edit-mode"))) { targetField.selectAll(); 216 } 217 218 } 220 private void dataTextAreaKeyPressed(java.awt.event.KeyEvent evt) { if ( applyKeyPressed (evt) ) { 223 updateProcessingInstructionData (); 224 } 225 } 227 private void dataTextAreaFocusLost(java.awt.event.FocusEvent evt) { updateProcessingInstructionData (); 230 } 232 234 private void targetFieldFocusLost (java.awt.event.FocusEvent evt) { updateProcessingInstructionTarget (); 237 } 239 240 242 private void targetFieldActionPerformed (java.awt.event.ActionEvent evt) { updateProcessingInstructionTarget (); 245 } 247 248 249 private javax.swing.JTextArea dataTextArea; 251 private javax.swing.JLabel targetLabel; 252 private javax.swing.JPanel dataPanel; 253 private javax.swing.JTextField targetField; 254 private javax.swing.JScrollPane dataScroll; 255 257 259 public void initAccessibility (){ 260 this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeProcessingInstructionCustomizer")); 261 targetField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_targetField")); 262 dataTextArea.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_dataPanel1")); 263 dataTextArea.getAccessibleContext ().setAccessibleName (Util.THIS.getString ("ACSN_dataPanel1")); 264 } 265 } 266 | Popular Tags |