KickJava   Java API By Example, From Geeks To Geeks.

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


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 BUTTON implements ActiveEditorDrop {
32
33     public static final String JavaDoc TYPE_SUBMIT = "submit"; // NOI18N
34
public static final String JavaDoc TYPE_RESET = "reset"; // NOI18N
35
public static final String JavaDoc TYPE_BUTTON = "button"; // NOI18N
36

37     private String JavaDoc value = "";
38     private String JavaDoc type = TYPE_SUBMIT;
39     private boolean disabled = false;
40     private String JavaDoc name = "";
41     
42     public BUTTON() {
43     }
44
45     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
46
47         BUTTONCustomizer c = new BUTTONCustomizer(this);
48         boolean accept = c.showDialog();
49         if (accept) {
50             String JavaDoc body = createBody();
51             try {
52                 HTMLPaletteUtilities.insert(body, targetComponent);
53             } catch (BadLocationException JavaDoc ble) {
54                 accept = false;
55             }
56         }
57         
58         return accept;
59     }
60
61     private String JavaDoc createBody() {
62         
63         String JavaDoc strType = " type=\"" + type + "\""; // NOI18N
64

65         String JavaDoc strValue = " value=\"" + value + "\""; // NOI18N
66

67         String JavaDoc strName = "";
68         if (name.length() > 0)
69             strName = " name=\"" + name + "\""; // NOI18N
70

71         String JavaDoc strDisabled = (disabled ? " disabled=\"disabled\"" : ""); // NOI18N
72

73         String JavaDoc inputBody = "<input" + strType + strValue + strName + strDisabled + " />"; // NOI18N
74

75         return inputBody;
76     }
77
78     public String JavaDoc getValue() {
79         return value;
80     }
81
82     public void setValue(String JavaDoc value) {
83         this.value = value;
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 boolean isDisabled() {
95         return disabled;
96     }
97
98     public void setDisabled(boolean disabled) {
99         this.disabled = disabled;
100     }
101
102     public String JavaDoc getName() {
103         return name;
104     }
105
106     public void setName(String JavaDoc name) {
107         this.name = name;
108     }
109         
110 }
111
Popular Tags