KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > ui > 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.refactoring.java.ui;
20 import java.awt.Component JavaDoc;
21 import java.awt.event.ItemEvent 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.java.RefactoringModule;
27 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
28
29
30 /**
31  * Rename refactoring parameters panel
32  *
33  * @author Pavel Flaska
34  */

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

80     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
81
private void initComponents() {
82         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
83
84         label = new javax.swing.JLabel JavaDoc();
85         nameField = new javax.swing.JTextField JavaDoc();
86         jPanel1 = new javax.swing.JPanel JavaDoc();
87         textCheckBox = new javax.swing.JCheckBox JavaDoc();
88         updateReferencesCheckBox = new javax.swing.JCheckBox JavaDoc();
89
90         setLayout(new java.awt.GridBagLayout JavaDoc());
91
92         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
93         label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
94         label.setLabelFor(nameField);
95         org.openide.awt.Mnemonics.setLocalizedText(label, org.openide.util.NbBundle.getMessage(RenamePanel.class, "LBL_NewName")); // NOI18N
96
add(label, new java.awt.GridBagConstraints JavaDoc());
97
98         nameField.setText(oldName);
99         nameField.selectAll();
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
102         gridBagConstraints.weightx = 1.0;
103         add(nameField, gridBagConstraints);
104         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/refactoring/java/ui/Bundle"); // NOI18N
105
nameField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_nameField")); // NOI18N
106

107         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(0, 0));
108         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 0;
111         gridBagConstraints.gridy = 2;
112         gridBagConstraints.gridwidth = 2;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
114         gridBagConstraints.weightx = 1.0;
115         gridBagConstraints.weighty = 1.0;
116         add(jPanel1, gridBagConstraints);
117
118         textCheckBox.setSelected(((Boolean JavaDoc) RefactoringModule.getOption("searchInComments.rename", Boolean.FALSE)).booleanValue());
119         org.openide.awt.Mnemonics.setLocalizedText(textCheckBox, org.openide.util.NbBundle.getBundle(RenamePanel.class).getString("LBL_RenameComments")); // NOI18N
120
textCheckBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
121             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
122                 textCheckBoxItemStateChanged(evt);
123             }
124         });
125
126         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints.gridx = 0;
128         gridBagConstraints.gridy = 1;
129         gridBagConstraints.gridwidth = 2;
130         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
131         add(textCheckBox, gridBagConstraints);
132         textCheckBox.getAccessibleContext().setAccessibleDescription(textCheckBox.getText());
133
134         org.openide.awt.Mnemonics.setLocalizedText(updateReferencesCheckBox, org.openide.util.NbBundle.getBundle(RenamePanel.class).getString("LBL_RenameWithoutRefactoring")); // NOI18N
135
updateReferencesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 0, 4));
136         updateReferencesCheckBox.setMargin(new java.awt.Insets JavaDoc(2, 2, 0, 2));
137         updateReferencesCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
138             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
139                 updateReferencesCheckBoxActionPerformed(evt);
140             }
141         });
142
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 0;
145         gridBagConstraints.gridy = 3;
146         gridBagConstraints.gridwidth = 2;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148         add(updateReferencesCheckBox, gridBagConstraints);
149
150     }// </editor-fold>//GEN-END:initComponents
151

152     private void updateReferencesCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_updateReferencesCheckBoxActionPerformed
153
textCheckBox.setEnabled(!updateReferencesCheckBox.isSelected());
154     }//GEN-LAST:event_updateReferencesCheckBoxActionPerformed
155

156     private void textCheckBoxItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_textCheckBoxItemStateChanged
157
// used for change default value for searchInComments check-box.
158
// The value is persisted and then used as default in next IDE run.
159
Boolean JavaDoc b = evt.getStateChange() == ItemEvent.SELECTED ? Boolean.TRUE : Boolean.FALSE;
160         RefactoringModule.setOption("searchInComments.rename", b);
161     }//GEN-LAST:event_textCheckBoxItemStateChanged
162

163     // Variables declaration - do not modify//GEN-BEGIN:variables
164
private javax.swing.JPanel JavaDoc jPanel1;
165     private javax.swing.JLabel JavaDoc label;
166     private javax.swing.JTextField JavaDoc nameField;
167     private javax.swing.JCheckBox JavaDoc textCheckBox;
168     private javax.swing.JCheckBox JavaDoc updateReferencesCheckBox;
169     // End of variables declaration//GEN-END:variables
170

171     public String JavaDoc getNameValue() {
172         return nameField.getText();
173     }
174     
175     public boolean searchJavadoc() {
176         return textCheckBox.isSelected();
177     }
178     
179     public boolean isUpdateReferences() {
180         if (updateReferencesCheckBox.isVisible() && updateReferencesCheckBox.isSelected())
181             return false;
182         return true;
183     }
184
185     public Component JavaDoc getComponent() {
186         return this;
187     }
188 }
189
Popular Tags