KickJava   Java API By Example, From Geeks To Geeks.

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


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 TEXTAREA implements ActiveEditorDrop {
32
33     public static final String JavaDoc STATE_DISABLED = "disabled"; // NOI18N
34
public static final String JavaDoc STATE_READONLY = "readonly"; // NOI18N
35

36     public static final int ROWS_DEFAULT = 4;
37     public static final int COLS_DEFAULT = 20;
38     
39     private String JavaDoc name = "";
40     private String JavaDoc value = "";
41     private boolean disabled = false;
42     private boolean readonly = false;
43     private int rows = ROWS_DEFAULT;
44     private int cols = COLS_DEFAULT;
45     
46     public TEXTAREA() {
47     }
48
49     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
50
51         TEXTAREACustomizer c = new TEXTAREACustomizer(this);
52         boolean accept = c.showDialog();
53         if (accept) {
54             String JavaDoc body = createBody();
55             try {
56                 HTMLPaletteUtilities.insert(body, targetComponent);
57             } catch (BadLocationException JavaDoc ble) {
58                 accept = false;
59             }
60         }
61         
62         return accept;
63     }
64
65     private String JavaDoc createBody() {
66         
67         String JavaDoc strName = " name=\"" + name + "\""; // NOI18N
68

69         String JavaDoc strValue = value;
70         if (value.length() > 0)
71             strValue += "\n";
72
73         String JavaDoc strReadOnly = (readonly ? " readonly=\"readonly\"" : ""); // NOI18N
74
String JavaDoc strDisabled = (disabled ? " disabled=\"disabled\"" : ""); // NOI18N
75

76         String JavaDoc strRows = " rows=\"" + rows + "\""; // NOI18N
77
String JavaDoc strCols = " cols=\"" + cols + "\""; // NOI18N
78

79         String JavaDoc taBody = "<textarea" + strName + strRows + strCols + strReadOnly + strDisabled + ">\n" + // NOI18N
80
strValue +
81                         "</textarea>"; // NOI18N
82

83         return taBody;
84     }
85
86     public String JavaDoc getName() {
87         return name;
88     }
89
90     public String JavaDoc getValue() {
91         return value;
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 boolean isReadonly() {
103         return readonly;
104     }
105
106     public void setReadonly(boolean readonly) {
107         this.readonly = readonly;
108     }
109
110     public int getRows() {
111         return rows;
112     }
113
114     public void setRows(int rows) {
115         this.rows = rows;
116     }
117
118     public int getCols() {
119         return cols;
120     }
121
122     public void setCols(int cols) {
123         this.cols = cols;
124     }
125
126     public void setName(String JavaDoc name) {
127         this.name = name;
128     }
129
130     public void setValue(String JavaDoc value) {
131         this.value = value;
132     }
133         
134 }
135
Popular Tags