Пример #1
0
 public void inheritListSettings(int listNumber, int listLevel) {
   for (RtfBasicElement rtfElement : chunks) {
     if (rtfElement instanceof RtfList) {
       ((RtfList) rtfElement).setListNumber(listNumber);
       ((RtfList) rtfElement).setListLevel(listLevel);
       ((RtfList) rtfElement).setParent(this.parentList);
     }
   }
 }
Пример #2
0
  /**
   * Constructs a new RtfList for the specified List.
   *
   * @param doc The RtfDocument this RtfList belongs to
   * @param list The List this RtfList is based on
   */
  public RtfList(RtfDocument doc, List list) {
    super(doc);

    this.listNumber = document.getDocumentHeader().getListNumber(this);

    this.items = new ArrayList();
    if (list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent =
          (int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR);
    } else if (list.getSymbolIndent() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR);
    } else if (list.getIndentationLeft() > 0) {
      this.firstIndent = 0;
      this.leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR);
    } else {
      this.firstIndent = 0;
      this.leftIndent = 0;
    }
    this.rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR);
    this.symbolIndent =
        (int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR);

    if (list instanceof RomanList) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_ROMAN;
      } else {
        this.listType = LIST_TYPE_UPPER_ROMAN;
      }
    } else if (list.isNumbered()) {
      this.listType = LIST_TYPE_NUMBERED;
    } else if (list.isLettered()) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_LETTERS;
      } else {
        this.listType = LIST_TYPE_UPPER_LETTERS;
      }
    }

    for (int i = 0; i < list.getItems().size(); i++) {
      try {
        Element element = (Element) list.getItems().get(i);
        if (element.type() == Element.CHUNK) {
          element = new ListItem((Chunk) element);
        }
        if (element instanceof ListItem) {
          this.alignment = ((ListItem) element).getAlignment();
        }
        RtfBasicElement rtfElement = doc.getMapper().mapElement(element);
        if (rtfElement instanceof RtfList) {
          ((RtfList) rtfElement).setListNumber(listNumber);
          ((RtfList) rtfElement).setListLevel(listLevel + 1);
          ((RtfList) rtfElement).setParent(this);
        } else if (rtfElement instanceof RtfListItem) {
          ((RtfListItem) rtfElement).setParent(this);
          ((RtfListItem) rtfElement).inheritListSettings(listNumber, listLevel + 1);
        }
        items.add(rtfElement);
      } catch (DocumentException de) {
        de.printStackTrace();
      }
    }

    if (this.listLevel == 0) {
      correctIndentation();
    }

    fontNumber =
        new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
    if (list.getSymbol() != null
        && list.getSymbol().getFont() != null
        && !list.getSymbol().getContent().startsWith("-")
        && list.getSymbol().getContent().length() > 0) {
      // only set this to bullet symbol is not default
      this.fontBullet = new RtfFont(document, list.getSymbol().getFont());
      this.bulletCharacter = list.getSymbol().getContent().substring(0, 1);
    } else {
      this.fontBullet =
          new RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
    }
  }