KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > javascript > refactoring > RenamePanel


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.languages.javascript.refactoring;
20
21 import java.awt.Component JavaDoc;
22 import javax.swing.JPanel JavaDoc;
23 import javax.swing.event.ChangeListener JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import javax.swing.event.DocumentListener JavaDoc;
26 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
27
28
29 /**
30  * JavaScript Rename refactoring parameters panel
31  *
32  * @author Daniel Prusa
33  */

34 public class RenamePanel extends JPanel JavaDoc implements CustomRefactoringPanel {
35
36     private final transient String JavaDoc oldName;
37     private final transient ChangeListener JavaDoc parent;
38     
39     /** Creates new form RenamePanelName */
40     public RenamePanel(String JavaDoc oldName, ChangeListener JavaDoc parent, String JavaDoc name) {
41         setName(name);
42         this.oldName = oldName;
43         this.parent = parent;
44         initComponents();
45         updateReferencesCheckBox.setVisible(false);
46         //nameField.setEnabled(true);
47
//parent.setPreviewEnabled(false);
48
nameField.requestFocus();
49         nameField.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
50             public void changedUpdate(DocumentEvent JavaDoc event) {
51                 RenamePanel.this.parent.stateChanged(null);
52             }
53             public void insertUpdate(DocumentEvent JavaDoc event) {
54                 RenamePanel.this.parent.stateChanged(null);
55             }
56             public void removeUpdate(DocumentEvent JavaDoc event) {
57                 RenamePanel.this.parent.stateChanged(null);
58             }
59         });
60     }
61     
62     private boolean initialized = false;
63     public void initialize() {
64         if (initialized)
65             return ;
66         //put initialization code here
67
initialized = true;
68     }
69     
70     public void requestFocus() {
71         nameField.requestFocus();
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         label = new javax.swing.JLabel JavaDoc();
84         nameField = new javax.swing.JTextField JavaDoc();
85         jPanel1 = new javax.swing.JPanel JavaDoc();
86         updateReferencesCheckBox = new javax.swing.JCheckBox JavaDoc();
87
88         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
89         setLayout(new java.awt.GridBagLayout JavaDoc());
90
91         label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
92         label.setLabelFor(nameField);
93         org.openide.awt.Mnemonics.setLocalizedText(label, org.openide.util.NbBundle.getMessage(RenamePanel.class, "LBL_NewName")); // NOI18N
94
add(label, new java.awt.GridBagConstraints JavaDoc());
95
96         nameField.setText(oldName);
97         nameField.selectAll();
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100         gridBagConstraints.weightx = 1.0;
101         add(nameField, gridBagConstraints);
102         nameField.getAccessibleContext().setAccessibleDescription(null);
103
104         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(0, 0));
105         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 2;
109         gridBagConstraints.gridwidth = 2;
110         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
111         gridBagConstraints.weightx = 1.0;
112         gridBagConstraints.weighty = 1.0;
113         add(jPanel1, gridBagConstraints);
114
115         updateReferencesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 0, 4));
116         updateReferencesCheckBox.setMargin(new java.awt.Insets JavaDoc(2, 2, 0, 2));
117         updateReferencesCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
118             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
119                 updateReferencesCheckBoxActionPerformed(evt);
120             }
121         });
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 0;
124         gridBagConstraints.gridy = 3;
125         gridBagConstraints.gridwidth = 2;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
127         add(updateReferencesCheckBox, gridBagConstraints);
128     }// </editor-fold>//GEN-END:initComponents
129

130     private void updateReferencesCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_updateReferencesCheckBoxActionPerformed
131
}//GEN-LAST:event_updateReferencesCheckBoxActionPerformed
132

133     // Variables declaration - do not modify//GEN-BEGIN:variables
134
private javax.swing.JPanel JavaDoc jPanel1;
135     private javax.swing.JLabel JavaDoc label;
136     private javax.swing.JTextField JavaDoc nameField;
137     private javax.swing.JCheckBox JavaDoc updateReferencesCheckBox;
138     // End of variables declaration//GEN-END:variables
139

140     public String JavaDoc getNameValue() {
141         return nameField.getText();
142     }
143     
144     public boolean isUpdateReferences() {
145         if (updateReferencesCheckBox.isVisible() && updateReferencesCheckBox.isSelected())
146             return false;
147         return true;
148     }
149
150     public Component JavaDoc getComponent() {
151         return this;
152     }
153 }
154
Popular Tags