1 19 20 package org.netbeans.modules.form.wizard; 21 22 import java.beans.*; 23 import java.util.*; 24 import javax.swing.event.*; 25 26 import org.openide.util.NbBundle; 27 import org.netbeans.modules.form.*; 28 29 34 35 class ConnectionPanel2 extends javax.swing.JPanel { 36 37 private ConnectionWizardPanel2 wizardPanel; 38 39 private Object [] propertyListData; 40 private Object [] methodListData; 41 private MethodDescriptor[] methodDescriptors; 42 private PropertyDescriptor[] propDescriptors; 43 44 java.util.ResourceBundle bundle; 45 46 47 ConnectionPanel2(ConnectionWizardPanel2 wizardPanel) { 48 this.wizardPanel = wizardPanel; 49 50 initComponents(); 51 52 bundle = NbBundle.getBundle(ConnectionPanel2.class); 53 54 setName(bundle.getString("CTL_CW_Step2_Title")); 56 javax.swing.ButtonGroup gr = new javax.swing.ButtonGroup (); 57 gr.add(propertyButton); 58 gr.add(methodButton); 59 gr.add(codeButton); 60 61 targetComponentName.setText(wizardPanel.getTargetComponent().getName()); 62 63 actionList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 64 actionList.addListSelectionListener(new ListSelectionListener() { 65 public void valueChanged(ListSelectionEvent evt) { 66 if (!evt.getValueIsAdjusting()) 67 ConnectionPanel2.this.wizardPanel.fireStateChanged(); 68 } 69 }); 70 71 targetNameLabel.setText( 73 bundle.getString("CTL_CW_TargetComponent")); targetNameLabel.setDisplayedMnemonic( 75 bundle.getString("CTL_CW_TargetComponent_Mnemonic").charAt(0)); targetComponentName.setToolTipText( 77 bundle.getString("CTL_CW_TargetComponent_Hint")); propertyButton.setText(bundle.getString("CTL_CW_SetProperty")); propertyButton.setMnemonic( 80 bundle.getString("CTL_CW_SetProperty_Mnemonic").charAt(0)); propertyButton.setToolTipText( 82 bundle.getString("CTL_CW_SetProperty_Hint")); methodButton.setText(bundle.getString("CTL_CW_MethodCall")); methodButton.setMnemonic( 85 bundle.getString("CTL_CW_MethodCall_Mnemonic").charAt(0)); methodButton.setToolTipText(bundle.getString("CTL_CW_MethodCall_Hint")); 87 codeButton.setText(bundle.getString("CTL_CW_XUserCode")); codeButton.setMnemonic( 89 bundle.getString("CTL_CW_XUserCode_Mnemonic").charAt(0)); codeButton.setToolTipText( 91 bundle.getString("CTL_CW_XUserCode_Hint")); 93 targetComponentName.getAccessibleContext().setAccessibleDescription( 94 bundle.getString("ACSD_CW_TargetComponent")); propertyButton.getAccessibleContext().setAccessibleDescription( 96 bundle.getString("ACSD_CW_SetProperty")); methodButton.getAccessibleContext().setAccessibleDescription( 98 bundle.getString("ACSD_CW_MethodCall")); codeButton.getAccessibleContext().setAccessibleDescription( 100 bundle.getString("ACSD_CW_XUserCode")); actionList.getAccessibleContext().setAccessibleDescription( 102 bundle.getString("ACSD_CW_ActionList")); getAccessibleContext().setAccessibleDescription( 104 bundle.getString("ACSD_CW_ConnectionPanel2")); 106 updateActionList(); 107 108 putClientProperty("WizardPanel_contentSelectedIndex", new Integer (1)); } 110 111 public java.awt.Dimension getPreferredSize() { 112 return new java.awt.Dimension (450, 300); 113 } 114 115 int getActionType() { 116 if (methodButton.isSelected()) 117 return ConnectionWizardPanel2.METHOD_TYPE; 118 else if (propertyButton.isSelected()) 119 return ConnectionWizardPanel2.PROPERTY_TYPE; 120 else 121 return ConnectionWizardPanel2.CODE_TYPE; 122 } 123 124 MethodDescriptor getSelectedMethod() { 125 if (!methodButton.isSelected() || actionList.getSelectedIndex() == -1) 126 return null; 127 return methodDescriptors[actionList.getSelectedIndex()]; 128 } 129 130 PropertyDescriptor getSelectedProperty() { 131 if (!propertyButton.isSelected() || actionList.getSelectedIndex() == -1) 132 return null; 133 return propDescriptors[actionList.getSelectedIndex()]; 134 } 135 136 private void updateActionList() { 137 if (codeButton.isSelected()) { 138 actionList.setListData(new String [] { 139 bundle.getString("CTL_CW_UserCodeText1"), bundle.getString("CTL_CW_UserCodeText2") }); actionList.setEnabled(false); 142 actionList.getAccessibleContext().setAccessibleName(codeButton.getText()); 143 } 144 else if (propertyButton.isSelected()) { 145 actionList.setEnabled(true); 147 if (propertyListData == null) { 148 BeanInfo targetBeanInfo = 149 wizardPanel.getTargetComponent().getBeanInfo(); 150 PropertyDescriptor[] descs = targetBeanInfo.getPropertyDescriptors(); 151 152 ArrayList list = new ArrayList(); 154 for (int i = 0; i < descs.length; i++) { 155 if (descs[i].getWriteMethod() != null) { 156 list.add(descs[i]); 157 } 158 } 159 160 Collections.sort(list, new Comparator() { 162 public int compare(Object o1, Object o2) { 163 return((PropertyDescriptor)o1).getName().compareTo(((PropertyDescriptor)o2).getName()); 164 } 165 }); 166 167 propDescriptors = new PropertyDescriptor [list.size()]; 168 list.toArray(propDescriptors); 169 170 propertyListData = new String [propDescriptors.length]; 171 for (int i = 0; i < propDescriptors.length; i++) { 172 propertyListData [i] = propDescriptors [i].getName(); 173 } 174 } 175 actionList.setListData(propertyListData); 176 actionList.getAccessibleContext().setAccessibleName(propertyButton.getText()); 177 } 178 else { 179 actionList.setEnabled(true); 181 if (methodListData == null) { 182 BeanInfo targetBeanInfo = 183 wizardPanel.getTargetComponent().getBeanInfo(); 184 methodDescriptors = targetBeanInfo.getMethodDescriptors(); 185 ArrayList list = new ArrayList(); 186 for (int i = 0; i < methodDescriptors.length; i++) { 187 list.add(methodDescriptors[i]); 188 } 189 190 Collections.sort(list, new Comparator() { 192 public int compare(Object o1, Object o2) { 193 return((MethodDescriptor)o1).getName().compareTo(((MethodDescriptor)o2).getName()); 194 } 195 }); 196 197 list.toArray(methodDescriptors); 199 200 methodListData = new String [list.size()]; 201 int i = 0; 202 for (Iterator it = list.iterator(); it.hasNext();) { 203 methodListData [i++] = getMethodName((MethodDescriptor)it.next()); 204 } 205 } 206 actionList.setListData(methodListData); 207 actionList.getAccessibleContext().setAccessibleName(methodButton.getText()); 208 } 209 actionList.revalidate(); 210 actionList.repaint(); 211 } 212 213 private static String getMethodName(MethodDescriptor desc) { 214 StringBuffer sb = new StringBuffer (desc.getName()); 215 Class [] params = desc.getMethod().getParameterTypes(); 216 if ((params == null) ||(params.length == 0)) { 217 sb.append("()"); } else { 219 for (int i = 0; i < params.length; i++) { 220 if (i == 0) sb.append("("); else sb.append(", "); sb.append(org.openide.util.Utilities.getShortClassName(params[i])); 223 } 224 sb.append(")"); } 226 227 return sb.toString(); 228 } 229 230 235 private void initComponents() { targerInfoPanel = new javax.swing.JPanel (); 237 targetNamePanel = new javax.swing.JPanel (); 238 targetNameLabel = new javax.swing.JLabel (); 239 targetComponentName = new javax.swing.JTextField (); 240 actionTypePanel = new javax.swing.JPanel (); 241 propertyButton = new javax.swing.JRadioButton (); 242 methodButton = new javax.swing.JRadioButton (); 243 codeButton = new javax.swing.JRadioButton (); 244 actionPanel = new javax.swing.JScrollPane (); 245 actionList = new javax.swing.JList (); 246 247 setLayout(new java.awt.BorderLayout (0, 2)); 248 249 targerInfoPanel.setLayout(new java.awt.BorderLayout (0, 6)); 250 251 targetNamePanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 0, 0)); 252 253 targetNameLabel.setLabelFor(targetComponentName); 254 targetNameLabel.setText("Target Component:"); 255 targetNameLabel.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (0, 0, 0, 6))); 256 targetNamePanel.add(targetNameLabel); 257 258 targetComponentName.setEditable(false); 259 targetComponentName.setText("jTextField1"); 260 targetNamePanel.add(targetComponentName); 261 262 targerInfoPanel.add(targetNamePanel, java.awt.BorderLayout.NORTH); 263 264 actionTypePanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 0, 0)); 265 266 propertyButton.setSelected(true); 267 propertyButton.setText("Set Property"); 268 propertyButton.setMargin(new java.awt.Insets (2, 2, 2, 10)); 269 propertyButton.addActionListener(new java.awt.event.ActionListener () { 270 public void actionPerformed(java.awt.event.ActionEvent evt) { 271 ConnectionPanel2.this.actionTypeButtonPressed(evt); 272 } 273 }); 274 275 actionTypePanel.add(propertyButton); 276 277 methodButton.setText("Method Call"); 278 methodButton.setMargin(new java.awt.Insets (2, 2, 2, 10)); 279 methodButton.addActionListener(new java.awt.event.ActionListener () { 280 public void actionPerformed(java.awt.event.ActionEvent evt) { 281 ConnectionPanel2.this.actionTypeButtonPressed(evt); 282 } 283 }); 284 285 actionTypePanel.add(methodButton); 286 287 codeButton.setText("User Code"); 288 codeButton.addActionListener(new java.awt.event.ActionListener () { 289 public void actionPerformed(java.awt.event.ActionEvent evt) { 290 ConnectionPanel2.this.actionTypeButtonPressed(evt); 291 } 292 }); 293 294 actionTypePanel.add(codeButton); 295 296 targerInfoPanel.add(actionTypePanel, java.awt.BorderLayout.CENTER); 297 298 add(targerInfoPanel, java.awt.BorderLayout.NORTH); 299 300 actionPanel.setViewportView(actionList); 301 302 add(actionPanel, java.awt.BorderLayout.CENTER); 303 304 } 306 private void actionTypeButtonPressed(java.awt.event.ActionEvent evt) { updateActionList(); 308 wizardPanel.fireStateChanged(); 309 if (evt.getSource() != codeButton) 310 actionList.requestFocus(); 311 } 313 private javax.swing.JRadioButton codeButton; 315 private javax.swing.JList actionList; 316 private javax.swing.JRadioButton methodButton; 317 private javax.swing.JScrollPane actionPanel; 318 private javax.swing.JPanel targetNamePanel; 319 private javax.swing.JRadioButton propertyButton; 320 private javax.swing.JPanel targerInfoPanel; 321 private javax.swing.JLabel targetNameLabel; 322 private javax.swing.JTextField targetComponentName; 323 private javax.swing.JPanel actionTypePanel; 324 } 326 | Popular Tags |