1 19 20 package org.netbeans.modules.form.wizard; 21 22 import javax.swing.event.*; 23 import java.lang.reflect.Method ; 24 25 import org.openide.util.NbBundle; 26 import org.netbeans.modules.form.*; 27 28 33 34 class ConnectionPanel3 extends javax.swing.JPanel { 35 36 private ConnectionWizardPanel3 wizardPanel; 37 38 private Class [] parameters; 39 private ParametersPicker[] pickers; 40 private boolean valid = false; 41 42 private ChangeListener paramsChangeListener = null; 43 44 45 public ConnectionPanel3(ConnectionWizardPanel3 wizardPanel) { 46 this.wizardPanel = wizardPanel; 47 48 initComponents (); 49 50 java.util.ResourceBundle bundle = NbBundle.getBundle(ConnectionPanel3.class); 51 52 setName(bundle.getString("CTL_CW_Step3_Title")); 54 paramsChangeListener = new ChangeListener() { 55 public void stateChanged(ChangeEvent evt) { 56 updatePreview(); 57 } 58 }; 59 60 paramLabel.setText(bundle.getString("CTL_CW_ParamTabs")); paramLabel.setDisplayedMnemonic( 62 bundle.getString("CTL_CW_ParamTabs_Mnemonic").charAt(0)); previewLabel.setText( 64 bundle.getString("CTL_CW_GeneratedPreview")); previewLabel.setDisplayedMnemonic( 66 bundle.getString("CTL_CW_GeneratedPreview_Mnemonic").charAt(0)); previewField.setText(bundle.getString("CTL_CW_Preview")); 69 previewField.getAccessibleContext().setAccessibleDescription( 70 bundle.getString("ACSD_CW_Preview")); parameterTabs.getAccessibleContext().setAccessibleDescription( 72 bundle.getString("ACSD_CW_ParamTabs")); getAccessibleContext().setAccessibleDescription( 74 bundle.getString("ACSD_CW_ConnectionPanel3")); 76 putClientProperty("WizardPanel_contentSelectedIndex", new Integer (2)); } 78 79 public java.awt.Dimension getPreferredSize() { 80 return new java.awt.Dimension (450, 300); 81 } 82 83 void setMethod(Method m) { 84 parameterTabs.removeChangeListener(paramsChangeListener); 85 parameterTabs.removeAll(); 86 87 parameters = m.getParameterTypes(); 88 pickers = new ParametersPicker[parameters.length]; 89 for (int i=0; i < parameters.length; i++) { 90 pickers[i] = new ParametersPicker(wizardPanel.getFormModel(), 91 parameters[i]); 92 pickers[i].addChangeListener(new ChangeListener() { 93 public void stateChanged(ChangeEvent evt) { 94 updatePreview(); 95 } 96 }); 97 pickers[i].setBorder(new javax.swing.border.EmptyBorder (6, 6, 5, 5)); 98 99 parameterTabs.addTab( 100 org.openide.util.Utilities.getShortClassName(parameters[i]), 101 null, 102 pickers[i], 103 parameters[i].getName()); 104 } 105 106 valid = isValid(); 107 parameterTabs.addChangeListener(paramsChangeListener); 108 updatePreview(); 109 } 110 111 String getParametersText() { 112 StringBuffer buf = new StringBuffer (); 113 for (int i = 0; i < pickers.length; i++) { 114 buf.append(pickers[i].getText()); 115 if (i != pickers.length - 1) 116 buf.append(", "); } 118 return buf.toString(); 119 } 120 121 Object [] getParameters() { 122 try { 123 Object values[] = new Object [pickers.length]; 124 for (int i = 0; i < pickers.length; i++) 125 values[i] = pickers[i].getPropertyValue(); 126 127 return values; 128 } 129 catch (IllegalStateException e) { 130 e.printStackTrace(); 131 return null; 132 } 133 } 134 135 private String getPreviewText() { 136 StringBuffer buf = new StringBuffer (); 137 for (int i = 0; i < pickers.length; i++) { 138 buf.append(pickers[i].getPreviewText()); 139 if (i != pickers.length - 1) 140 buf.append(", "); } 142 return buf.toString(); 143 } 144 145 private void updatePreview() { 146 previewField.setText(getPreviewText()); 147 148 boolean now = isFilled(); 149 if (now != valid) { 150 valid = now; 151 wizardPanel.fireStateChanged(); 152 } 153 } 154 155 boolean isFilled() { 156 for (int i=0; i < pickers.length; i++) 157 if (!pickers[i].isFilled()) 158 return false; 159 return true; 160 } 161 162 167 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 169 170 paramLabel = new javax.swing.JLabel (); 171 parameterTabs = new javax.swing.JTabbedPane (); 172 previewLabel = new javax.swing.JLabel (); 173 previewField = new javax.swing.JTextField (); 174 175 setLayout(new java.awt.GridBagLayout ()); 176 177 paramLabel.setText("jLabel2"); 178 paramLabel.setLabelFor(parameterTabs); 179 gridBagConstraints = new java.awt.GridBagConstraints (); 180 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 181 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 182 add(paramLabel, gridBagConstraints); 183 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.gridy = 1; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 188 gridBagConstraints.weightx = 1.0; 189 gridBagConstraints.weighty = 1.0; 190 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 191 add(parameterTabs, gridBagConstraints); 192 193 previewLabel.setText("jLabel1"); 194 previewLabel.setLabelFor(previewField); 195 gridBagConstraints = new java.awt.GridBagConstraints (); 196 gridBagConstraints.gridx = 0; 197 gridBagConstraints.gridy = 2; 198 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 199 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 200 add(previewLabel, gridBagConstraints); 201 202 previewField.setEditable(false); 203 previewField.setText("jTextField1"); 204 gridBagConstraints = new java.awt.GridBagConstraints (); 205 gridBagConstraints.gridx = 0; 206 gridBagConstraints.gridy = 3; 207 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 208 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 209 add(previewField, gridBagConstraints); 210 211 } 213 private javax.swing.JLabel paramLabel; 215 private javax.swing.JTextField previewField; 216 private javax.swing.JLabel previewLabel; 217 private javax.swing.JTabbedPane parameterTabs; 218 } 220 | Popular Tags |