1 29 30 package nextapp.echo2.app; 31 import java.io.Serializable ; 32 33 37 public class Font 38 implements Serializable { 39 40 48 public static class Typeface 49 implements Serializable { 50 51 private String name; 52 private Typeface alternate; 53 54 59 public Typeface(String name) { 60 this(name, null); 61 } 62 63 70 public Typeface(String name, Typeface alternate) { 71 super(); 72 if (name == null) { 73 throw new IllegalArgumentException ("'name' argument cannot be null."); 74 } 75 this.name = name; 76 this.alternate = alternate; 77 } 78 79 82 public boolean equals(Object o) { 83 if (this == o) { 84 return true; 85 } 86 if (!(o instanceof Typeface)) { 87 return false; 88 } 89 Typeface that = (Typeface) o; 90 if (!this.name.equals(that.name)) { 91 return false; 92 } 93 if (this.alternate == null) { 94 return that.alternate == null; 95 } 96 return this.alternate.equals(that.alternate); 97 } 98 99 106 public Typeface getAlternate() { 107 return alternate; 108 } 109 110 115 public String getName() { 116 return name; 117 } 118 119 124 public String toString() { 125 return alternate == null ? name : name + ", " + alternate; 126 } 127 } 128 129 public static final Typeface SANS_SERIF = new Typeface("Sans-Serif"); 130 public static final Typeface SERIF = new Typeface("Serif"); 131 public static final Typeface MONOSPACE = new Typeface("Monospace"); 132 public static final Typeface HELVETICA = new Typeface("Helvetica", SANS_SERIF); 133 public static final Typeface ARIAL = new Typeface("Arial", HELVETICA); 134 public static final Typeface VERDANA = new Typeface("Verdana", ARIAL); 135 public static final Typeface TIMES = new Typeface("Times", SERIF); 136 public static final Typeface TIMES_ROMAN = new Typeface("Times Roman", TIMES); 137 public static final Typeface TIMES_NEW_ROMAN = new Typeface("Times New Roman", TIMES_ROMAN); 138 public static final Typeface COURIER = new Typeface("Courier", MONOSPACE); 139 public static final Typeface COURIER_NEW = new Typeface("Courier New", COURIER); 140 141 144 public static final int PLAIN = 0x0; 145 146 149 public static final int BOLD = 0x1; 150 151 154 public static final int ITALIC = 0x2; 155 156 159 public static final int UNDERLINE = 0x4; 160 161 164 public static final int OVERLINE = 0x8; 165 166 169 public static final int LINE_THROUGH = 0x10; 170 171 private Typeface typeface; 172 private Extent size; 173 private int style; 174 175 194 public Font(Typeface typeface, int style, Extent size) { 195 super(); 196 this.typeface = typeface; 197 this.style = style; 198 this.size = size; 199 } 200 201 204 public boolean equals(Object o) { 205 if (this == o) { 206 return true; 207 } 208 if (!(o instanceof Font)) { 209 return false; 210 } 211 Font that = (Font) o; 212 if (this.style != that.style) { 213 return false; 214 } 215 if (typeface == null) { 216 if (that.typeface != null) { 217 return false; 218 } 219 } else { 220 if (!this.typeface.equals(that.typeface)) { 221 return false; 222 } 223 } 224 if (size == null) { 225 if (that.size != null) { 226 return false; 227 } 228 } else { 229 if (!this.size.equals(that.size)) { 230 return false; 231 } 232 } 233 return true; 234 } 235 236 241 public Extent getSize() { 242 return size; 243 } 244 245 250 public Typeface getTypeface() { 251 return typeface; 252 } 253 254 259 public boolean isBold() { 260 return (style & BOLD) != 0; 261 } 262 263 268 public boolean isItalic() { 269 return (style & ITALIC) != 0; 270 } 271 272 277 public boolean isLineThrough() { 278 return (style & LINE_THROUGH) != 0; 279 } 280 281 287 public boolean isPlain() { 288 return style == 0; 289 } 290 291 296 public boolean isOverline() { 297 return (style & OVERLINE) != 0; 298 } 299 300 305 public boolean isUnderline() { 306 return (style & UNDERLINE) != 0; 307 } 308 309 314 public String toString() { 315 StringBuffer out = new StringBuffer (Font.class.getName()); 316 out.append(" ("); 317 out.append(getTypeface()); 318 out.append(" /"); 319 if (isPlain()) { 320 out.append(" Plain"); 321 } 322 if (isBold()) { 323 out.append(" Bold"); 324 } 325 if (isItalic()) { 326 out.append(" Italic"); 327 } 328 if (isLineThrough()) { 329 out.append(" LineThrough"); 330 } 331 if (isOverline()) { 332 out.append(" Overline"); 333 } 334 if (isUnderline()) { 335 out.append(" Underline"); 336 } 337 out.append(" / "); 338 out.append(getSize()); 339 out.append(")"); 340 return out.toString(); 341 } 342 } 343 | Popular Tags |