KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > experimental > ui > IntroduceVariablePanel


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.experimental.ui;
20 import java.awt.event.ItemEvent JavaDoc;
21 import javax.swing.ComboBoxModel JavaDoc;
22 import javax.swing.event.DocumentEvent JavaDoc;
23 import javax.swing.event.DocumentListener JavaDoc;
24 import org.netbeans.jmi.javamodel.Type;
25 import org.netbeans.modules.refactoring.RefactoringModule;
26 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
27 import org.netbeans.modules.refactoring.spi.ui.ParametersPanel;
28
29
30 /**
31  * Introduce Variable refactoring parameters panel
32  *
33  * @author Daniel Prusa
34  */

35 public class IntroduceVariablePanel extends CustomRefactoringPanel {
36
37     private final transient ParametersPanel parent;
38     private transient Type[] types;
39
40     public IntroduceVariablePanel(ParametersPanel parent, String JavaDoc defaultName, Type[] types) {
41         this.parent = parent;
42         this.types = types;
43         initComponents();
44         parent.setPreviewEnabled(false);
45         if (defaultName != null)
46             nameField.setText(defaultName);
47         nameField.requestFocus();
48         for (int x = 0; x < types.length; x++) {
49             typeCombo.addItem(types[x].getName());
50         }
51         nameField.setSelectionStart(0);
52         nameField.setSelectionEnd(nameField.getText().length());
53         nameField.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
54             public void changedUpdate(DocumentEvent JavaDoc event) {
55                 IntroduceVariablePanel.this.parent.stateChanged(null);
56             }
57             public void insertUpdate(DocumentEvent JavaDoc event) {
58                 IntroduceVariablePanel.this.parent.stateChanged(null);
59             }
60             public void removeUpdate(DocumentEvent JavaDoc event) {
61                 IntroduceVariablePanel.this.parent.stateChanged(null);
62             }
63         });
64     }
65     
66     private boolean initialized = false;
67     public void initialize() {
68         if (initialized)
69             return ;
70         //put initialization code here
71
initialized = true;
72     }
73     
74     public void requestFocus() {
75         nameField.requestFocus();
76     }
77     
78     public String JavaDoc getVariableName() {
79         return nameField.getText();
80     }
81     
82     public Type getVariableType() {
83         int index = typeCombo.getSelectedIndex();
84         return index >= 0 ? types[index] : null;
85     }
86     
87     public boolean declareFinal() {
88         return declareFinalCheckBox.isSelected();
89     }
90     
91     public boolean replaceAllOccurrences() {
92         return replaceAllCheckBox.isSelected();
93     }
94     
95     /** This method is called from within the constructor to
96      * initialize the form.
97      * WARNING: Do NOT modify this code. The content of this method is
98      * always regenerated by the Form Editor.
99      */

100     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
101
private void initComponents() {
102         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
103
104         nameLabel = new javax.swing.JLabel JavaDoc();
105         nameField = new javax.swing.JTextField JavaDoc();
106         typeLabel = new javax.swing.JLabel JavaDoc();
107         typeCombo = new javax.swing.JComboBox JavaDoc();
108         declareFinalCheckBox = new javax.swing.JCheckBox JavaDoc();
109         replaceAllCheckBox = new javax.swing.JCheckBox JavaDoc();
110         jPanel1 = new javax.swing.JPanel JavaDoc();
111
112         setLayout(new java.awt.GridBagLayout JavaDoc());
113
114         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(12, 12, 11, 11)));
115         setName(java.util.ResourceBundle.getBundle("org/netbeans/modules/refactoring/experimental/ui/Bundle").getString("LBL_IntroduceVariable"));
116         nameLabel.setLabelFor(nameField);
117         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(IntroduceVariablePanel.class, "LBL_Name"));
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 0;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         add(nameLabel, gridBagConstraints);
123
124         nameField.selectAll();
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridx = 1;
127         gridBagConstraints.gridy = 0;
128         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
130         gridBagConstraints.weightx = 1.0;
131         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 2, 3, 2);
132         add(nameField, gridBagConstraints);
133
134         typeLabel.setLabelFor(typeCombo);
135         org.openide.awt.Mnemonics.setLocalizedText(typeLabel, org.openide.util.NbBundle.getMessage(IntroduceVariablePanel.class, "LBL_Type"));
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 0;
138         gridBagConstraints.gridy = 1;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         add(typeLabel, gridBagConstraints);
141
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 1;
144         gridBagConstraints.gridy = 1;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 2, 3, 2);
148         add(typeCombo, gridBagConstraints);
149
150         org.openide.awt.Mnemonics.setLocalizedText(declareFinalCheckBox, org.openide.util.NbBundle.getMessage(IntroduceVariablePanel.class, "LBL_DeclareFinal"));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 3;
154         gridBagConstraints.gridwidth = 2;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         add(declareFinalCheckBox, gridBagConstraints);
157
158         org.openide.awt.Mnemonics.setLocalizedText(replaceAllCheckBox, org.openide.util.NbBundle.getBundle(IntroduceVariablePanel.class).getString("LBL_ReplaceAllOccurrences"));
159         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
160         gridBagConstraints.gridx = 0;
161         gridBagConstraints.gridy = 2;
162         gridBagConstraints.gridwidth = 2;
163         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
164         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 0, 0, 0);
165         add(replaceAllCheckBox, gridBagConstraints);
166
167         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
168         gridBagConstraints.gridx = 0;
169         gridBagConstraints.gridy = 4;
170         gridBagConstraints.gridwidth = 2;
171         gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
172         gridBagConstraints.weighty = 1.0;
173         add(jPanel1, gridBagConstraints);
174
175     }
176     // </editor-fold>//GEN-END:initComponents
177

178     // Variables declaration - do not modify//GEN-BEGIN:variables
179
private javax.swing.JCheckBox JavaDoc declareFinalCheckBox;
180     private javax.swing.JPanel JavaDoc jPanel1;
181     private javax.swing.JTextField JavaDoc nameField;
182     private javax.swing.JLabel JavaDoc nameLabel;
183     private javax.swing.JCheckBox JavaDoc replaceAllCheckBox;
184     private javax.swing.JComboBox JavaDoc typeCombo;
185     private javax.swing.JLabel JavaDoc typeLabel;
186     // End of variables declaration//GEN-END:variables
187

188 }
189
Popular Tags