1 19 20 package org.netbeans.modules.java.editor.codegen.ui; 21 22 import java.awt.GridBagConstraints ; 23 import java.util.List ; 24 import javax.lang.model.element.Element; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 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 35 public class ConstructorPanel extends JPanel { 36 37 private JLabel constructorSelectorLabel; 38 private ElementSelectorPanel constructorSelector; 39 private JLabel fieldSelectorLabel; 40 private ElementSelectorPanel fieldSelector; 41 42 43 public ConstructorPanel(ElementNode.Description constructorDescription, ElementNode.Description fieldsDescription) { 44 initComponents(); 45 if (constructorDescription != null) { 46 constructorSelectorLabel = new javax.swing.JLabel (); 47 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 48 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (0, 12, 0, 12); 60 add(constructorSelector, gridBagConstraints); 61 constructorSelectorLabel.setText(NbBundle.getMessage(ConstructorGenerator.class, "LBL_super_constructor_select")); constructorSelectorLabel.setLabelFor(constructorSelector); 63 } 64 if (fieldsDescription != null) { 65 fieldSelectorLabel = new javax.swing.JLabel (); 66 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 67 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (0, constructorDescription != null ? 0 : 12, 0, 12); 79 add(fieldSelector, gridBagConstraints); 80 fieldSelectorLabel.setText(NbBundle.getMessage(ConstructorGenerator.class, "LBL_constructor_select")); fieldSelectorLabel.setLabelFor(fieldSelector); 82 } 83 } 84 85 public ElementHandle<? extends Element> getInheritedConstructor() { 86 if (constructorSelector == null) 87 return null; 88 List <ElementHandle<? extends Element>> handles = constructorSelector.getSelectedElements(); 89 return (handles.size() == 1 ? handles.get(0) : null ); 90 } 91 92 public List <ElementHandle<? extends Element>> getVariablesToInitialize() { 93 if (fieldSelector == null) 94 return null; 95 return ((ElementSelectorPanel)fieldSelector).getSelectedElements(); 96 } 97 98 103 private void initComponents() { 105 java.awt.GridBagConstraints gridBagConstraints; 106 107 setLayout(new java.awt.GridBagLayout ()); 108 } 110 111 114 } 115 | Popular Tags |