1 50 51 package com.lowagie.text; 52 53 73 74 public class Paragraph extends Phrase { 75 76 private static final long serialVersionUID = 7852314969733375514L; 78 79 81 82 protected int alignment = Element.ALIGN_UNDEFINED; 83 84 85 protected float multipliedLeading = 0; 86 87 88 protected float indentationLeft; 89 90 91 protected float indentationRight; 92 93 94 private float firstLineIndent = 0; 95 96 97 protected float spacingBefore; 98 99 100 protected float spacingAfter; 101 102 103 private float extraParagraphSpace = 0; 104 105 106 protected boolean keeptogether = false; 107 108 110 113 public Paragraph() { 114 super(); 115 } 116 117 122 public Paragraph(float leading) { 123 super(leading); 124 } 125 126 131 public Paragraph(Chunk chunk) { 132 super(chunk); 133 } 134 135 142 public Paragraph(float leading, Chunk chunk) { 143 super(leading, chunk); 144 } 145 146 151 public Paragraph(String string) { 152 super(string); 153 } 154 155 162 public Paragraph(String string, Font font) { 163 super(string, font); 164 } 165 166 173 public Paragraph(float leading, String string) { 174 super(leading, string); 175 } 176 177 185 public Paragraph(float leading, String string, Font font) { 186 super(leading, string, font); 187 } 188 189 194 public Paragraph(Phrase phrase) { 195 super(phrase); 196 if (phrase instanceof Paragraph) { 197 Paragraph p = (Paragraph)phrase; 198 setAlignment(p.alignment); 199 setLeading(phrase.getLeading(), p.multipliedLeading); 200 setIndentationLeft(p.getIndentationLeft()); 201 setIndentationRight(p.getIndentationRight()); 202 setFirstLineIndent(p.getFirstLineIndent()); 203 setSpacingAfter(p.spacingAfter()); 204 setSpacingBefore(p.spacingBefore()); 205 setExtraParagraphSpace(p.getExtraParagraphSpace()); 206 } 207 } 208 209 211 216 public int type() { 217 return Element.PARAGRAPH; 218 } 219 220 222 228 public boolean add(Object o) { 229 if (o instanceof List) { 230 List list = (List) o; 231 list.setIndentationLeft(list.getIndentationLeft() + indentationLeft); 232 list.setIndentationRight(indentationRight); 233 return super.add(list); 234 } 235 else if (o instanceof Image) { 236 super.addSpecial(o); 237 return true; 238 } 239 else if (o instanceof Paragraph) { 240 super.add(o); 241 super.add(Chunk.NEWLINE); 242 return true; 243 } 244 return super.add(o); 245 } 246 247 249 254 public void setAlignment(int alignment) { 255 this.alignment = alignment; 256 } 257 258 263 public void setAlignment(String alignment) { 264 if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) { 265 this.alignment = Element.ALIGN_CENTER; 266 return; 267 } 268 if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) { 269 this.alignment = Element.ALIGN_RIGHT; 270 return; 271 } 272 if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) { 273 this.alignment = Element.ALIGN_JUSTIFIED; 274 return; 275 } 276 if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) { 277 this.alignment = Element.ALIGN_JUSTIFIED_ALL; 278 return; 279 } 280 this.alignment = Element.ALIGN_LEFT; 281 } 282 283 286 public void setLeading(float fixedLeading) { 287 this.leading = fixedLeading; 288 this.multipliedLeading = 0; 289 } 290 291 297 public void setMultipliedLeading(float multipliedLeading) { 298 this.leading = 0; 299 this.multipliedLeading = multipliedLeading; 300 } 301 302 309 public void setLeading(float fixedLeading, float multipliedLeading) { 310 this.leading = fixedLeading; 311 this.multipliedLeading = multipliedLeading; 312 } 313 314 319 public void setIndentationLeft(float indentation) { 320 this.indentationLeft = indentation; 321 } 322 323 328 public void setIndentationRight(float indentation) { 329 this.indentationRight = indentation; 330 } 331 332 336 public void setFirstLineIndent(float firstLineIndent) { 337 this.firstLineIndent = firstLineIndent; 338 } 339 340 345 public void setSpacingBefore(float spacing) { 346 this.spacingBefore = spacing; 347 } 348 349 354 public void setSpacingAfter(float spacing) { 355 this.spacingAfter = spacing; 356 } 357 358 363 public void setKeepTogether(boolean keeptogether) { 364 this.keeptogether = keeptogether; 365 } 366 367 372 public boolean getKeepTogether() { 373 return keeptogether; 374 } 375 376 378 383 public int getAlignment() { 384 return alignment; 385 } 386 387 391 public float getMultipliedLeading() { 392 return multipliedLeading; 393 } 394 395 403 public float getTotalLeading() { 404 float m = font == null ? 405 Font.DEFAULTSIZE * multipliedLeading : font.getCalculatedLeading(multipliedLeading); 406 if (m > 0 && !hasLeading()) { 407 return m; 408 } 409 return getLeading() + m; 410 } 411 412 417 public float getIndentationLeft() { 418 return indentationLeft; 419 } 420 421 426 public float getIndentationRight() { 427 return indentationRight; 428 } 429 430 434 public float getFirstLineIndent() { 435 return this.firstLineIndent; 436 } 437 438 443 public float spacingBefore() { 444 return spacingBefore; 445 } 446 447 452 public float spacingAfter() { 453 return spacingAfter; 454 } 455 456 460 public float getExtraParagraphSpace() { 461 return this.extraParagraphSpace; 462 } 463 464 468 public void setExtraParagraphSpace(float extraParagraphSpace) { 469 this.extraParagraphSpace = extraParagraphSpace; 470 } 471 472 474 481 public Paragraph(java.util.Properties attributes) { 482 this(com.lowagie.text.factories.ElementFactory.getParagraph(attributes)); 483 } 484 485 491 public int alignment() { 492 return getAlignment(); 493 } 494 495 501 public float indentationLeft() { 502 return getIndentationLeft(); 503 } 504 505 511 public float indentationRight() { 512 return getIndentationRight(); 513 } 514 } 515 | Popular Tags |