KickJava   Java API By Example, From Geeks To Geeks.

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


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 SELECT implements ActiveEditorDrop {
32
33     public static final int OPTIONS_DEFAULT = 2;
34     public static final int OPTIONS_VISIBLE_DEFAULT = 1;
35
36     private String JavaDoc name = "";
37     private int options = OPTIONS_DEFAULT;
38     private int optionsVisible = OPTIONS_VISIBLE_DEFAULT;
39     private boolean disabled = false;
40     private boolean multiple = false;
41     
42     
43     public SELECT() {
44     }
45
46     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
47
48         SELECTCustomizer c = new SELECTCustomizer(this);
49         boolean accept = c.showDialog();
50         if (accept) {
51             String JavaDoc body = createBody();
52             try {
53                 HTMLPaletteUtilities.insert(body, targetComponent);
54             } catch (BadLocationException JavaDoc ble) {
55                 accept = false;
56             }
57         }
58         
59         return accept;
60     }
61
62     private String JavaDoc createBody() {
63         
64         String JavaDoc sBody = generateSBody();
65         
66         String JavaDoc strName = " name=\"" + name + "\""; // NOI18N
67

68         String JavaDoc strVisibleOptions = "";
69         if (optionsVisible != OPTIONS_VISIBLE_DEFAULT)
70             strVisibleOptions = " size=\"" + optionsVisible + "\""; // NOI18N
71

72         String JavaDoc strMulti = (multiple ? " multiple=\"multiple\"" : ""); // NOI18N
73
String JavaDoc strDisabled = (disabled ? " disabled=\"disabled\"" : ""); // NOI18N
74

75         String JavaDoc selBody = "<select" + strName + strVisibleOptions + strMulti + strDisabled + ">\n" + // NOI18N
76
sBody +
77                         "</select>"; // NOI18N
78

79         return selBody;
80     }
81         
82     private String JavaDoc generateSBody() {
83         
84         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
85         for (int i = 0; i < options; i++)
86             sb.append("<option></option>\n"); // NOI18N
87

88         String JavaDoc sBody = sb.toString();
89         
90         return sBody;
91     }
92
93     public String JavaDoc getName() {
94         return name;
95     }
96
97     public void setName(String JavaDoc name) {
98         this.name = name;
99     }
100
101     public int getOptions() {
102         return options;
103     }
104
105     public void setOptions(int options) {
106         this.options = options;
107     }
108
109     public int getOptionsVisible() {
110         return optionsVisible;
111     }
112
113     public void setOptionsVisible(int optionsVisible) {
114         this.optionsVisible = optionsVisible;
115     }
116
117     public boolean isDisabled() {
118         return disabled;
119     }
120
121     public void setDisabled(boolean disabled) {
122         this.disabled = disabled;
123     }
124
125     public boolean isMultiple() {
126         return multiple;
127     }
128
129     public void setMultiple(boolean multiple) {
130         this.multiple = multiple;
131     }
132     
133 }
134
Popular Tags