KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > PropertyPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.properties;
22
23
24 import java.awt.event.KeyEvent JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import javax.swing.*;
27
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31
32 /**
33  * Panel for customizing <code>Element.ItemElem</code> element.
34  *
35  * @author Peter Zavadsky
36  * @see Element.ItemElem
37  */

38 public class PropertyPanel extends JPanel {
39
40     /** Element to customize. */
41     private Element.ItemElem element;
42
43
44     /** Creates new <code>PropertyPanel</code>.
45      * @param element element to customize */

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         // Unregister Enter on text fields so default button could work.
57
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     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
84
85         keyLabel = new javax.swing.JLabel JavaDoc();
86         keyText = new JTextField(25);
87         valueLabel = new javax.swing.JLabel JavaDoc();
88         valueText = new JTextField(25);
89         commentLabel = new javax.swing.JLabel JavaDoc();
90         commentText = new JTextField(25);
91
92         setLayout(new java.awt.GridBagLayout JavaDoc());
93
94         org.openide.awt.Mnemonics.setLocalizedText(keyLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_KeyLabel")); // NOI18N
95
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.gridx = 0;
97         gridBagConstraints.gridy = 0;
98         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
99         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
100         add(keyLabel, gridBagConstraints);
101
102         keyText.addActionListener(new java.awt.event.ActionListener JavaDoc() {
103             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
104                 keyTextActionPerformed(evt);
105             }
106         });
107         keyText.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
108             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
109                 keyTextFocusLost(evt);
110             }
111         });
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(12, 7, 0, 11);
118         add(keyText, gridBagConstraints);
119
120         org.openide.awt.Mnemonics.setLocalizedText(valueLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_ValueLabel")); // NOI18N
121
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
122         gridBagConstraints.gridx = 0;
123         gridBagConstraints.gridy = 1;
124         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
126         add(valueLabel, gridBagConstraints);
127
128         valueText.addActionListener(new java.awt.event.ActionListener JavaDoc() {
129             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
130                 valueTextActionPerformed(evt);
131             }
132         });
133         valueText.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
134             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
135                 valueTextFocusLost(evt);
136             }
137         });
138         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 7, 0, 11);
144         add(valueText, gridBagConstraints);
145
146         org.openide.awt.Mnemonics.setLocalizedText(commentLabel, NbBundle.getBundle(PropertyPanel.class).getString("LBL_CommentLabel")); // NOI18N
147
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = 0;
149         gridBagConstraints.gridy = 2;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
151         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 11, 0);
152         add(commentLabel, gridBagConstraints);
153
154         commentText.addActionListener(new java.awt.event.ActionListener JavaDoc() {
155             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
156                 commentTextActionPerformed(evt);
157             }
158         });
159         commentText.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
160             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
161                 commentTextFocusLost(evt);
162             }
163         });
164         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 7, 11, 11);
170         add(commentText, gridBagConstraints);
171     }// </editor-fold>//GEN-END:initComponents
172

173     private void valueTextFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_valueTextFocusLost
174
valueTextHandler();
175     }//GEN-LAST:event_valueTextFocusLost
176

177     private void workaround11364(ActionEvent JavaDoc 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 JavaDoc evt) {//GEN-FIRST:event_valueTextActionPerformed
188
valueTextHandler();
189         workaround11364(evt);
190     }//GEN-LAST:event_valueTextActionPerformed
191

192     
193     /** Value text field event handler. */
194     private void valueTextHandler() {
195         element.getValueElem().setValue(valueText.getText());
196     }
197     
198     private void keyTextFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_keyTextFocusLost
199
keyTextHandler();
200     }//GEN-LAST:event_keyTextFocusLost
201

202     private void keyTextActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_keyTextActionPerformed
203
keyTextHandler();
204         workaround11364(evt);
205     }//GEN-LAST:event_keyTextActionPerformed
206

207     /** Key text field event handler. */
208     private void keyTextHandler() {
209         element.getKeyElem().setValue(keyText.getText());
210     }
211     
212     private void commentTextFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_commentTextFocusLost
213
commentTextHandler();
214     }//GEN-LAST:event_commentTextFocusLost
215

216     private void commentTextActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_commentTextActionPerformed
217
commentTextHandler();
218         workaround11364(evt);
219     }//GEN-LAST:event_commentTextActionPerformed
220

221     /** Comment text field event handler. */
222     private void commentTextHandler() {
223         element.getCommentElem().setValue(commentText.getText());
224     }
225     
226     // Variables declaration - do not modify//GEN-BEGIN:variables
227
private javax.swing.JLabel JavaDoc commentLabel;
228     private javax.swing.JTextField JavaDoc commentText;
229     private javax.swing.JLabel JavaDoc keyLabel;
230     private javax.swing.JTextField JavaDoc keyText;
231     private javax.swing.JLabel JavaDoc valueLabel;
232     private javax.swing.JTextField JavaDoc valueText;
233     // End of variables declaration//GEN-END:variables
234

235 }
236
Popular Tags