KickJava   Java API By Example, From Geeks To Geeks.

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


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 IMG implements ActiveEditorDrop {
32
33     private String JavaDoc location = "";
34     private String JavaDoc width = "";
35     private String JavaDoc height = "";
36     private String JavaDoc alttext = "";
37
38     public IMG() {
39     }
40
41     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
42
43         IMGCustomizer c = new IMGCustomizer(this, targetComponent);
44         boolean accept = c.showDialog();
45         if (accept) {
46             String JavaDoc body = createBody();
47             try {
48                 HTMLPaletteUtilities.insert(body, targetComponent);
49             } catch (BadLocationException JavaDoc ble) {
50                 accept = false;
51             }
52         }
53         
54         return accept;
55     }
56
57     private String JavaDoc createBody() {
58         
59         String JavaDoc strLoc = " SRC=\"\""; // NOI18N
60
if (location.length() > 0)
61             strLoc = " SRC=\"" + location + "\""; // NOI18N
62

63         String JavaDoc strWidth = "";
64         if (width.length() > 0)
65             strWidth = " width=\"" + width + "\""; // NOI18N
66

67         String JavaDoc strHeight = "";
68         if (height.length() > 0)
69             strHeight = " height=\"" + height + "\""; // NOI18N
70

71         String JavaDoc strAlt = "";
72         if (alttext.length() > 0)
73             strAlt = " alt=\"" + alttext + "\""; // NOI18N
74

75         String JavaDoc imgBody = "<img" + strLoc + strWidth + strHeight + strAlt + "/>\n"; // NOI18N
76

77         return imgBody;
78     }
79
80     public String JavaDoc getLocation() {
81         return location;
82     }
83
84     public void setLocation(String JavaDoc location) {
85         this.location = location;
86     }
87
88     public String JavaDoc getWidth() {
89         return width;
90     }
91
92     public void setWidth(String JavaDoc width) {
93         this.width = width;
94     }
95
96     public String JavaDoc getHeight() {
97         return height;
98     }
99
100     public void setHeight(String JavaDoc height) {
101         this.height = height;
102     }
103
104     public String JavaDoc getAlttext() {
105         return alttext;
106     }
107
108     public void setAlttext(String JavaDoc alttext) {
109         this.alttext = alttext;
110     }
111         
112 }
113
Popular Tags