1 19 20 package org.netbeans.modules.html.palette.items; 21 import javax.swing.text.BadLocationException ; 22 import javax.swing.text.JTextComponent ; 23 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 24 import org.openide.text.ActiveEditorDrop; 25 26 27 31 public class IMG implements ActiveEditorDrop { 32 33 private String location = ""; 34 private String width = ""; 35 private String height = ""; 36 private String alttext = ""; 37 38 public IMG() { 39 } 40 41 public boolean handleTransfer(JTextComponent targetComponent) { 42 43 IMGCustomizer c = new IMGCustomizer(this, targetComponent); 44 boolean accept = c.showDialog(); 45 if (accept) { 46 String body = createBody(); 47 try { 48 HTMLPaletteUtilities.insert(body, targetComponent); 49 } catch (BadLocationException ble) { 50 accept = false; 51 } 52 } 53 54 return accept; 55 } 56 57 private String createBody() { 58 59 String strLoc = " SRC=\"\""; if (location.length() > 0) 61 strLoc = " SRC=\"" + location + "\""; 63 String strWidth = ""; 64 if (width.length() > 0) 65 strWidth = " width=\"" + width + "\""; 67 String strHeight = ""; 68 if (height.length() > 0) 69 strHeight = " height=\"" + height + "\""; 71 String strAlt = ""; 72 if (alttext.length() > 0) 73 strAlt = " alt=\"" + alttext + "\""; 75 String imgBody = "<img" + strLoc + strWidth + strHeight + strAlt + "/>\n"; 77 return imgBody; 78 } 79 80 public String getLocation() { 81 return location; 82 } 83 84 public void setLocation(String location) { 85 this.location = location; 86 } 87 88 public String getWidth() { 89 return width; 90 } 91 92 public void setWidth(String width) { 93 this.width = width; 94 } 95 96 public String getHeight() { 97 return height; 98 } 99 100 public void setHeight(String height) { 101 this.height = height; 102 } 103 104 public String getAlttext() { 105 return alttext; 106 } 107 108 public void setAlttext(String alttext) { 109 this.alttext = alttext; 110 } 111 112 } 113 | Popular Tags |