KickJava   Java API By Example, From Geeks To Geeks.

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


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.java.editor.codegen.ui;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.lang.model.element.Element;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.netbeans.api.java.source.ElementHandle;
27 import org.netbeans.modules.java.editor.codegen.DelegateMethodGenerator;
28 import org.openide.explorer.ExplorerManager;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Jan Lahoda, Dusan Balek
34  */

35 public class DelegatePanel extends javax.swing.JPanel JavaDoc implements PropertyChangeListener JavaDoc {
36
37     private JTextComponent JavaDoc component;
38     private ElementSelectorPanel delegateSelector;
39     private ElementSelectorPanel methodSelector;
40
41     /** Creates new form DelegatePanel */
42     public DelegatePanel(JTextComponent JavaDoc component, ElementNode.Description description) {
43         this.component = component;
44         initComponents();
45         delegateSelector = new ElementSelectorPanel(description, false);
46         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
47         gridBagConstraints.gridx = 0;
48         gridBagConstraints.gridy = 1;
49         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
50         gridBagConstraints.weightx = 0.5;
51         gridBagConstraints.weighty = 1.0;
52         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
53         add(delegateSelector, gridBagConstraints);
54         delegateSelector.getExplorerManager().addPropertyChangeListener(this);
55         
56         methodSelector = new ElementSelectorPanel(null, false);
57         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
58         gridBagConstraints.gridx = 1;
59         gridBagConstraints.gridy = 1;
60         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
61         gridBagConstraints.weightx = 0.5;
62         gridBagConstraints.weighty = 1.0;
63         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
64         add(methodSelector, gridBagConstraints);
65         
66         delegateLabel.setText(NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_field_select")); //NOI18N
67
delegateLabel.setLabelFor(delegateSelector);
68         methodLabel.setText(NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_method_select")); //NOI18N
69
methodLabel.setLabelFor(methodSelector);
70         
71         
72         delegateSelector.doInitialExpansion(1);
73     }
74
75     public ElementHandle<? extends Element> getDelegateField() {
76         List JavaDoc<ElementHandle<? extends Element>> handles = delegateSelector.getTreeSelectedElements();
77         return handles.size() == 1 ? handles.get(0) : null;
78     }
79
80     public List JavaDoc<ElementHandle<? extends Element>> getDelegateMethods() {
81         return ((ElementSelectorPanel)methodSelector).getSelectedElements();
82     }
83
84     /** This method is called from within the constructor to
85      * initialize the form.
86      * WARNING: Do NOT modify this code. The content of this method is
87      * always regenerated by the Form Editor.
88      */

89     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
90
private void initComponents() {
91         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
92
93         delegateLabel = new javax.swing.JLabel JavaDoc();
94         methodLabel = new javax.swing.JLabel JavaDoc();
95
96         setFocusable(false);
97         setLayout(new java.awt.GridBagLayout JavaDoc());
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.gridx = 0;
100         gridBagConstraints.gridy = 0;
101         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
102         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
103         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 6, 12);
104         add(delegateLabel, gridBagConstraints);
105         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
106         gridBagConstraints.gridx = 1;
107         gridBagConstraints.gridy = 0;
108         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110         gridBagConstraints.weightx = 0.5;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 6, 12);
112         add(methodLabel, gridBagConstraints);
113     }// </editor-fold>//GEN-END:initComponents
114

115     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
116         if ( ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) ) {
117             ElementHandle<? extends Element> handle = getDelegateField();
118             methodSelector.setRootElement(handle == null ? null : DelegateMethodGenerator.getAvailableMethods(component, handle), false);
119             methodSelector.doInitialExpansion(-1);
120         }
121     }
122
123     // Variables declaration - do not modify//GEN-BEGIN:variables
124
public javax.swing.JLabel JavaDoc delegateLabel;
125     public javax.swing.JLabel JavaDoc methodLabel;
126     // End of variables declaration//GEN-END:variables
127
}
128
Popular Tags