KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > 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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.refactoring.ui.j.ui;
20 import java.awt.Component JavaDoc;
21 import javax.swing.JPanel JavaDoc;
22 import javax.swing.event.ChangeListener JavaDoc;
23 import javax.swing.event.DocumentEvent JavaDoc;
24 import javax.swing.event.DocumentListener JavaDoc;
25 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
26 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.ParametersPanel;
27 /**
28  * Rename refactoring parameters panel
29  *
30  * @author Pavel Flaska
31  */

32 public class RenamePanel extends JPanel JavaDoc implements CustomRefactoringPanel {
33
34     private final transient String JavaDoc oldName;
35    // private final transient ParametersPanel parent;
36
private final transient ChangeListener JavaDoc parent;
37
38     /** Creates new form RenamePanelName */
39     public RenamePanel(String JavaDoc oldName, ChangeListener JavaDoc parent, String JavaDoc name, boolean editable, boolean showUpdateReferences) {
40         setName(name);
41         this.oldName = oldName;
42         this.parent = parent;
43         initComponents();
44         updateReferencesCheckBox.setVisible(showUpdateReferences);
45         nameField.setEnabled(editable);
46         //parent.setPreviewEnabled(false);
47
nameField.requestFocus();
48         nameField.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
49             public void changedUpdate(DocumentEvent JavaDoc event) {
50                 RenamePanel.this.parent.stateChanged(null);
51             }
52             public void insertUpdate(DocumentEvent JavaDoc event) {
53                 RenamePanel.this.parent.stateChanged(null);
54             }
55             public void removeUpdate(DocumentEvent JavaDoc event) {
56                 RenamePanel.this.parent.stateChanged(null);
57             }
58         });
59     }
60     
61     private boolean initialized = false;
62     public void initialize() {
63         if (initialized)
64             return ;
65         //put initialization code here
66
parent.stateChanged(null);
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         setLayout(new java.awt.GridBagLayout JavaDoc());
89
90         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
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         nameField.addInputMethodListener(new java.awt.event.InputMethodListener JavaDoc() {
99             public void caretPositionChanged(java.awt.event.InputMethodEvent JavaDoc evt) {
100             }
101             public void inputMethodTextChanged(java.awt.event.InputMethodEvent JavaDoc evt) {
102                 nameFieldInputMethodTextChanged(evt);
103             }
104         });
105
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
108         gridBagConstraints.weightx = 1.0;
109         add(nameField, gridBagConstraints);
110         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/refactoring/ui/j/ui/Bundle"); // NOI18N
111
nameField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_nameField")); // NOI18N
112

113         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(0, 0));
114         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
115         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.gridx = 0;
117         gridBagConstraints.gridy = 2;
118         gridBagConstraints.gridwidth = 2;
119         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
120         gridBagConstraints.weightx = 1.0;
121         gridBagConstraints.weighty = 1.0;
122         add(jPanel1, gridBagConstraints);
123
124         org.openide.awt.Mnemonics.setLocalizedText(updateReferencesCheckBox, org.openide.util.NbBundle.getBundle(RenamePanel.class).getString("LBL_RenameWithoutRefactoring")); // NOI18N
125
updateReferencesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 0, 4));
126         updateReferencesCheckBox.setMargin(new java.awt.Insets JavaDoc(2, 2, 0, 2));
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.gridx = 0;
129         gridBagConstraints.gridy = 3;
130         gridBagConstraints.gridwidth = 2;
131         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132         add(updateReferencesCheckBox, gridBagConstraints);
133
134     }// </editor-fold>//GEN-END:initComponents
135

136     private void nameFieldInputMethodTextChanged(java.awt.event.InputMethodEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldInputMethodTextChanged
137
parent.stateChanged(null);
138     }//GEN-LAST:event_nameFieldInputMethodTextChanged
139

140     // Variables declaration - do not modify//GEN-BEGIN:variables
141
private javax.swing.JPanel JavaDoc jPanel1;
142     private javax.swing.JLabel JavaDoc label;
143     private javax.swing.JTextField JavaDoc nameField;
144     private javax.swing.JCheckBox JavaDoc updateReferencesCheckBox;
145     // End of variables declaration//GEN-END:variables
146

147     public String JavaDoc getNameValue() {
148         return nameField.getText();
149     }
150     
151     
152     public boolean isUpdateReferences() {
153         if (updateReferencesCheckBox.isVisible() && updateReferencesCheckBox.isSelected())
154             return false;
155         return true;
156     }
157     
158     public Component JavaDoc getComponent(){
159         return this;
160     }
161     
162 }
163
Popular Tags