KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > palette > items > FORM


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.html.palette.items;
21 import javax.swing.text.BadLocationException JavaDoc;
22 import javax.swing.text.JTextComponent JavaDoc;
23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities;
24 import org.openide.text.ActiveEditorDrop;
25
26
27 /**
28  *
29  * @author Libor Kotouc
30  */

31 public class FORM implements ActiveEditorDrop {
32
33     public static final String JavaDoc METHOD_GET = "GET"; // NOI18N
34
public static final String JavaDoc METHOD_POST = "POST"; // NOI18N
35

36     public static final String JavaDoc ENC_URLENC = "application/x-www-form-urlencoded"; // NOI18N
37
public static final String JavaDoc ENC_MULTI = "multipart/form-data"; // NOI18N
38

39     private static final String JavaDoc METHOD_DEFAULT = METHOD_GET;
40     private static final String JavaDoc ENC_DEFAULT = ENC_URLENC;
41     
42     private String JavaDoc action = "";
43     private String JavaDoc method = METHOD_DEFAULT;
44     private String JavaDoc enc = ENC_DEFAULT;
45     private String JavaDoc name = "";
46     
47     public FORM() {
48     }
49
50     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
51
52         FORMCustomizer c = new FORMCustomizer(this, targetComponent);
53         boolean accept = c.showDialog();
54         if (accept) {
55             String JavaDoc body = createBody();
56             try {
57                 HTMLPaletteUtilities.insert(body, targetComponent);
58             } catch (BadLocationException JavaDoc ble) {
59                 accept = false;
60             }
61         }
62         
63         return accept;
64     }
65
66     private String JavaDoc createBody() {
67         
68         String JavaDoc strAction = "";
69         if (action.length() > 0)
70             strAction = " action=\"" + action + "\""; // NOI18N
71

72         String JavaDoc strMethod = "";
73         if (!method.equals(METHOD_DEFAULT))
74             strMethod = " method=\"" + method + "\""; // NOI18N
75

76         String JavaDoc strEnc = "";
77         if (!enc.equals(ENC_DEFAULT))
78             strEnc = " enctype=\"" + enc + "\""; // NOI18N
79

80         String JavaDoc strName = "";
81         if (name.length() > 0)
82             strName = " name=\"" + name + "\""; // NOI18N
83

84         String JavaDoc formBody = "<form" + strName + strAction + strMethod + strEnc + ">\n</form>"; // NOI18N
85

86         return formBody;
87     }
88
89     public String JavaDoc getAction() {
90         return action;
91     }
92
93     public void setAction(String JavaDoc action) {
94         this.action = action;
95     }
96
97     public String JavaDoc getMethod() {
98         return method;
99     }
100
101     public void setMethod(String JavaDoc method) {
102         this.method = method;
103     }
104
105     public String JavaDoc getEnc() {
106         return enc;
107     }
108
109     public void setEnc(String JavaDoc enc) {
110         this.enc = enc;
111     }
112
113     public String JavaDoc getName() {
114         return name;
115     }
116
117     public void setName(String JavaDoc name) {
118         this.name = name;
119     }
120         
121 }
122
Popular Tags