KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > codegen > ui > ConstructorPanel


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
20 package org.netbeans.modules.java.editor.codegen.ui;
21
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.lang.model.element.Element;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import org.netbeans.api.java.source.ElementHandle;
28 import org.netbeans.modules.java.editor.codegen.ConstructorGenerator;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Dusan Balek
34  */

35 public class ConstructorPanel extends JPanel JavaDoc {
36     
37     private JLabel JavaDoc constructorSelectorLabel;
38     private ElementSelectorPanel constructorSelector;
39     private JLabel JavaDoc fieldSelectorLabel;
40     private ElementSelectorPanel fieldSelector;
41     
42     /** Creates new form ConstructorPanel */
43     public ConstructorPanel(ElementNode.Description constructorDescription, ElementNode.Description fieldsDescription) {
44         initComponents();
45         if (constructorDescription != null) {
46             constructorSelectorLabel = new javax.swing.JLabel JavaDoc();
47             GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
48             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
49             gridBagConstraints.gridx = 0;
50             gridBagConstraints.gridy = 0;
51             gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
52             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
53             gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 6, 12);
54             add(constructorSelectorLabel, gridBagConstraints);
55             constructorSelector = new ElementSelectorPanel(constructorDescription, true);
56             gridBagConstraints.gridy = 1;
57             gridBagConstraints.weightx = 0.5;
58             gridBagConstraints.weighty = 1.0;
59             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
60             add(constructorSelector, gridBagConstraints);
61             constructorSelectorLabel.setText(NbBundle.getMessage(ConstructorGenerator.class, "LBL_super_constructor_select")); //NOI18N
62
constructorSelectorLabel.setLabelFor(constructorSelector);
63         }
64         if (fieldsDescription != null) {
65             fieldSelectorLabel = new javax.swing.JLabel JavaDoc();
66             GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
67             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
68             gridBagConstraints.gridx = 1;
69             gridBagConstraints.gridy = 0;
70             gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
71             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
72             gridBagConstraints.insets =new java.awt.Insets JavaDoc(12, constructorDescription != null ? 0 : 12, 6, 12);
73             add(fieldSelectorLabel, gridBagConstraints);
74             fieldSelector = new ElementSelectorPanel(fieldsDescription, false);
75             gridBagConstraints.gridy = 1;
76             gridBagConstraints.weightx = 0.5;
77             gridBagConstraints.weighty = 1.0;
78             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, constructorDescription != null ? 0 : 12, 0, 12);
79             add(fieldSelector, gridBagConstraints);
80             fieldSelectorLabel.setText(NbBundle.getMessage(ConstructorGenerator.class, "LBL_constructor_select")); //NOI18N
81
fieldSelectorLabel.setLabelFor(fieldSelector);
82         }
83     }
84     
85     public ElementHandle<? extends Element> getInheritedConstructor() {
86         if (constructorSelector == null)
87             return null;
88         List JavaDoc<ElementHandle<? extends Element>> handles = constructorSelector.getSelectedElements();
89         return (handles.size() == 1 ? handles.get(0) : null );
90     }
91
92     public List JavaDoc<ElementHandle<? extends Element>> getVariablesToInitialize() {
93         if (fieldSelector == null)
94             return null;
95         return ((ElementSelectorPanel)fieldSelector).getSelectedElements();
96     }
97
98     /** This method is called from within the constructor to
99      * initialize the form.
100      * WARNING: Do NOT modify this code. The content of this method is
101      * always regenerated by the Form Editor.
102      */

103     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
104
private void initComponents() {
105         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
106
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108     }// </editor-fold>//GEN-END:initComponents
109

110     
111     // Variables declaration - do not modify//GEN-BEGIN:variables
112
// End of variables declaration//GEN-END:variables
113

114 }
115
Popular Tags