1 19 package org.netbeans.modules.gsf; 20 21 import org.netbeans.api.gsf.ElementKind; 22 import org.netbeans.api.gsf.HtmlFormatter; 23 24 25 29 public class GsfHtmlFormatter extends HtmlFormatter { 30 protected boolean isDeprecated; 31 protected boolean isParameter; 32 protected boolean isType; 33 protected boolean isName; 34 35 protected StringBuilder sb = new StringBuilder (); 36 37 public GsfHtmlFormatter() { 38 } 39 40 public void reset() { 41 sb.setLength(0); 42 } 43 44 public void appendHtml(String html) { 45 sb.append(html); 46 } 47 48 public void appendText(String text) { 49 for (int i = 0, n = text.length(); i < n; i++) { 50 char c = text.charAt(i); 51 52 switch (c) { 53 case '<': 54 sb.append("<"); 56 break; 57 58 case '>': 59 sb.append(">"); 61 break; 62 63 case '&': 64 sb.append("&"); 66 break; 67 68 case '"': 69 sb.append("""); 71 break; 72 73 case '\'': 74 sb.append("'"); 76 break; 77 78 default: 79 sb.append(c); 80 } 81 } 82 } 83 84 public void name(ElementKind kind, boolean start) { 85 assert start != isName; 86 isName = start; 87 88 if (isName) { 89 sb.append("<b>"); 90 } else { 91 sb.append("</b>"); 92 } 93 } 94 95 public void parameters(boolean start) { 96 assert start != isParameter; 97 isParameter = start; 98 99 if (isParameter) { 100 sb.append("<font color=\"#808080\">"); 101 } else { 102 sb.append("</font>"); 103 } 104 } 105 106 public void type(boolean start) { 107 assert start != isType; 108 isType = start; 109 110 if (isType) { 111 sb.append("<font color=\"#808080\">"); 112 } else { 113 sb.append("</font>"); 114 } 115 } 116 117 public void deprecated(boolean start) { 118 assert start != isDeprecated; 119 isDeprecated = start; 120 121 if (isDeprecated) { 122 sb.append("<s>"); 123 } else { 124 sb.append("</s>"); 125 } 126 } 127 128 public String getText() { 129 assert !isParameter && !isDeprecated && !isName && !isType; 130 131 return sb.toString(); 132 } 133 } 134 | Popular Tags |