1 19 20 package org.netbeans.modules.html.palette.items; 21 import javax.swing.text.BadLocationException ; 22 import javax.swing.text.JTextComponent ; 23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 24 import org.openide.text.ActiveEditorDrop; 25 26 27 31 public class FORM implements ActiveEditorDrop { 32 33 public static final String METHOD_GET = "GET"; public static final String METHOD_POST = "POST"; 36 public static final String ENC_URLENC = "application/x-www-form-urlencoded"; public static final String ENC_MULTI = "multipart/form-data"; 39 private static final String METHOD_DEFAULT = METHOD_GET; 40 private static final String ENC_DEFAULT = ENC_URLENC; 41 42 private String action = ""; 43 private String method = METHOD_DEFAULT; 44 private String enc = ENC_DEFAULT; 45 private String name = ""; 46 47 public FORM() { 48 } 49 50 public boolean handleTransfer(JTextComponent targetComponent) { 51 52 FORMCustomizer c = new FORMCustomizer(this, targetComponent); 53 boolean accept = c.showDialog(); 54 if (accept) { 55 String body = createBody(); 56 try { 57 HTMLPaletteUtilities.insert(body, targetComponent); 58 } catch (BadLocationException ble) { 59 accept = false; 60 } 61 } 62 63 return accept; 64 } 65 66 private String createBody() { 67 68 String strAction = ""; 69 if (action.length() > 0) 70 strAction = " action=\"" + action + "\""; 72 String strMethod = ""; 73 if (!method.equals(METHOD_DEFAULT)) 74 strMethod = " method=\"" + method + "\""; 76 String strEnc = ""; 77 if (!enc.equals(ENC_DEFAULT)) 78 strEnc = " enctype=\"" + enc + "\""; 80 String strName = ""; 81 if (name.length() > 0) 82 strName = " name=\"" + name + "\""; 84 String formBody = "<form" + strName + strAction + strMethod + strEnc + ">\n</form>"; 86 return formBody; 87 } 88 89 public String getAction() { 90 return action; 91 } 92 93 public void setAction(String action) { 94 this.action = action; 95 } 96 97 public String getMethod() { 98 return method; 99 } 100 101 public void setMethod(String method) { 102 this.method = method; 103 } 104 105 public String getEnc() { 106 return enc; 107 } 108 109 public void setEnc(String enc) { 110 this.enc = enc; 111 } 112 113 public String getName() { 114 return name; 115 } 116 117 public void setName(String name) { 118 this.name = name; 119 } 120 121 } 122 | Popular Tags |