1 50 51 package com.lowagie.text; 52 53 import java.net.URL ; 54 import java.util.ArrayList ; 55 import java.util.HashMap ; 56 57 64 65 public class Annotation implements Element { 66 67 69 70 public static final int TEXT = 0; 71 72 73 public static final int URL_NET = 1; 74 75 76 public static final int URL_AS_STRING = 2; 77 78 79 public static final int FILE_DEST = 3; 80 81 82 public static final int FILE_PAGE = 4; 83 84 85 public static final int NAMED_DEST = 5; 86 87 88 public static final int LAUNCH = 6; 89 90 91 public static final int SCREEN = 7; 92 93 94 public static final String TITLE = "title"; 95 96 97 public static final String CONTENT = "content"; 98 99 100 public static final String URL = "url"; 101 102 103 public static final String FILE = "file"; 104 105 106 public static final String DESTINATION = "destination"; 107 108 109 public static final String PAGE = "page"; 110 111 112 public static final String NAMED = "named"; 113 114 115 public static final String APPLICATION = "application"; 116 117 118 public static final String PARAMETERS = "parameters"; 119 120 121 public static final String OPERATION = "operation"; 122 123 124 public static final String DEFAULTDIR = "defaultdir"; 125 126 127 public static final String LLX = "llx"; 128 129 130 public static final String LLY = "lly"; 131 132 133 public static final String URX = "urx"; 134 135 136 public static final String URY = "ury"; 137 138 139 public static final String MIMETYPE = "mime"; 140 141 142 protected int annotationtype; 143 144 145 protected HashMap annotationAttributes = new HashMap (); 146 147 148 protected float llx = Float.NaN; 149 150 151 protected float lly = Float.NaN; 152 153 154 protected float urx = Float.NaN; 155 156 157 protected float ury = Float.NaN; 158 159 161 174 private Annotation(float llx, float lly, float urx, float ury) { 175 this.llx = llx; 176 this.lly = lly; 177 this.urx = urx; 178 this.ury = ury; 179 } 180 181 184 public Annotation(Annotation an) { 185 annotationtype = an.annotationtype; 186 annotationAttributes = an.annotationAttributes; 187 llx = an.llx; 188 lly = an.lly; 189 urx = an.urx; 190 ury = an.ury; 191 } 192 193 202 public Annotation(String title, String text) { 203 annotationtype = TEXT; 204 annotationAttributes.put(TITLE, title); 205 annotationAttributes.put(CONTENT, text); 206 } 207 208 225 public Annotation(String title, String text, float llx, float lly, 226 float urx, float ury) { 227 this(llx, lly, urx, ury); 228 annotationtype = TEXT; 229 annotationAttributes.put(TITLE, title); 230 annotationAttributes.put(CONTENT, text); 231 } 232 233 247 public Annotation(float llx, float lly, float urx, float ury, URL url) { 248 this(llx, lly, urx, ury); 249 annotationtype = URL_NET; 250 annotationAttributes.put(URL, url); 251 } 252 253 267 public Annotation(float llx, float lly, float urx, float ury, String url) { 268 this(llx, lly, urx, ury); 269 annotationtype = URL_AS_STRING; 270 annotationAttributes.put(FILE, url); 271 } 272 273 289 public Annotation(float llx, float lly, float urx, float ury, String file, 290 String dest) { 291 this(llx, lly, urx, ury); 292 annotationtype = FILE_DEST; 293 annotationAttributes.put(FILE, file); 294 annotationAttributes.put(DESTINATION, dest); 295 } 296 297 311 public Annotation(float llx, float lly, float urx, float ury, 312 String moviePath, String mimeType, boolean showOnDisplay) { 313 this(llx, lly, urx, ury); 314 annotationtype = SCREEN; 315 annotationAttributes.put(FILE, moviePath); 316 annotationAttributes.put(MIMETYPE, mimeType); 317 annotationAttributes.put(PARAMETERS, new boolean[] { 318 false , showOnDisplay }); 319 } 320 321 337 public Annotation(float llx, float lly, float urx, float ury, String file, 338 int page) { 339 this(llx, lly, urx, ury); 340 annotationtype = FILE_PAGE; 341 annotationAttributes.put(FILE, file); 342 annotationAttributes.put(PAGE, new Integer (page)); 343 } 344 345 359 public Annotation(float llx, float lly, float urx, float ury, int named) { 360 this(llx, lly, urx, ury); 361 annotationtype = NAMED_DEST; 362 annotationAttributes.put(NAMED, new Integer (named)); 363 } 364 365 385 public Annotation(float llx, float lly, float urx, float ury, 386 String application, String parameters, String operation, 387 String defaultdir) { 388 this(llx, lly, urx, ury); 389 annotationtype = LAUNCH; 390 annotationAttributes.put(APPLICATION, application); 391 annotationAttributes.put(PARAMETERS, parameters); 392 annotationAttributes.put(OPERATION, operation); 393 annotationAttributes.put(DEFAULTDIR, defaultdir); 394 } 395 396 398 403 public int type() { 404 return Element.ANNOTATION; 405 } 406 407 415 public boolean process(ElementListener listener) { 416 try { 417 return listener.add(this); 418 } catch (DocumentException de) { 419 return false; 420 } 421 } 422 423 428 429 public ArrayList getChunks() { 430 return new ArrayList (); 431 } 432 433 435 447 public void setDimensions(float llx, float lly, float urx, float ury) { 448 this.llx = llx; 449 this.lly = lly; 450 this.urx = urx; 451 this.ury = ury; 452 } 453 454 456 461 public float llx() { 462 return llx; 463 } 464 465 470 public float lly() { 471 return lly; 472 } 473 474 479 public float urx() { 480 return urx; 481 } 482 483 488 public float ury() { 489 return ury; 490 } 491 492 499 public float llx(float def) { 500 if (Float.isNaN(llx)) 501 return def; 502 return llx; 503 } 504 505 512 public float lly(float def) { 513 if (Float.isNaN(lly)) 514 return def; 515 return lly; 516 } 517 518 525 public float urx(float def) { 526 if (Float.isNaN(urx)) 527 return def; 528 return urx; 529 } 530 531 538 public float ury(float def) { 539 if (Float.isNaN(ury)) 540 return def; 541 return ury; 542 } 543 544 549 public int annotationType() { 550 return annotationtype; 551 } 552 553 558 public String title() { 559 String s = (String ) annotationAttributes.get(TITLE); 560 if (s == null) 561 s = ""; 562 return s; 563 } 564 565 570 public String content() { 571 String s = (String ) annotationAttributes.get(CONTENT); 572 if (s == null) 573 s = ""; 574 return s; 575 } 576 577 582 public HashMap attributes() { 583 return annotationAttributes; 584 } 585 586 594 public Annotation(java.util.Properties attributes) { 595 this(com.lowagie.text.factories.ElementFactory.getAnnotation(attributes)); 596 } 597 } | Popular Tags |