KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.openide.util.NbBundle;
26
27
28 /**
29  *
30  * @author Libor Kotouc
31  */

32 public class A implements ActiveEditorDrop {
33
34     public static final String JavaDoc[] protocols = new String JavaDoc[] { "file", "http", "https", "ftp", "mailto" }; // NOI18N
35
public static final int PROTOCOL_DEFAULT = 0;
36     public static final String JavaDoc[] targets = new String JavaDoc[] {
37         NbBundle.getMessage(A.class, "LBL_SameFrame"),
38         NbBundle.getMessage(A.class, "LBL_NewWindow"),
39         NbBundle.getMessage(A.class, "LBL_ParentFrame"),
40         NbBundle.getMessage(A.class, "LBL_FullWindow")
41     };
42     public static final int TARGET_DEFAULT = 0;
43     
44     private int protocolIndex = PROTOCOL_DEFAULT;
45     private String JavaDoc url = "";
46     private String JavaDoc text = "";
47     private int targetIndex = TARGET_DEFAULT;
48     private String JavaDoc target = "";
49     
50     public A() {
51     }
52
53     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
54
55         ACustomizer c = new ACustomizer(this, targetComponent);
56         boolean accept = c.showDialog();
57         if (accept) {
58             String JavaDoc body = createBody();
59             try {
60                 HTMLPaletteUtilities.insert(body, targetComponent);
61             } catch (BadLocationException JavaDoc ble) {
62                 accept = false;
63             }
64         }
65         
66         return accept;
67     }
68
69     private String JavaDoc createBody() {
70         
71         String JavaDoc strProtocol = " HREF=\""; // NOI18N
72
if (getProtocolIndex() != PROTOCOL_DEFAULT) {
73             try {
74                 switch (getProtocolIndex()) {
75                     case 1: strProtocol += "http://"; // NOI18N
76
break;
77                     case 2: strProtocol += "https://"; // NOI18N
78
break;
79                     case 3: strProtocol += "ftp://"; // NOI18N
80
break;
81                     case 4: strProtocol += "mailto:"; // NOI18N
82
}
83             }
84             catch (NumberFormatException JavaDoc nfe) {} // cannot occur
85
}
86         
87         String JavaDoc strURL = "\"";
88         if (getUrl().length() > 0)
89             strURL = getUrl() + "\"";
90         
91         strProtocol += strURL;
92
93         String JavaDoc strTarget = "";
94         if (targetIndex != -1 && targetIndex != TARGET_DEFAULT) {
95             try {
96                 switch (getTargetIndex()) {
97                     case 1: setTarget("_blank"); // NOI18N
98
break;
99                     case 2: setTarget("_parent"); // NOI18N
100
break;
101                     case 3: setTarget("_top"); // NOI18N
102
}
103             }
104             catch (NumberFormatException JavaDoc nfe) {}
105         }
106         
107         if (getTarget().length() > 0)
108             strTarget = " target=\"" + getTarget() + "\""; // NOI18N
109

110         String JavaDoc aLink = "<a" + strProtocol + strTarget + ">" + getText() + "</a>"; // NOI18N
111

112         return aLink;
113     }
114
115     public int getProtocolIndex() {
116         return protocolIndex;
117     }
118
119     public void setProtocolIndex(int protocolIndex) {
120         this.protocolIndex = protocolIndex;
121     }
122
123     public String JavaDoc getUrl() {
124         return url;
125     }
126
127     public void setUrl(String JavaDoc url) {
128         this.url = url;
129     }
130
131     public String JavaDoc getText() {
132         return text;
133     }
134
135     public void setText(String JavaDoc text) {
136         this.text = text;
137     }
138
139     public int getTargetIndex() {
140         return targetIndex;
141     }
142
143     public void setTargetIndex(int targetIndex) {
144         this.targetIndex = targetIndex;
145     }
146
147     public String JavaDoc getTarget() {
148         return target;
149     }
150
151     public void setTarget(String JavaDoc target) {
152         this.target = target;
153     }
154         
155 }
156
Popular Tags