KickJava   Java API By Example, From Geeks To Geeks.

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


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 INPUT implements ActiveEditorDrop {
32
33     public static final String JavaDoc TYPE_TEXT = "text"; // NOI18N
34
public static final String JavaDoc TYPE_PASS = "password"; // NOI18N
35
public static final String JavaDoc TYPE_HIDDEN = "hidden"; // NOI18N
36
public static final String JavaDoc STATE_DISABLED = "disabled"; // NOI18N
37
public static final String JavaDoc STATE_READONLY = "readonly"; // NOI18N
38

39     private String JavaDoc name = "";
40     private String JavaDoc value = "";
41     private String JavaDoc type = TYPE_TEXT;
42     private boolean disabled = false;
43     private boolean hidden = false;
44     private boolean readonly = false;
45     private String JavaDoc width = "";
46     
47     public INPUT() {
48     }
49
50     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
51
52         INPUTCustomizer c = new INPUTCustomizer(this);
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 strType = " type=\"" + type + "\""; // NOI18N
69

70         String JavaDoc strName = " name=\"" + name + "\""; // NOI18N
71

72         String JavaDoc strValue = " value=\"" + value + "\""; // NOI18N
73

74         String JavaDoc strReadOnly = (readonly ? " readonly=\"readonly\"" : ""); // NOI18N
75
String JavaDoc strDisabled = (disabled ? " disabled=\"disabled\"" : ""); // NOI18N
76

77         String JavaDoc strWidth = "";
78         if (width.length() > 0)
79             strWidth = " size=\"" + width + "\""; // NOI18N
80

81         String JavaDoc inputBody = "<input" + strType + strName + strValue + strWidth + strReadOnly + strDisabled + " />"; // NOI18N
82

83         return inputBody;
84     }
85
86     public String JavaDoc getType() {
87         return type;
88     }
89
90     public void setType(String JavaDoc type) {
91         this.type = type;
92     }
93
94     public String JavaDoc getName() {
95         return name;
96     }
97
98     public void setName(String JavaDoc name) {
99         this.name = name;
100     }
101
102     public String JavaDoc getValue() {
103         return value;
104     }
105
106     public void setValue(String JavaDoc value) {
107         this.value = value;
108     }
109
110     public boolean isDisabled() {
111         return disabled;
112     }
113
114     public void setDisabled(boolean disabled) {
115         this.disabled = disabled;
116     }
117
118     public boolean isHidden() {
119         return hidden;
120     }
121
122     public void setHidden(boolean hidden) {
123         this.hidden = hidden;
124     }
125
126     public String JavaDoc getWidth() {
127         return width;
128     }
129
130     public void setWidth(String JavaDoc width) {
131         this.width = width;
132     }
133
134     public boolean isReadonly() {
135         return readonly;
136     }
137
138     public void setReadonly(boolean readonly) {
139         this.readonly = readonly;
140     }
141         
142 }
143
Popular Tags