001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.refactoring.java.ui;
042:
043: import java.awt.Component;
044: import java.awt.event.ItemEvent;
045: import javax.swing.JPanel;
046: import javax.swing.event.ChangeListener;
047: import javax.swing.event.DocumentEvent;
048: import javax.swing.event.DocumentListener;
049: import org.netbeans.modules.refactoring.java.RefactoringModule;
050: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
051:
052: /**
053: * Rename refactoring parameters panel
054: *
055: * @author Pavel Flaska
056: */
057: public class RenamePanel extends JPanel implements
058: CustomRefactoringPanel {
059:
060: private final transient String oldName;
061: private final transient ChangeListener parent;
062:
063: /** Creates new form RenamePanelName */
064: public RenamePanel(String oldName, ChangeListener parent,
065: String name, boolean editable, boolean showUpdateReferences) {
066: setName(name);
067: this .oldName = oldName;
068: this .parent = parent;
069: initComponents();
070: updateReferencesCheckBox.setVisible(showUpdateReferences);
071: nameField.setEnabled(editable);
072: //parent.setPreviewEnabled(false);
073: nameField.requestFocus();
074: nameField.getDocument().addDocumentListener(
075: new DocumentListener() {
076: public void changedUpdate(DocumentEvent event) {
077: RenamePanel.this .parent.stateChanged(null);
078: }
079:
080: public void insertUpdate(DocumentEvent event) {
081: RenamePanel.this .parent.stateChanged(null);
082: }
083:
084: public void removeUpdate(DocumentEvent event) {
085: RenamePanel.this .parent.stateChanged(null);
086: }
087: });
088: }
089:
090: private boolean initialized = false;
091:
092: public void initialize() {
093: if (initialized)
094: return;
095: //put initialization code here
096: initialized = true;
097: }
098:
099: public void requestFocus() {
100: nameField.requestFocus();
101: }
102:
103: /** This method is called from within the constructor to
104: * initialize the form.
105: * WARNING: Do NOT modify this code. The content of this method is
106: * always regenerated by the Form Editor.
107: */
108: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
109: private void initComponents() {
110: java.awt.GridBagConstraints gridBagConstraints;
111:
112: label = new javax.swing.JLabel();
113: nameField = new javax.swing.JTextField();
114: jPanel1 = new javax.swing.JPanel();
115: textCheckBox = new javax.swing.JCheckBox();
116: updateReferencesCheckBox = new javax.swing.JCheckBox();
117:
118: setLayout(new java.awt.GridBagLayout());
119:
120: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
121: 11, 11));
122: label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
123: label.setLabelFor(nameField);
124: org.openide.awt.Mnemonics.setLocalizedText(label,
125: org.openide.util.NbBundle.getMessage(RenamePanel.class,
126: "LBL_NewName")); // NOI18N
127: add(label, new java.awt.GridBagConstraints());
128:
129: nameField.setText(oldName);
130: nameField.selectAll();
131: gridBagConstraints = new java.awt.GridBagConstraints();
132: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133: gridBagConstraints.weightx = 1.0;
134: add(nameField, gridBagConstraints);
135: java.util.ResourceBundle bundle = java.util.ResourceBundle
136: .getBundle("org/netbeans/modules/refactoring/java/ui/Bundle"); // NOI18N
137: nameField.getAccessibleContext().setAccessibleDescription(
138: bundle.getString("ACSD_nameField")); // NOI18N
139:
140: jPanel1.setMinimumSize(new java.awt.Dimension(0, 0));
141: jPanel1.setPreferredSize(new java.awt.Dimension(0, 0));
142: gridBagConstraints = new java.awt.GridBagConstraints();
143: gridBagConstraints.gridx = 0;
144: gridBagConstraints.gridy = 2;
145: gridBagConstraints.gridwidth = 2;
146: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
147: gridBagConstraints.weightx = 1.0;
148: gridBagConstraints.weighty = 1.0;
149: add(jPanel1, gridBagConstraints);
150:
151: textCheckBox.setSelected(((Boolean) RefactoringModule
152: .getOption("searchInComments.rename", Boolean.FALSE))
153: .booleanValue());
154: org.openide.awt.Mnemonics.setLocalizedText(textCheckBox,
155: org.openide.util.NbBundle.getBundle(RenamePanel.class)
156: .getString("LBL_RenameComments")); // NOI18N
157: textCheckBox.addItemListener(new java.awt.event.ItemListener() {
158: public void itemStateChanged(java.awt.event.ItemEvent evt) {
159: textCheckBoxItemStateChanged(evt);
160: }
161: });
162:
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 0;
165: gridBagConstraints.gridy = 1;
166: gridBagConstraints.gridwidth = 2;
167: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
168: add(textCheckBox, gridBagConstraints);
169: textCheckBox.getAccessibleContext().setAccessibleDescription(
170: textCheckBox.getText());
171:
172: org.openide.awt.Mnemonics.setLocalizedText(
173: updateReferencesCheckBox, org.openide.util.NbBundle
174: .getBundle(RenamePanel.class).getString(
175: "LBL_RenameWithoutRefactoring")); // NOI18N
176: updateReferencesCheckBox.setBorder(javax.swing.BorderFactory
177: .createEmptyBorder(4, 4, 0, 4));
178: updateReferencesCheckBox.setMargin(new java.awt.Insets(2, 2, 0,
179: 2));
180: updateReferencesCheckBox
181: .addActionListener(new java.awt.event.ActionListener() {
182: public void actionPerformed(
183: java.awt.event.ActionEvent evt) {
184: updateReferencesCheckBoxActionPerformed(evt);
185: }
186: });
187:
188: gridBagConstraints = new java.awt.GridBagConstraints();
189: gridBagConstraints.gridx = 0;
190: gridBagConstraints.gridy = 3;
191: gridBagConstraints.gridwidth = 2;
192: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
193: add(updateReferencesCheckBox, gridBagConstraints);
194:
195: }// </editor-fold>//GEN-END:initComponents
196:
197: private void updateReferencesCheckBoxActionPerformed(
198: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateReferencesCheckBoxActionPerformed
199: textCheckBox.setEnabled(!updateReferencesCheckBox.isSelected());
200: parent.stateChanged(null);
201: }//GEN-LAST:event_updateReferencesCheckBoxActionPerformed
202:
203: private void textCheckBoxItemStateChanged(
204: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_textCheckBoxItemStateChanged
205: // used for change default value for searchInComments check-box.
206: // The value is persisted and then used as default in next IDE run.
207: Boolean b = evt.getStateChange() == ItemEvent.SELECTED ? Boolean.TRUE
208: : Boolean.FALSE;
209: RefactoringModule.setOption("searchInComments.rename", b); // NOI18N
210: }//GEN-LAST:event_textCheckBoxItemStateChanged
211:
212: // Variables declaration - do not modify//GEN-BEGIN:variables
213: private javax.swing.JPanel jPanel1;
214: private javax.swing.JLabel label;
215: private javax.swing.JTextField nameField;
216: private javax.swing.JCheckBox textCheckBox;
217: private javax.swing.JCheckBox updateReferencesCheckBox;
218:
219: // End of variables declaration//GEN-END:variables
220:
221: public String getNameValue() {
222: return nameField.getText();
223: }
224:
225: public boolean searchJavadoc() {
226: return textCheckBox.isSelected();
227: }
228:
229: public boolean isUpdateReferences() {
230: if (updateReferencesCheckBox.isVisible()
231: && updateReferencesCheckBox.isSelected())
232: return false;
233: return true;
234: }
235:
236: public Component getComponent() {
237: return this;
238: }
239: }
|