KickJava   Java API By Example, From Geeks To Geeks.

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


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 UL implements ActiveEditorDrop {
32
33     public static final int ITEM_COUNT_DEFAULT = 2;
34
35     public static final String JavaDoc DEFAULT = "default"; // NOI18N
36
public static final String JavaDoc DISC = "disc"; // NOI18N
37
public static final String JavaDoc CIRCLE = "circle"; // NOI18N
38
public static final String JavaDoc SQUARE = "square"; // NOI18N
39

40     private String JavaDoc type = DEFAULT;
41     private int count = ITEM_COUNT_DEFAULT;
42     
43     public UL() {
44     }
45
46     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
47
48         ULCustomizer c = new ULCustomizer(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         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
65         for (int i = 0; i < count; i++)
66             sb.append("<li></li>\n"); // NOI18N
67

68         String JavaDoc strType = "";
69         if (!type.equals(DEFAULT))
70             strType = " type=\"" + type + "\""; // NOI18N
71

72         String JavaDoc oList = "<ul" + strType + ">\n" + sb.toString() + "</ul>\n"; // NOI18N
73

74         return oList;
75     }
76
77     public String JavaDoc getType() {
78         return type;
79     }
80
81     public void setType(String JavaDoc type) {
82         this.type = type;
83     }
84
85     public int getCount() {
86         return count;
87     }
88
89     public void setCount(int count) {
90         this.count = count;
91     }
92         
93 }
94
Popular Tags