~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to refactoring/java/src/org/netbeans/modules/refactoring/java/ui/InnerToOuterPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.refactoring.java.ui;
 
42
 
 
43
import java.awt.Component;
 
44
import java.awt.Dimension;
 
45
import java.awt.event.ItemEvent;
 
46
import javax.swing.JPanel;
 
47
import javax.swing.SwingUtilities;
 
48
import javax.swing.event.ChangeListener;
 
49
import javax.swing.event.DocumentEvent;
 
50
import javax.swing.event.DocumentListener;
 
51
import org.netbeans.modules.refactoring.java.api.InnerToOuterRefactoring;
 
52
import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
 
53
 
 
54
 
 
55
/** UI panel for collecting refactoring parameters.
 
56
 *
 
57
 * @author Martin Matula
 
58
 * @author Jan Becicka
 
59
 */
 
60
public class InnerToOuterPanel extends JPanel implements CustomRefactoringPanel {
 
61
    // refactoring this panel provides parameters for
 
62
    private final InnerToOuterRefactoring refactoring;
 
63
    private final ChangeListener parent;
 
64
    private boolean disableDeclareFields;
 
65
    
 
66
    /** Creates new form InnerToOuterPanel
 
67
     * @param refactoring The refactoring this panel provides parameters for.
 
68
     */
 
69
    public InnerToOuterPanel(InnerToOuterRefactoring refactoring, final ChangeListener parent, boolean disableDeclareFields) {
 
70
        this.refactoring = refactoring;
 
71
        this.parent = parent;
 
72
        initComponents();
 
73
        setPreferredSize(new Dimension(300, 130));
 
74
        this.disableDeclareFields = disableDeclareFields;
 
75
    }
 
76
    
 
77
    public Component getComponent() {
 
78
        return this;
 
79
    }
 
80
 
 
81
    /** Initialization of the panel (called by the parent window).
 
82
     */
 
83
    public void initialize() {
 
84
        SwingUtilities.invokeLater(new Runnable() {
 
85
            public void run() {
 
86
                classNameField.setText(refactoring.getClassName());
 
87
                if (disableDeclareFields) {
 
88
                    fieldCheckBox.setEnabled(false);
 
89
                } else if (refactoring.getReferenceName() != null) {
 
90
                    fieldNameField.setText(refactoring.getReferenceName());
 
91
                    fieldCheckBox.setSelected(true);
 
92
                }
 
93
                DocumentListener dl = new DocumentListener() {
 
94
                    public void changedUpdate(DocumentEvent event) {
 
95
                        parent.stateChanged(null);
 
96
                    }
 
97
                    public void insertUpdate(DocumentEvent event) {
 
98
                        parent.stateChanged(null);
 
99
                    }
 
100
                    public void removeUpdate(DocumentEvent event) {
 
101
                        parent.stateChanged(null);
 
102
                    }
 
103
                };
 
104
                classNameField.getDocument().addDocumentListener(dl);
 
105
                fieldNameField.getDocument().addDocumentListener(dl);
 
106
                classNameField.selectAll();
 
107
                classNameField.requestFocusInWindow();
 
108
            }
 
109
        });
 
110
    }
 
111
    
 
112
    // --- GETTERS FOR REFACTORING PARAMETERS ----------------------------------
 
113
    
 
114
    /** Getter used by the refactoring UI to get value
 
115
     * of target type.
 
116
     * @return Target type.
 
117
     */
 
118
    public String getClassName() {
 
119
        return classNameField.getText();
 
120
    }
 
121
    
 
122
    public String getReferenceName() {
 
123
        if (fieldCheckBox.isSelected()) {
 
124
            return fieldNameField.getText();
 
125
        } else {
 
126
            return null;
 
127
        }
 
128
    }
 
129
 
 
130
    public void requestFocus() {
 
131
        super.requestFocus();
 
132
        classNameField.requestFocus();
 
133
    }
 
134
    
 
135
    // --- GENERATED CODE ------------------------------------------------------
 
136
    
 
137
    /** This method is called from within the constructor to
 
138
     * initialize the form.
 
139
     * WARNING: Do NOT modify this code. The content of this method is
 
140
     * always regenerated by the Form Editor.
 
141
     */
 
142
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 
143
    private void initComponents() {
 
144
 
 
145
        dataPanel = new javax.swing.JPanel();
 
146
        classNameLabel = new javax.swing.JLabel();
 
147
        classNameField = new javax.swing.JTextField();
 
148
        fieldPanel = new javax.swing.JPanel();
 
149
        fieldCheckBox = new javax.swing.JCheckBox();
 
150
        fieldNamePanel = new javax.swing.JPanel();
 
151
        fieldNameLabel = new javax.swing.JLabel();
 
152
        fieldNameField = new javax.swing.JTextField();
 
153
 
 
154
        setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
 
155
        setLayout(new java.awt.BorderLayout());
 
156
 
 
157
        dataPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
 
158
        dataPanel.setLayout(new java.awt.BorderLayout(12, 0));
 
159
 
 
160
        classNameLabel.setLabelFor(classNameField);
 
161
        org.openide.awt.Mnemonics.setLocalizedText(classNameLabel, org.openide.util.NbBundle.getBundle(InnerToOuterPanel.class).getString("LBL_InnerToOuter_ClassName")); // NOI18N
 
162
        dataPanel.add(classNameLabel, java.awt.BorderLayout.WEST);
 
163
        dataPanel.add(classNameField, java.awt.BorderLayout.CENTER);
 
164
        classNameField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "ACSD_nameField")); // NOI18N
 
