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 import org.openide.util.NbBundle; 26 27 28 32 public class A implements ActiveEditorDrop { 33 34 public static final String [] protocols = new String [] { "file", "http", "https", "ftp", "mailto" }; public static final int PROTOCOL_DEFAULT = 0; 36 public static final String [] targets = new String [] { 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 url = ""; 46 private String text = ""; 47 private int targetIndex = TARGET_DEFAULT; 48 private String target = ""; 49 50 public A() { 51 } 52 53 public boolean handleTransfer(JTextComponent targetComponent) { 54 55 ACustomizer c = new ACustomizer(this, targetComponent); 56 boolean accept = c.showDialog(); 57 if (accept) { 58 String body = createBody(); 59 try { 60 HTMLPaletteUtilities.insert(body, targetComponent); 61 } catch (BadLocationException ble) { 62 accept = false; 63 } 64 } 65 66 return accept; 67 } 68 69 private String createBody() { 70 71 String strProtocol = " HREF=\""; if (getProtocolIndex() != PROTOCOL_DEFAULT) { 73 try { 74 switch (getProtocolIndex()) { 75 case 1: strProtocol += "http://"; break; 77 case 2: strProtocol += "https://"; break; 79 case 3: strProtocol += "ftp://"; break; 81 case 4: strProtocol += "mailto:"; } 83 } 84 catch (NumberFormatException nfe) {} } 86 87 String strURL = "\""; 88 if (getUrl().length() > 0) 89 strURL = getUrl() + "\""; 90 91 strProtocol += strURL; 92 93 String strTarget = ""; 94 if (targetIndex != -1 && targetIndex != TARGET_DEFAULT) { 95 try { 96 switch (getTargetIndex()) { 97 case 1: setTarget("_blank"); break; 99 case 2: setTarget("_parent"); break; 101 case 3: setTarget("_top"); } 103 } 104 catch (NumberFormatException nfe) {} 105 } 106 107 if (getTarget().length() > 0) 108 strTarget = " target=\"" + getTarget() + "\""; 110 String aLink = "<a" + strProtocol + strTarget + ">" + getText() + "</a>"; 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 getUrl() { 124 return url; 125 } 126 127 public void setUrl(String url) { 128 this.url = url; 129 } 130 131 public String getText() { 132 return text; 133 } 134 135 public void setText(String 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 getTarget() { 148 return target; 149 } 150 151 public void setTarget(String target) { 152 this.target = target; 153 } 154 155 } 156 | Popular Tags |