KickJava   Java API By Example, From Geeks To Geeks.

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


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 CHECKBOX implements ActiveEditorDrop {
32
33     public static final String JavaDoc VALUE_DEFAULT = "ON"; // NOI18N
34

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

63         String JavaDoc strValue = " value=\"" + value + "\""; // NOI18N
64

65         String JavaDoc strSelected = (selected ? " checked=\"checked\"" : ""); // NOI18N
66

67         String JavaDoc strDisabled = (disabled ? " disabled=\"disabled\"" : ""); // NOI18N
68

69         String JavaDoc inputBody = "<input type=\"checkbox\"" + strName + strValue + strSelected + strDisabled + " />"; // NOI18N
70

71         return inputBody;
72     }
73
74     public String JavaDoc getName() {
75         return name;
76     }
77
78     public void setName(String JavaDoc name) {
79         this.name = name;
80     }
81
82     public String JavaDoc getValue() {
83         return value;
84     }
85
86     public void setValue(String JavaDoc value) {
87         this.value = value;
88     }
89
90     public boolean isSelected() {
91         return selected;
92     }
93
94     public void setSelected(boolean selected) {
95         this.selected = selected;
96     }
97
98     public boolean isDisabled() {
99         return disabled;
100     }
101
102     public void setDisabled(boolean disabled) {
103         this.disabled = disabled;
104     }
105         
106 }
107
Popular Tags