1 17 18 19 20 package org.apache.fop.area; 21 22 import java.awt.Color ; 23 import java.io.Serializable ; 24 25 import org.apache.fop.fo.Constants; 26 import org.apache.fop.fonts.FontTriplet; 27 import org.apache.fop.image.FopImage; 28 import org.apache.fop.traits.BorderProps; 29 import org.apache.fop.util.ColorUtil; 30 31 36 public class Trait implements Serializable { 37 38 42 44 48 public static final Integer INTERNAL_LINK = new Integer (1); 50 53 public static final Integer EXTERNAL_LINK = new Integer (2); 54 55 58 public static final Integer FONT = new Integer (3); 59 60 63 public static final Integer FONT_SIZE = new Integer (4); 64 65 68 public static final Integer COLOR = new Integer (7); 69 70 73 public static final Integer PROD_ID = new Integer (8); 74 75 78 public static final Integer BACKGROUND = new Integer (9); 79 80 83 public static final Integer UNDERLINE = new Integer (10); 84 85 88 public static final Integer OVERLINE = new Integer (11); 89 90 93 public static final Integer LINETHROUGH = new Integer (12); 94 95 98 100 103 105 108 public static final Integer BORDER_START = new Integer (15); 109 110 113 public static final Integer BORDER_END = new Integer (16); 114 115 118 public static final Integer BORDER_BEFORE = new Integer (17); 119 120 123 public static final Integer BORDER_AFTER = new Integer (18); 124 125 128 public static final Integer PADDING_START = new Integer (19); 129 130 133 public static final Integer PADDING_END = new Integer (20); 134 135 138 public static final Integer PADDING_BEFORE = new Integer (21); 139 140 143 public static final Integer PADDING_AFTER = new Integer (22); 144 145 148 public static final Integer SPACE_START = new Integer (23); 149 150 153 public static final Integer SPACE_END = new Integer (24); 154 155 158 160 163 165 168 public static final Integer START_INDENT = new Integer (27); 169 170 173 public static final Integer END_INDENT = new Integer (28); 174 175 176 public static final Integer SPACE_BEFORE = new Integer (29); 177 178 179 public static final Integer SPACE_AFTER = new Integer (30); 180 181 182 public static final Integer IS_REFERENCE_AREA = new Integer (31); 183 184 185 public static final Integer IS_VIEWPORT_AREA = new Integer (32); 186 187 188 public static final Integer BLINK = new Integer (33); 189 190 191 public static final Integer UNDERLINE_COLOR = new Integer (34); 192 193 public static final Integer OVERLINE_COLOR = new Integer (35); 194 195 public static final Integer LINETHROUGH_COLOR = new Integer (36); 196 197 198 public static final int MAX_TRAIT_KEY = 36; 199 200 private static final TraitInfo[] TRAIT_INFO = new TraitInfo[MAX_TRAIT_KEY + 1]; 201 202 private static class TraitInfo { 203 private String name; 204 private Class clazz; 206 public TraitInfo(String name, Class clazz) { 207 this.name = name; 208 this.clazz = clazz; 209 } 210 211 public String getName() { 212 return this.name; 213 } 214 215 public Class getClazz() { 216 return this.clazz; 217 } 218 } 219 220 private static void put(Integer key, TraitInfo info) { 221 TRAIT_INFO[key.intValue()] = info; 222 } 223 224 static { 225 put(INTERNAL_LINK, new TraitInfo("internal-link", String .class)); 228 put(EXTERNAL_LINK, new TraitInfo("external-link", String .class)); 229 put(FONT, new TraitInfo("font", FontTriplet.class)); 230 put(FONT_SIZE, new TraitInfo("font-size", Integer .class)); 231 put(COLOR, new TraitInfo("color", Color .class)); 232 put(PROD_ID, new TraitInfo("prod-id", String .class)); 233 put(BACKGROUND, new TraitInfo("background", Background.class)); 234 put(UNDERLINE, new TraitInfo("underline-score", Boolean .class)); 235 put(UNDERLINE_COLOR, new TraitInfo("underline-score-color", Color .class)); 236 put(OVERLINE, new TraitInfo("overline-score", Boolean .class)); 237 put(OVERLINE_COLOR, new TraitInfo("overline-score-color", Color .class)); 238 put(LINETHROUGH, new TraitInfo("through-score", Boolean .class)); 239 put(LINETHROUGH_COLOR, new TraitInfo("through-score-color", Color .class)); 240 put(BLINK, new TraitInfo("blink", Boolean .class)); 241 put(BORDER_START, 244 new TraitInfo("border-start", BorderProps.class)); 245 put(BORDER_END, 246 new TraitInfo("border-end", BorderProps.class)); 247 put(BORDER_BEFORE, 248 new TraitInfo("border-before", BorderProps.class)); 249 put(BORDER_AFTER, 250 new TraitInfo("border-after", BorderProps.class)); 251 put(PADDING_START, 252 new TraitInfo("padding-start", Integer .class)); 253 put(PADDING_END, 254 new TraitInfo("padding-end", Integer .class)); 255 put(PADDING_BEFORE, 256 new TraitInfo("padding-before", Integer .class)); 257 put(PADDING_AFTER, 258 new TraitInfo("padding-after", Integer .class)); 259 put(SPACE_START, 260 new TraitInfo("space-start", Integer .class)); 261 put(SPACE_END, 262 new TraitInfo("space-end", Integer .class)); 263 put(START_INDENT, 268 new TraitInfo("start-indent", Integer .class)); 269 put(END_INDENT, 270 new TraitInfo("end-indent", Integer .class)); 271 put(SPACE_BEFORE, 272 new TraitInfo("space-before", Integer .class)); 273 put(SPACE_AFTER, 274 new TraitInfo("space-after", Integer .class)); 275 put(IS_REFERENCE_AREA, 276 new TraitInfo("is-reference-area", Boolean .class)); 277 put(IS_VIEWPORT_AREA, 278 new TraitInfo("is-viewport-area", Boolean .class)); 279 280 } 281 282 288 public static String getTraitName(Object traitCode) { 289 return TRAIT_INFO[((Integer )traitCode).intValue()].getName(); 290 } 291 292 298 310 311 317 public static Class getTraitClass(Object traitCode) { 318 return TRAIT_INFO[((Integer )traitCode).intValue()].getClazz(); 319 } 320 321 324 private Object propType; 325 326 329 private Object data; 330 331 334 public Trait() { 335 this.propType = null; 336 this.data = null; 337 } 338 339 345 public Trait(Object propType, Object data) { 346 this.propType = propType; 347 this.data = data; 348 } 349 350 354 public Object getData() { 355 return this.data; 356 } 357 358 362 public Object getPropType() { 363 return this.propType; 364 } 365 366 370 public String toString() { 371 return data.toString(); 372 } 373 374 381 413 414 415 419 public static class Background implements Serializable { 420 421 422 private Color color = null; 423 424 425 private String url = null; 426 427 428 private FopImage fopimage = null; 429 430 431 private int repeat; 432 433 434 private int horiz; 435 436 437 private int vertical; 438 439 443 public Color getColor() { 444 return color; 445 } 446 447 451 public int getHoriz() { 452 return horiz; 453 } 454 455 459 public int getRepeat() { 460 return repeat; 461 } 462 463 467 public String getURL() { 468 return url; 469 } 470 471 475 public FopImage getFopImage() { 476 return fopimage; 477 } 478 479 483 public int getVertical() { 484 return vertical; 485 } 486 487 491 public void setColor(Color color) { 492 this.color = color; 493 } 494 495 499 public void setHoriz(int horiz) { 500 this.horiz = horiz; 501 } 502 503 507 public void setRepeat(int repeat) { 508 this.repeat = repeat; 509 } 510 511 515 public void setRepeat(String repeat) { 516 setRepeat(getConstantForRepeat(repeat)); 517 } 518 519 523 public void setURL(String url) { 524 this.url = url; 525 } 526 527 531 public void setFopImage(FopImage fopimage) { 532 this.fopimage = fopimage; 533 } 534 535 539 public void setVertical(int vertical) { 540 this.vertical = vertical; 541 } 542 543 private String getRepeatString() { 544 switch (getRepeat()) { 545 case Constants.EN_REPEAT: return "repeat"; 546 case Constants.EN_REPEATX: return "repeat-x"; 547 case Constants.EN_REPEATY: return "repeat-y"; 548 case Constants.EN_NOREPEAT: return "no-repeat"; 549 default: throw new IllegalStateException ("Illegal repeat style: " + getRepeat()); 550 } 551 } 552 553 private static int getConstantForRepeat(String repeat) { 554 if ("repeat".equalsIgnoreCase(repeat)) { 555 return Constants.EN_REPEAT; 556 } else if ("repeat-x".equalsIgnoreCase(repeat)) { 557 return Constants.EN_REPEATX; 558 } else if ("repeat-y".equalsIgnoreCase(repeat)) { 559 return Constants.EN_REPEATY; 560 } else if ("no-repeat".equalsIgnoreCase(repeat)) { 561 return Constants.EN_NOREPEAT; 562 } else { 563 throw new IllegalStateException ("Illegal repeat style: " + repeat); 564 } 565 } 566 567 571 public String toString() { 572 StringBuffer sb = new StringBuffer (); 573 if (color != null) { 574 sb.append("color=").append(ColorUtil.colorToString(color)); 575 } 576 if (url != null) { 577 if (color != null) { 578 sb.append(","); 579 } 580 sb.append("url=").append(url); 581 sb.append(",repeat=").append(getRepeatString()); 582 sb.append(",horiz=").append(horiz); 583 sb.append(",vertical=").append(vertical); 584 } 585 return sb.toString(); 586 } 587 588 } 589 } 590 591 | Popular Tags |