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-2007 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:
042: package org.netbeans.modules.visualweb.insync.faces.refactoring;
043:
044: import java.awt.Component;
045: import java.awt.event.ItemEvent;
046: import javax.swing.JPanel;
047: import javax.swing.event.ChangeListener;
048: import javax.swing.event.DocumentEvent;
049: import javax.swing.event.DocumentListener;
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 FacesRenamePanel extends JPanel implements
058: CustomRefactoringPanel {
059:
060: private final transient ChangeListener parent;
061: private final transient String oldName;
062:
063: /** Creates new form FacesRenamePanelName */
064: public FacesRenamePanel(ChangeListener parent, String oldName,
065: String title, boolean editable) {
066: this .oldName = oldName;
067: this .parent = parent;
068: setName(title);
069: initComponents();
070: nameField.setEnabled(editable);
071: //parent.setPreviewEnabled(false);
072: nameField.requestFocus();
073: nameField.getDocument().addDocumentListener(
074: new DocumentListener() {
075: public void changedUpdate(DocumentEvent event) {
076: }
077:
078: public void insertUpdate(DocumentEvent event) {
079: fireChange();
080: }
081:
082: public void removeUpdate(DocumentEvent event) {
083: fireChange();
084: }
085: });
086: }
087:
088: private boolean initialized = false;
089:
090: public void initialize() {
091: if (initialized)
092: return;
093: //put initialization code here
094: initialized = true;
095: }
096:
097: public void requestFocus() {
098: nameField.requestFocus();
099: }
100:
101: /** This method is called from within the constructor to
102: * initialize the form.
103: * WARNING: Do NOT modify this code. The content of this method is
104: * always regenerated by the Form Editor.
105: */
106: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
107: private void initComponents() {
108: java.awt.GridBagConstraints gridBagConstraints;
109:
110: label = new javax.swing.JLabel();
111: nameField = new javax.swing.JTextField();
112: jPanel1 = new javax.swing.JPanel();
113: textCheckBox = new javax.swing.JCheckBox();
114: updateReferencesCheckBox = new javax.swing.JCheckBox();
115:
116: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
117: 11, 11));
118: setLayout(new java.awt.GridBagLayout());
119:
120: label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
121: label.setLabelFor(nameField);
122: org.openide.awt.Mnemonics.setLocalizedText(label,
123: org.openide.util.NbBundle.getMessage(
124: FacesRenamePanel.class, "LBL_NewName")); // NOI18N
125: add(label, new java.awt.GridBagConstraints());
126:
127: nameField.setText(oldName);
128: nameField.selectAll();
129: gridBagConstraints = new java.awt.GridBagConstraints();
130: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
131: gridBagConstraints.weightx = 1.0;
132: add(nameField, gridBagConstraints);
133: nameField.getAccessibleContext().setAccessibleDescription(null);
134:
135: gridBagConstraints = new java.awt.GridBagConstraints();
136: gridBagConstraints.gridx = 0;
137: gridBagConstraints.gridy = 2;
138: gridBagConstraints.gridwidth = 2;
139: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
140: gridBagConstraints.weightx = 1.0;
141: gridBagConstraints.weighty = 1.0;
142: add(jPanel1, gridBagConstraints);
143:
144: org.openide.awt.Mnemonics.setLocalizedText(textCheckBox,
145: org.openide.util.NbBundle.getBundle(
146: FacesRenamePanel.class).getString(
147: "LBL_RenameComments")); // NOI18N
148: textCheckBox.addItemListener(new java.awt.event.ItemListener() {
149: public void itemStateChanged(java.awt.event.ItemEvent evt) {
150: textCheckBoxItemStateChanged(evt);
151: }
152: });
153: gridBagConstraints = new java.awt.GridBagConstraints();
154: gridBagConstraints.gridx = 0;
155: gridBagConstraints.gridy = 1;
156: gridBagConstraints.gridwidth = 2;
157: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
158: add(textCheckBox, gridBagConstraints);
159: textCheckBox.getAccessibleContext().setAccessibleDescription(
160: textCheckBox.getText());
161:
162: org.openide.awt.Mnemonics.setLocalizedText(
163: updateReferencesCheckBox, org.openide.util.NbBundle
164: .getBundle(FacesRenamePanel.class).getString(
165: "LBL_RenameWithoutRefactoring")); // NOI18N
166: updateReferencesCheckBox.setBorder(javax.swing.BorderFactory
167: .createEmptyBorder(4, 4, 0, 4));
168: updateReferencesCheckBox.setMargin(new java.awt.Insets(2, 2, 0,
169: 2));
170: updateReferencesCheckBox
171: .addActionListener(new java.awt.event.ActionListener() {
172: public void actionPerformed(
173: java.awt.event.ActionEvent evt) {
174: updateReferencesCheckBoxActionPerformed(evt);
175: }
176: });
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.gridx = 0;
179: gridBagConstraints.gridy = 3;
180: gridBagConstraints.gridwidth = 2;
181: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
182: add(updateReferencesCheckBox, gridBagConstraints);
183: }// </editor-fold>//GEN-END:initComponents
184:
185: private void textCheckBoxItemStateChanged(
186: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_textCheckBoxItemStateChanged
187: // used for change default value for searchInComments check-box.
188: // The value is persisted and then used as default in next IDE run.
189: Boolean b = evt.getStateChange() == ItemEvent.SELECTED ? Boolean.TRUE
190: : Boolean.FALSE;
191: }//GEN-LAST:event_textCheckBoxItemStateChanged
192:
193: private void updateReferencesCheckBoxActionPerformed(
194: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateReferencesCheckBoxActionPerformed
195: textCheckBox.setEnabled(!updateReferencesCheckBox.isSelected());
196: }//GEN-LAST:event_updateReferencesCheckBoxActionPerformed
197:
198: // Variables declaration - do not modify//GEN-BEGIN:variables
199: private javax.swing.JPanel jPanel1;
200: private javax.swing.JLabel label;
201: private javax.swing.JTextField nameField;
202: private javax.swing.JCheckBox textCheckBox;
203: private javax.swing.JCheckBox updateReferencesCheckBox;
204:
205: // End of variables declaration//GEN-END:variables
206:
207: private void fireChange() {
208: parent.stateChanged(null);
209: }
210:
211: public String getNameValue() {
212: return nameField.getText();
213: }
214:
215: public boolean searchJavadoc() {
216: return textCheckBox.isSelected();
217: }
218:
219: public boolean isUpdateReferences() {
220: if (updateReferencesCheckBox.isVisible()
221: && updateReferencesCheckBox.isSelected())
222: return false;
223: return true;
224: }
225:
226: public Component getComponent() {
227: return this;
228: }
229: }
|