1 19 20 21 package org.netbeans.modules.properties; 22 23 24 import java.awt.event.KeyEvent ; 25 import java.awt.event.ActionEvent ; 26 import javax.swing.*; 27 28 import org.openide.util.HelpCtx; 29 import org.openide.util.NbBundle; 30 31 32 38 public class PropertyPanel extends JPanel { 39 40 41 private Element.ItemElem element; 42 43 44 46 public PropertyPanel(Element.ItemElem element) { 47 this.element = element; 48 49 initComponents(); 50 initAccessibility(); 51 52 keyText.setText(element.getKey()); 53 valueText.setText(element.getValue()); 54 commentText.setText(element.getComment()); 55 56 keyText.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 58 valueText.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 59 commentText.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); 60 61 HelpCtx.setHelpIDString(this, Util.HELP_ID_ADDING); 62 } 63 64 private void initAccessibility() { 65 this.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(PropertyPanel.class).getString("ACS_PropertyPanel")); 66 67 keyLabel.setLabelFor(keyText); 68 valueLabel.setLabelFor(valueText); 69 commentLabel.setLabelFor(commentText); 70 71 keyText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(PropertyPanel.class).getString("ACS_PropertyPanel")); 72 valueText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(PropertyPanel.class).getString("ACS_PropertyPanel")); 73 commentText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(PropertyPanel.class).getString("ACS_PropertyPanel")); 74 } 75 76 81 private void initComponents() { 83 java.awt.GridBagConstraints gridBagConstraints; 84 85 keyLabel = new javax.swing.JLabel (); 86 keyText = new JTextField(25); 87 valueLabel = new javax.swing.JLabel (); 88 valueText = new JTextField(25); 89 commentLabel = new javax.swing.JLabel (); 90 commentText = new JTextField(25); 91 92 setLayout(new java.awt.GridBagLayout ()); 93 94 org.openide.awt.Mnemonics.setLocalizedText(keyLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_KeyLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 96 gridBagConstraints.gridx = 0; 97 gridBagConstraints.gridy = 0; 98 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 99 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 100 add(keyLabel, gridBagConstraints); 101 102 keyText.addActionListener(new java.awt.event.ActionListener () { 103 public void actionPerformed(java.awt.event.ActionEvent evt) { 104 keyTextActionPerformed(evt); 105 } 106 }); 107 keyText.addFocusListener(new java.awt.event.FocusAdapter () { 108 public void focusLost(java.awt.event.FocusEvent evt) { 109 keyTextFocusLost(evt); 110 } 111 }); 112 gridBagConstraints = new java.awt.GridBagConstraints (); 113 gridBagConstraints.gridx = 1; 114 gridBagConstraints.gridy = 0; 115 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 116 gridBagConstraints.weightx = 1.0; 117 gridBagConstraints.insets = new java.awt.Insets (12, 7, 0, 11); 118 add(keyText, gridBagConstraints); 119 120 org.openide.awt.Mnemonics.setLocalizedText(valueLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_ValueLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 122 gridBagConstraints.gridx = 0; 123 gridBagConstraints.gridy = 1; 124 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 125 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 126 add(valueLabel, gridBagConstraints); 127 128 valueText.addActionListener(new java.awt.event.ActionListener () { 129 public void actionPerformed(java.awt.event.ActionEvent evt) { 130 valueTextActionPerformed(evt); 131 } 132 }); 133 valueText.addFocusListener(new java.awt.event.FocusAdapter () { 134 public void focusLost(java.awt.event.FocusEvent evt) { 135 valueTextFocusLost(evt); 136 } 137 }); 138 gridBagConstraints = new java.awt.GridBagConstraints (); 139 gridBagConstraints.gridx = 1; 140 gridBagConstraints.gridy = 1; 141 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 142 gridBagConstraints.weightx = 1.0; 143 gridBagConstraints.insets = new java.awt.Insets (5, 7, 0, 11); 144 add(valueText, gridBagConstraints); 145 146 org.openide.awt.Mnemonics.setLocalizedText(commentLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_CommentLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 0; 149 gridBagConstraints.gridy = 2; 150 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 151 gridBagConstraints.insets = new java.awt.Insets (5, 12, 11, 0); 152 add(commentLabel, gridBagConstraints); 153 154 commentText.addActionListener(new java.awt.event.ActionListener () { 155 public void actionPerformed(java.awt.event.ActionEvent evt) { 156 commentTextActionPerformed(evt); 157 } 158 }); 159 commentText.addFocusListener(new java.awt.event.FocusAdapter () { 160 public void focusLost(java.awt.event.FocusEvent evt) { 161 commentTextFocusLost(evt); 162 } 163 }); 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 1; 166 gridBagConstraints.gridy = 2; 167 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 168 gridBagConstraints.weightx = 1.0; 169 gridBagConstraints.insets = new java.awt.Insets (5, 7, 11, 11); 170 add(commentText, gridBagConstraints); 171 } 173 private void valueTextFocusLost(java.awt.event.FocusEvent evt) { valueTextHandler(); 175 } 177 private void workaround11364(ActionEvent evt) { 178 JRootPane root = getRootPane(); 179 if (root != null) { 180 JButton defaultButton = root.getDefaultButton(); 181 if (defaultButton != null) { 182 defaultButton.doClick(); 183 } 184 } 185 } 186 187 private void valueTextActionPerformed(java.awt.event.ActionEvent evt) { valueTextHandler(); 189 workaround11364(evt); 190 } 192 193 194 private void valueTextHandler() { 195 element.getValueElem().setValue(valueText.getText()); 196 } 197 198 private void keyTextFocusLost(java.awt.event.FocusEvent evt) { keyTextHandler(); 200 } 202 private void keyTextActionPerformed(java.awt.event.ActionEvent evt) { keyTextHandler(); 204 workaround11364(evt); 205 } 207 208 private void keyTextHandler() { 209 element.getKeyElem().setValue(keyText.getText()); 210 } 211 212 private void commentTextFocusLost(java.awt.event.FocusEvent evt) { commentTextHandler(); 214 } 216 private void commentTextActionPerformed(java.awt.event.ActionEvent evt) { commentTextHandler(); 218 workaround11364(evt); 219 } 221 222 private void commentTextHandler() { 223 element.getCommentElem().setValue(commentText.getText()); 224 } 225 226 private javax.swing.JLabel commentLabel; 228 private javax.swing.JTextField commentText; 229 private javax.swing.JLabel keyLabel; 230 private javax.swing.JTextField keyText; 231 private javax.swing.JLabel valueLabel; 232 private javax.swing.JTextField valueText; 233 235 } 236 | Popular Tags |