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.xml.refactoring.ui;
042:
043: import java.awt.Component;
044: import javax.swing.JPanel;
045: import javax.swing.event.ChangeListener;
046: import javax.swing.event.DocumentEvent;
047: import javax.swing.event.DocumentListener;
048: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
049:
050: /**
051: * Rename refactoring parameters panel
052: *
053: * @author Pavel Flaska
054: */
055: public class RenamePanel extends JPanel implements
056: CustomRefactoringPanel {
057:
058: private final transient String oldName;
059: // private final transient ParametersPanel parent;
060: private final transient ChangeListener parent;
061:
062: /** Creates new form RenamePanelName */
063: public RenamePanel(String oldName, ChangeListener parent,
064: String name, boolean editable, boolean showUpdateReferences) {
065: setName(name);
066: this .oldName = oldName;
067: this .parent = parent;
068: initComponents();
069: updateReferencesCheckBox.setVisible(showUpdateReferences);
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: RenamePanel.this .parent.stateChanged(null);
077: }
078:
079: public void insertUpdate(DocumentEvent event) {
080: RenamePanel.this .parent.stateChanged(null);
081: }
082:
083: public void removeUpdate(DocumentEvent event) {
084: RenamePanel.this .parent.stateChanged(null);
085: }
086: });
087: }
088:
089: private boolean initialized = false;
090:
091: public void initialize() {
092: if (initialized)
093: return;
094: //put initialization code here
095: parent.stateChanged(null);
096: initialized = true;
097: }
098:
099: public void requestFocus() {
100: nameField.setText(oldName);
101: nameField.selectAll();
102: nameField.requestFocus();
103: }
104:
105: /** This method is called from within the constructor to
106: * initialize the form.
107: * WARNING: Do NOT modify this code. The content of this method is
108: * always regenerated by the Form Editor.
109: */
110: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
111: private void initComponents() {
112: java.awt.GridBagConstraints gridBagConstraints;
113:
114: label = new javax.swing.JLabel();
115: nameField = new javax.swing.JTextField();
116: jPanel1 = new javax.swing.JPanel();
117: updateReferencesCheckBox = new javax.swing.JCheckBox();
118:
119: setLayout(new java.awt.GridBagLayout());
120:
121: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
122: 11, 11));
123: label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
124: label.setLabelFor(nameField);
125: org.openide.awt.Mnemonics.setLocalizedText(label,
126: org.openide.util.NbBundle.getMessage(RenamePanel.class,
127: "LBL_NewName"));
128: add(label, new java.awt.GridBagConstraints());
129:
130: nameField.setText(oldName);
131: nameField.selectAll();
132: nameField
133: .addInputMethodListener(new java.awt.event.InputMethodListener() {
134: public void caretPositionChanged(
135: java.awt.event.InputMethodEvent evt) {
136: }
137:
138: public void inputMethodTextChanged(
139: java.awt.event.InputMethodEvent evt) {
140: nameFieldInputMethodTextChanged(evt);
141: }
142: });
143:
144: gridBagConstraints = new java.awt.GridBagConstraints();
145: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146: gridBagConstraints.weightx = 1.0;
147: add(nameField, gridBagConstraints);
148: nameField.getAccessibleContext().setAccessibleDescription(null);
149:
150: jPanel1.setMinimumSize(new java.awt.Dimension(0, 0));
151: jPanel1.setPreferredSize(new java.awt.Dimension(0, 0));
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 2;
155: gridBagConstraints.gridwidth = 2;
156: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
157: gridBagConstraints.weightx = 1.0;
158: gridBagConstraints.weighty = 1.0;
159: add(jPanel1, gridBagConstraints);
160:
161: org.openide.awt.Mnemonics.setLocalizedText(
162: updateReferencesCheckBox, org.openide.util.NbBundle
163: .getBundle(RenamePanel.class).getString(
164: "LBL_RenameWithoutRefactoring"));
165: updateReferencesCheckBox.setBorder(javax.swing.BorderFactory
166: .createEmptyBorder(4, 4, 0, 4));
167: updateReferencesCheckBox.setMargin(new java.awt.Insets(2, 2, 0,
168: 2));
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 0;
171: gridBagConstraints.gridy = 3;
172: gridBagConstraints.gridwidth = 2;
173: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174: add(updateReferencesCheckBox, gridBagConstraints);
175:
176: }// </editor-fold>//GEN-END:initComponents
177:
178: private void nameFieldInputMethodTextChanged(
179: java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_nameFieldInputMethodTextChanged
180: parent.stateChanged(null);
181: }//GEN-LAST:event_nameFieldInputMethodTextChanged
182:
183: // Variables declaration - do not modify//GEN-BEGIN:variables
184: private javax.swing.JPanel jPanel1;
185: private javax.swing.JLabel label;
186: private javax.swing.JTextField nameField;
187: private javax.swing.JCheckBox updateReferencesCheckBox;
188:
189: // End of variables declaration//GEN-END:variables
190:
191: public String getNameValue() {
192: return nameField.getText();
193: }
194:
195: public boolean isUpdateReferences() {
196: if (updateReferencesCheckBox.isVisible()
197: && updateReferencesCheckBox.isSelected())
198: return false;
199: return true;
200: }
201:
202: public Component getComponent() {
203: return this;
204: }
205:
206: }
|