1 19 20 package org.netbeans.modules.html.palette.items; 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import javax.swing.text.Document ; 26 import javax.swing.text.JTextComponent ; 27 import org.netbeans.api.project.SourceGroup; 28 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 29 import org.netbeans.modules.editor.NbEditorUtilities; 30 import org.openide.DialogDescriptor; 31 import org.openide.DialogDisplayer; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.netbeans.modules.html.palette.BrowseFolders; 35 import org.openide.util.NbBundle; 36 37 38 39 40 44 public class FORMCustomizer extends javax.swing.JPanel { 45 46 private Dialog dialog = null; 47 private DialogDescriptor descriptor = null; 48 private boolean dialogOK = false; 49 50 FORM form; 51 JTextComponent target; 52 53 public FORMCustomizer(FORM form, JTextComponent target) { 54 this.form = form; 55 this.target = target; 56 57 initComponents(); 58 } 59 60 public boolean showDialog() { 61 62 dialogOK = false; 63 64 String displayName = ""; 65 try { 66 displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-FORM"); } 68 catch (Exception e) {} 69 70 descriptor = new DialogDescriptor 71 (this, NbBundle.getMessage(FORMCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true, 72 DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, 73 new ActionListener () { 74 public void actionPerformed(ActionEvent e) { 75 if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { 76 evaluateInput(); 77 dialogOK = true; 78 } 79 dialog.dispose(); 80 } 81 } 82 ); 83 84 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 85 dialog.setVisible(true); 86 repaint(); 87 88 return dialogOK; 89 } 90 91 private void evaluateInput() { 92 93 String action = jTextField1.getText(); 94 form.setAction(action); 95 96 if (jRadioButton1.isSelected()) 97 form.setMethod(FORM.METHOD_GET); 98 if (jRadioButton2.isSelected()) 99 form.setMethod(FORM.METHOD_POST); 100 101 if (jRadioButton3.isSelected()) 102 form.setEnc(FORM.ENC_URLENC); 103 if (jRadioButton4.isSelected()) 104 form.setEnc(FORM.ENC_MULTI); 105 106 String name = jTextField4.getText(); 107 form.setName(name); 108 109 } 110 111 private void setEncoding() { 112 113 if (jRadioButton1.isSelected()) { jRadioButton3.setSelected(true); 115 jRadioButton3.setEnabled(false); 116 jRadioButton4.setEnabled(false); 117 } 118 else if (jRadioButton2.isSelected()) { jRadioButton3.setEnabled(true); 120 jRadioButton4.setEnabled(true); 121 jRadioButton3.setSelected(true); 122 } 123 } 124 125 130 private void initComponents() { 132 java.awt.GridBagConstraints gridBagConstraints; 133 134 jFileChooser1 = new javax.swing.JFileChooser (); 135 buttonGroup1 = new javax.swing.ButtonGroup (); 136 buttonGroup2 = new javax.swing.ButtonGroup (); 137 jLabel4 = new javax.swing.JLabel (); 138 jTextField1 = new javax.swing.JTextField (); 139 jButton1 = new javax.swing.JButton (); 140 jLabel1 = new javax.swing.JLabel (); 141 jLabel2 = new javax.swing.JLabel (); 142 jLabel3 = new javax.swing.JLabel (); 143 jTextField4 = new javax.swing.JTextField (); 144 jRadioButton1 = new javax.swing.JRadioButton (); 145 jRadioButton2 = new javax.swing.JRadioButton (); 146 jRadioButton3 = new javax.swing.JRadioButton (); 147 jRadioButton4 = new javax.swing.JRadioButton (); 148 149 jFileChooser1.setCurrentDirectory(null); 150 151 setLayout(new java.awt.GridBagLayout ()); 152 153 jLabel4.setLabelFor(jTextField4); 154 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "LBL_FORM_Name")); 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridx = 0; 157 gridBagConstraints.gridy = 6; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 160 gridBagConstraints.weighty = 1.0; 161 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 0); 162 add(jLabel4, gridBagConstraints); 163 jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSN_FORM_Name")); 164 jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_Name")); 165 166 jTextField1.setColumns(30); 167 gridBagConstraints = new java.awt.GridBagConstraints (); 168 gridBagConstraints.gridx = 1; 169 gridBagConstraints.gridy = 0; 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 172 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 173 add(jTextField1, gridBagConstraints); 174 175 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "LBL_FORM_Browse")); 176 jButton1.addActionListener(new java.awt.event.ActionListener () { 177 public void actionPerformed(java.awt.event.ActionEvent evt) { 178 jButton1ActionPerformed(evt); 179 } 180 }); 181 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridx = 2; 184 gridBagConstraints.gridy = 0; 185 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 186 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 187 add(jButton1, gridBagConstraints); 188 jButton1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSN_FORM_Browse")); 189 jButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_Browse")); 190 191 jLabel1.setLabelFor(jTextField1); 192 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "LBL_FORM_Action")); 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridx = 0; 195 gridBagConstraints.gridy = 0; 196 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 197 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 198 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 199 add(jLabel1, gridBagConstraints); 200 jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSN_FORM_Action")); 201 jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_Action")); 202 203 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "LBL_FORM_Method")); 204 gridBagConstraints = new java.awt.GridBagConstraints (); 205 gridBagConstraints.gridx = 0; 206 gridBagConstraints.gridy = 1; 207 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 208 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 209 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 210 add(jLabel2, gridBagConstraints); 211 jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSN_FORM_Method")); 212 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_Method")); 213 214 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "LBL_FORM_Encoding")); 215 gridBagConstraints = new java.awt.GridBagConstraints (); 216 gridBagConstraints.gridx = 0; 217 gridBagConstraints.gridy = 3; 218 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 219 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 220 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 221 add(jLabel3, gridBagConstraints); 222 jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSN_FORM_Encoding")); 223 jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_Encoding")); 224 225 jTextField4.setColumns(30); 226 gridBagConstraints = new java.awt.GridBagConstraints (); 227 gridBagConstraints.gridx = 1; 228 gridBagConstraints.gridy = 6; 229 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 230 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 231 gridBagConstraints.weightx = 1.0; 232 gridBagConstraints.weighty = 1.0; 233 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 0); 234 add(jTextField4, gridBagConstraints); 235 236 buttonGroup1.add(jRadioButton1); 237 jRadioButton1.setSelected(true); 238 org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1, "&GET"); 239 jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 240 jRadioButton1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 241 jRadioButton1.addItemListener(new java.awt.event.ItemListener () { 242 public void itemStateChanged(java.awt.event.ItemEvent evt) { 243 jRadioButton1ItemStateChanged(evt); 244 } 245 }); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 1; 249 gridBagConstraints.gridy = 1; 250 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 251 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 252 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 253 add(jRadioButton1, gridBagConstraints); 254 jRadioButton1.getAccessibleContext().setAccessibleName("GET"); 255 jRadioButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_GET")); 256 257 buttonGroup1.add(jRadioButton2); 258 org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2, "&POST"); 259 jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 260 jRadioButton2.setMargin(new java.awt.Insets (0, 0, 0, 0)); 261 jRadioButton2.addItemListener(new java.awt.event.ItemListener () { 262 public void itemStateChanged(java.awt.event.ItemEvent evt) { 263 jRadioButton2ItemStateChanged(evt); 264 } 265 }); 266 267 gridBagConstraints = new java.awt.GridBagConstraints (); 268 gridBagConstraints.gridx = 1; 269 gridBagConstraints.gridy = 2; 270 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 271 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 272 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 273 add(jRadioButton2, gridBagConstraints); 274 jRadioButton2.getAccessibleContext().setAccessibleName("POST"); 275 jRadioButton2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_POST")); 276 277 buttonGroup2.add(jRadioButton3); 278 jRadioButton3.setSelected(true); 279 org.openide.awt.Mnemonics.setLocalizedText(jRadioButton3, "application/x-www-form-&urlencoded"); 280 jRadioButton3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 281 jRadioButton3.setEnabled(false); 282 jRadioButton3.setMargin(new java.awt.Insets (0, 0, 0, 0)); 283 gridBagConstraints = new java.awt.GridBagConstraints (); 284 gridBagConstraints.gridx = 1; 285 gridBagConstraints.gridy = 3; 286 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 287 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 288 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 289 add(jRadioButton3, gridBagConstraints); 290 jRadioButton3.getAccessibleContext().setAccessibleName("application/x-www-form-urlencoded"); 291 jRadioButton3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_urlenc")); 292 293 buttonGroup2.add(jRadioButton4); 294 org.openide.awt.Mnemonics.setLocalizedText(jRadioButton4, "multipart/form-&data"); 295 jRadioButton4.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 296 jRadioButton4.setEnabled(false); 297 jRadioButton4.setMargin(new java.awt.Insets (0, 0, 0, 0)); 298 gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.gridx = 1; 300 gridBagConstraints.gridy = 4; 301 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 302 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 303 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 304 add(jRadioButton4, gridBagConstraints); 305 jRadioButton4.getAccessibleContext().setAccessibleName("multipart/form-data"); 306 jRadioButton4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FORMCustomizer.class, "ACSD_FORM_multi")); 307 308 } 310 private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) { setEncoding(); 312 } 314 private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) { setEncoding(); 316 } 318 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 320 Document targetDoc = target.getDocument(); 321 FileObject targetDocFO = NbEditorUtilities.getFileObject(targetDoc); 322 SourceGroup[] sg = HTMLPaletteUtilities.getSourceGroups(targetDocFO); 323 324 File file = null; 325 if (sg.length > 0) { 326 FileObject fo = BrowseFolders.showDialog(sg); 327 if (fo != null) 328 file = FileUtil.toFile(fo); 329 } 330 else { 331 jFileChooser1.setCurrentDirectory(FileUtil.toFile(targetDocFO.getParent())); 332 int returnVal = jFileChooser1.showOpenDialog(this); 333 334 if (returnVal == jFileChooser1.APPROVE_OPTION) 335 file = jFileChooser1.getSelectedFile(); 336 } 337 338 if (file != null) { 339 String path = file.getAbsolutePath(); 340 FileObject actionFO = FileUtil.toFileObject(file); 341 try { 342 String relPathToAction = HTMLPaletteUtilities.getRelativePath(targetDocFO, actionFO); 343 if (relPathToAction.length() > 0) 344 path = relPathToAction; 345 } 346 catch (Exception e) { 347 } 349 350 jTextField1.setText(path); 351 } 352 } 354 355 private javax.swing.ButtonGroup buttonGroup1; 357 private javax.swing.ButtonGroup buttonGroup2; 358 private javax.swing.JButton jButton1; 359 private javax.swing.JFileChooser jFileChooser1; 360 private javax.swing.JLabel jLabel1; 361 private javax.swing.JLabel jLabel2; 362 private javax.swing.JLabel jLabel3; 363 private javax.swing.JLabel jLabel4; 364 private javax.swing.JRadioButton jRadioButton1; 365 private javax.swing.JRadioButton jRadioButton2; 366 private javax.swing.JRadioButton jRadioButton3; 367 private javax.swing.JRadioButton jRadioButton4; 368 private javax.swing.JTextField jTextField1; 369 private javax.swing.JTextField jTextField4; 370 372 } 373 | Popular Tags |