1 64 65 package com.jcorporate.expresso.services.html; 66 67 72 73 import java.io.PrintWriter ; 74 75 76 80 public class Text 81 extends HtmlElement { 82 private String thisClass = (this.getClass().getName() + "."); 83 84 85 private static String defaultStyle = null; 86 private static String defaultFontColor = null; 87 private static String defaultFontFace = null; 88 private static boolean defaultSmall = false; 89 protected String contentString = (" "); 90 private String style = defaultStyle; 91 private boolean isSmall = defaultSmall; 92 private String fontColor = defaultFontColor; 93 private String fontFace = defaultFontFace; 94 95 98 public Text() 99 throws HtmlException { 100 super(); 101 } 102 103 108 public Text(String newString) 109 throws HtmlException { 110 super(newString); 111 112 String myName = (thisClass + "Text(String)"); 113 114 if (contentString == null) { 115 throw new HtmlException(myName + 116 ":Unable to defined a null text string for " + 117 getName()); 118 } 119 120 contentString = newString; 121 } 122 123 129 public Text(String newString, String newStyle) 130 throws HtmlException { 131 this(newString); 132 setDefaultStyle(newStyle); 133 } 134 135 139 protected void display(PrintWriter out, int depth) 140 throws HtmlException { 141 boolean terminate = false; 142 143 if ((cSSClass != null) && (!cSSClass.equals("jc-default"))) { 144 terminate = true; 145 this.padWithTabs(out, depth); 146 out.print("<span"); 147 out.print(" class=\"" + cSSClass + "\""); 148 149 if (cSSID != null) { 150 out.print(" id=\"" + cSSID + "\""); 151 } 152 153 out.print(">"); 154 } else { 155 this.padWithTabs(out, depth); 156 157 if (cSSID != null) { 158 out.print("<span id=\"" + cSSID + "\">"); 159 terminate = true; 160 } 161 } 162 if (style != null) { 163 if (style.equals("bold")) { 164 out.print("<strong>"); 165 } else if (style.equals("italic")) { 166 out.print("<i>"); 167 } 168 } 169 if (fontColor != null) { 170 out.print("<font color=\"" + fontColor + "\">"); 171 } 172 if (isSmall) { 173 out.print("<small>"); 174 } 175 176 out.print(contentString); 177 178 if (isSmall) { 179 out.print("</small>"); 180 } 181 if (fontColor != null) { 182 out.print("</font>"); 183 } 184 if (style != null) { 185 if (style.equals("bold")) { 186 out.print("</strong>"); 187 } else if (style.equals("italic")) { 188 out.print("</i>"); 189 } 190 } 191 if (terminate) { 192 out.print("</SPAN>"); 193 } 194 195 setDisplayed(); 196 } 197 198 199 202 public void resetDefaults() 203 throws HtmlException { 204 cSSClass = null; 205 setDefaultFontColor(null); 206 setDefaultFontFace(null); 207 setDefaultStyle(null); 208 } 209 210 211 214 public static void setDefaultFontColor(String newFontColor) 215 throws HtmlException { 216 defaultFontColor = newFontColor; 217 } 218 219 220 223 public static void setDefaultFontFace(String newFontFace) 224 throws HtmlException { 225 defaultFontFace = newFontFace; 226 } 227 228 229 232 public static void setDefaultSmall(boolean newSmall) 233 throws HtmlException { 234 defaultSmall = newSmall; 235 } 236 237 238 241 public static void setDefaultStyle(String newStyle) { 242 defaultStyle = newStyle; 243 } 244 245 248 public void setFontColor(String newColor) 249 throws HtmlException { 250 fontColor = newColor; 251 } 252 253 254 257 public void setFontFace(String newFace) 258 throws HtmlException { 259 fontFace = newFace; 260 } 261 262 263 266 public void setSmall(boolean newSmall) 267 throws HtmlException { 268 isSmall = newSmall; 269 } 270 271 272 275 public void setStyle(String newStyle) 276 throws HtmlException { 277 String myName = (thisClass + "setStyle(String)"); 278 279 if (newStyle.equalsIgnoreCase("bold")) { 280 style = ("bold"); 281 } else if (newStyle.equalsIgnoreCase("italic")) { 282 style = ("italic"); 283 } else { 284 throw new HtmlException(myName + 285 ":Style must be 'bold' or 'italic', '" + 286 newStyle + "' is not valid for " + 287 getName()); 288 } 289 } 290 291 292 295 public void setText(String newText) 296 throws HtmlException { 297 String myName = (thisClass + "setText(String)"); 298 299 if (newText == null) { 300 throw new HtmlException(myName + 301 ":Can't set a null string for context of a Text for " + 302 getName()); 303 } 304 305 contentString = newText; 306 } 307 308 309 } 310 | Popular Tags |