1 50 51 package com.lowagie.text; 52 53 import java.util.ArrayList ; 54 import java.util.Iterator ; 55 56 import com.lowagie.text.factories.RomanAlphabetFactory; 57 58 102 103 public class List implements TextElementArray { 104 105 107 108 public static final boolean ORDERED = true; 109 110 public static final boolean UNORDERED = false; 111 112 public static final boolean NUMERICAL = false; 113 114 public static final boolean ALPHABETICAL = true; 115 116 public static final boolean UPPERCASE = false; 117 118 public static final boolean LOWERCASE = true; 119 120 122 123 protected ArrayList list = new ArrayList (); 124 125 126 protected boolean numbered = false; 127 128 protected boolean lettered = false; 129 130 protected boolean lowercase = false; 131 132 protected boolean autoindent = false; 133 134 protected boolean alignindent = false; 135 136 137 protected int first = 1; 138 139 protected Chunk symbol = new Chunk("- "); 140 141 142 protected float indentationLeft = 0; 143 144 protected float indentationRight = 0; 145 146 protected float symbolIndent = 0; 147 148 150 151 public List() { 152 this(false, false); 153 } 154 155 159 public List(boolean numbered) { 160 this(numbered, false); 161 } 162 163 168 public List(boolean numbered, boolean lettered) { 169 this.numbered = numbered; 170 this.lettered = lettered; 171 this.autoindent = true; 172 this.alignindent = true; 173 } 174 175 185 public List(boolean numbered, float symbolIndent) { 186 this(numbered, false, symbolIndent); 187 } 188 189 195 public List(boolean numbered, boolean lettered, float symbolIndent) { 196 this.numbered = numbered; 197 this.lettered = lettered; 198 this.symbolIndent = symbolIndent; 199 } 200 201 203 210 public boolean process(ElementListener listener) { 211 try { 212 for (Iterator i = list.iterator(); i.hasNext(); ) { 213 listener.add((Element) i.next()); 214 } 215 return true; 216 } 217 catch(DocumentException de) { 218 return false; 219 } 220 } 221 222 227 public int type() { 228 return Element.LIST; 229 } 230 231 236 public ArrayList getChunks() { 237 ArrayList tmp = new ArrayList (); 238 for (Iterator i = list.iterator(); i.hasNext(); ) { 239 tmp.addAll(((Element) i.next()).getChunks()); 240 } 241 return tmp; 242 } 243 244 246 252 public boolean add(Object o) { 253 if (o instanceof ListItem) { 254 ListItem item = (ListItem) o; 255 if (numbered || lettered) { 256 Chunk chunk; 257 int index = first + list.size(); 258 if ( lettered ) 259 chunk = new Chunk(RomanAlphabetFactory.getString(index, lowercase), symbol.getFont()); 260 else 261 chunk = new Chunk(String.valueOf(index), symbol.getFont()); 262 chunk.append(". "); 263 item.setListSymbol(chunk); 264 } 265 else { 266 item.setListSymbol(symbol); 267 } 268 item.setIndentationLeft(symbolIndent, autoindent); 269 item.setIndentationRight(0); 270 list.add(item); 271 } 272 else if (o instanceof List) { 273 List nested = (List) o; 274 nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); 275 first--; 276 return list.add(nested); 277 } 278 else if (o instanceof String ) { 279 return this.add(new ListItem((String ) o)); 280 } 281 return false; 282 } 283 284 286 287 public void normalizeIndentation() { 288 float max = 0; 289 Element o; 290 for (Iterator i = list.iterator(); i.hasNext(); ) { 291 o = (Element)i.next(); 292 if (o instanceof ListItem) { 293 max = Math.max(max, ((ListItem)o).getIndentationLeft()); 294 } 295 } 296 for (Iterator i = list.iterator(); i.hasNext(); ) { 297 o = (Element)i.next(); 298 if (o instanceof ListItem) { 299 ((ListItem)o).setIndentationLeft(max); 300 } 301 } 302 } 303 304 306 309 public void setNumbered(boolean numbered) { 310 this.numbered = numbered; 311 } 312 313 316 public void setLettered(boolean lettered) { 317 this.lettered = lettered; 318 } 319 320 323 public void setLowercase(boolean uppercase) { 324 this.lowercase = uppercase; 325 } 326 327 330 public void setAutoindent(boolean autoindent) { 331 this.autoindent = autoindent; 332 } 333 336 public void setAlignindent(boolean alignindent) { 337 this.alignindent = alignindent; 338 } 339 340 345 public void setFirst(int first) { 346 this.first = first; 347 } 348 349 354 public void setListSymbol(Chunk symbol) { 355 this.symbol = symbol; 356 } 357 358 365 public void setListSymbol(String symbol) { 366 this.symbol = new Chunk(symbol); 367 } 368 369 374 public void setIndentationLeft(float indentation) { 375 this.indentationLeft = indentation; 376 } 377 378 383 public void setIndentationRight(float indentation) { 384 this.indentationRight = indentation; 385 } 386 387 390 public void setSymbolIndent(float symbolIndent) { 391 this.symbolIndent = symbolIndent; 392 } 393 394 396 401 public ArrayList getItems() { 402 return list; 403 } 404 405 410 public int size() { 411 return list.size(); 412 } 413 414 419 public boolean isEmpty() { 420 return list.isEmpty(); 421 } 422 423 428 public float getTotalLeading() { 429 if (list.size() < 1) { 430 return -1; 431 } 432 ListItem item = (ListItem) list.get(0); 433 return item.getTotalLeading(); 434 } 435 436 438 442 443 public boolean isNumbered() { 444 return numbered; 445 } 446 447 451 public boolean isLettered() { 452 return lettered; 453 } 454 455 459 public boolean isLowercase() { 460 return lowercase; 461 } 462 463 467 public boolean isAutoindent() { 468 return autoindent; 469 } 470 471 475 public boolean isAlignindent() { 476 return alignindent; 477 } 478 479 483 public int getFirst() { 484 return first; 485 } 486 487 491 public Chunk getSymbol() { 492 return symbol; 493 } 494 495 499 public float getIndentationLeft() { 500 return indentationLeft; 501 } 502 503 507 public float getIndentationRight() { 508 return indentationRight; 509 } 510 511 515 public float getSymbolIndent() { 516 return symbolIndent; 517 } 518 519 527 528 public List(java.util.Properties attributes) { 529 this(); 530 List l = com.lowagie.text.factories.ElementFactory.getList(attributes); 531 this.list = l.list; 532 this.numbered = l.numbered; 533 this.lettered = l.lettered; 534 this.lowercase = l.lowercase; 535 this.autoindent = l.autoindent; 536 this.alignindent = l.alignindent; 537 this.first = l.first; 538 this.symbol = l.symbol; 539 this.indentationLeft = l.indentationLeft; 540 this.indentationRight = l.indentationRight; 541 this.symbolIndent = l.symbolIndent; 542 } 543 544 549 public boolean isLowerCase() { 550 return isLowercase(); 551 } 552 553 558 public int first() { 559 return getFirst(); 560 } 561 562 567 public Chunk symbol() { 568 return getSymbol(); 569 } 570 571 576 577 public float indentationLeft() { 578 return indentationLeft; 579 } 580 581 586 587 public float indentationRight() { 588 return getIndentationRight(); 589 } 590 591 596 public float symbolIndent() { 597 return getSymbolIndent(); 598 } 599 } | Popular Tags |