165
        classNameField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "ACSD_nameField")); // NOI18N
 
166
 
 
167
        fieldPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 0, 0, 0));
 
168
        fieldPanel.setLayout(new java.awt.BorderLayout());
 
169
 
 
170
        org.openide.awt.Mnemonics.setLocalizedText(fieldCheckBox, org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "LBL_InnerToOuter_DeclareField")); // NOI18N
 
171
        fieldCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 0, 4, 0));
 
172
        fieldCheckBox.addItemListener(new java.awt.event.ItemListener() {
 
173
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
 
174
                fieldCheckBoxItemStateChanged(evt);
 
175
            }
 
176
        });
 
177
        fieldPanel.add(fieldCheckBox, java.awt.BorderLayout.NORTH);
 
178
        fieldCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "ACSD_DeclareFieldName")); // NOI18N
 
179
        fieldCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "ACSD_DeclareFieldDescription")); // NOI18N
 
180
 
 
181
        fieldNamePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 32, 0, 0));
 
182
        fieldNamePanel.setLayout(new java.awt.BorderLayout(12, 0));
 
183
 
 
184
        fieldNameLabel.setLabelFor(fieldNameField);
 
185
        org.openide.awt.Mnemonics.setLocalizedText(fieldNameLabel, org.openide.util.NbBundle.getMessage(InnerToOuterPanel.class, "LBL_InnerToOuter_FieldName")); // NOI18N
 
186
        fieldNameLabel.setEnabled(false);
 
187
        fieldNamePanel.add(fieldNameLabel, java.awt.BorderLayout.WEST);
 
188
 
 
189
        fieldNameField.setEnabled(false);
 
190
        fieldNamePanel.add(fieldNameField, java.awt.BorderLayout.CENTER);
 
191
 
 
192
        fieldPanel.add(fieldNamePanel, java.awt.BorderLayout.SOUTH);
 
193
 
 
194
        dataPanel.add(fieldPanel, java.awt.BorderLayout.SOUTH);
 
195
 
 
196
        add(dataPanel, java.awt.BorderLayout.NORTH);
 
197
    }// </editor-fold>//GEN-END:initComponents
 
198
 
 
199
    private void fieldCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fieldCheckBoxItemStateChanged
 
200
        boolean enable = evt.getStateChange() == ItemEvent.SELECTED;
 
201
        fieldNameField.setEnabled(enable);
 
202
        fieldNameLabel.setEnabled(enable);
 
203
        parent.stateChanged(null);
 
204
    }//GEN-LAST:event_fieldCheckBoxItemStateChanged
 
205
    
 
206
    
 
207
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
208
    private javax.swing.JTextField classNameField;
 
209
    private javax.swing.JLabel classNameLabel;
 
210
    private javax.swing.JPanel dataPanel;
 
211
    private javax.swing.JCheckBox fieldCheckBox;
 
212
    private javax.swing.JTextField fieldNameField;
 
213
    private javax.swing.JLabel fieldNameLabel;
 
214
    private javax.swing.JPanel fieldNamePanel;
 
215
    private javax.swing.JPanel fieldPanel;
 
216
    // End of variables declaration//GEN-END:variables
 
217
    
 
218
}