KickJava   Java API By Example, From Geeks To Geeks.

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


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 OL 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 ARABIC_NUMBERS = "1"; // NOI18N
37
public static final String JavaDoc LOWER_ALPHA = "a"; // NOI18N
38
public static final String JavaDoc UPPER_ALPHA = "A"; // NOI18N
39
public static final String JavaDoc LOWER_ROMAN = "i"; // NOI18N
40
public static final String JavaDoc UPPER_ROMAN = "I"; // NOI18N
41

42     private String JavaDoc type = DEFAULT;
43     private int count = ITEM_COUNT_DEFAULT;
44     
45     public OL() {
46     }
47
48     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
49
50         OLCustomizer c = new OLCustomizer(this);
51         boolean accept = c.showDialog();
52         if (accept) {
53             String JavaDoc body = createBody();
54             try {
55                 HTMLPaletteUtilities.insert(body, targetComponent);
56             } catch (BadLocationException JavaDoc ble) {
57                 accept = false;
58             }
59         }
60         
61         return accept;
62     }
63
64     private String JavaDoc createBody() {
65         
66         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
67         for (int i = 0; i < count; i++)
68             sb.append("<li></li>\n"); // NOI18N
69

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

74         String JavaDoc oList = "<ol" + strType + ">\n" + sb.toString() + "</ol>\n"; // NOI18N
75

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