Package org.odftoolkit.simple.text

Examples of org.odftoolkit.simple.text.Paragraph


    // first-row-start-column
    Cell cell = table.getCellByPosition(0, 0);
    cell.getParagraphIterator().hasNext();
    cell.getParagraphIterator().next().getStyleName();
    Paragraph para = cell.getParagraphByIndex(0, false);
    String paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.FIRSTROWSTARTCOLUM, cell
            .getStyleName(), paraStyle);
    TableTableCellElementBase oldCellEle = cell.getOdfElement();
    TableTableCellElementBase newCellEle = (TableTableCellElementBase) oldCellEle
        .cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first-row-end-column
    cell = table.getCellByPosition(4, 0);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.FIRSTROWENDCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last-row-start-column
    cell = table.getCellByPosition(0, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.LASTROWSTARTCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last-row-end-column
    cell = table.getCellByPosition(4, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.LASTROWENDCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first column
    cell = table.getCellByPosition(0, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableFirstColumnStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last column
    cell = table.getCellByPosition(4, 2);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableLastColumnStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first row
    cell = table.getCellByPosition(1, 0);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableFirstRowStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last row
    cell = table.getCellByPosition(1, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableLastRowStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // body (=odd row/column)
    cell = table.getCellByPosition(1, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableBodyStyle(cell.getStyleName(), paraStyle);
    template.setTableOddRowsStyle(cell.getStyleName(), paraStyle);
    template.setTableOddColumnsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // even row
    cell = table.getCellByPosition(1, 2);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableEvenRowsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // even row
    cell = table.getCellByPosition(2, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableEvenColumnsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());
View Full Code Here


    if (validate() == false) {
      throw new InvalidNavigationException("No matched string at this position");
    }
    Field newfield=null;
    OdfElement parentElement = getContainerElement();
    Paragraph orgparagraph = Paragraph.getInstanceof((TextParagraphElementBase) parentElement);
    TextDocument document = (TextDocument) orgparagraph.getOwnerDocument();
   
    FieldSelection nextFieldSelection=new FieldSelection(this);
    FieldType fieldType = orgField.getFieldType();
 
    switch (fieldType) {
View Full Code Here

      OdfElement rightparentElement = textSelection.getContainerElement();
      int nodeLength = TextExtractor.getText(rightparentElement).length();
      if(index==0){
        if(leftLength==nodeLength){
          //Replace whole Paragraph
          Paragraph orgparagraph = Paragraph
              .getInstanceof((TextParagraphElementBase) rightparentElement);
          TextDocument document = (TextDocument) orgparagraph
              .getOwnerDocument();
          paragraphContainer = document.insertParagraph(orgparagraph,
              sourceParagraph, false);
          NodeList cnl = rightparentElement.getChildNodes();
          pos = "whole";
          handlePageBreak(orgparagraph, pos, continued);

          rightparentElement.getParentNode().removeChild(
              rightparentElement);
        }else{
          //at the start of original Paragraph, insert before original Paragraph
          delete(index, leftLength, rightparentElement);
          Paragraph orgparagraph = Paragraph
              .getInstanceof((TextParagraphElementBase) rightparentElement);
          TextDocument document = (TextDocument) orgparagraph
              .getOwnerDocument();
          paragraphContainer = document.insertParagraph(orgparagraph,
              sourceParagraph, true);
          pos = "head";
          handlePageBreak(orgparagraph, pos, continued);
      }
      } else if (nodeLength == (index + leftLength)) {
        //at the end of original Paragraph, insert after original Paragraph
        delete(index, leftLength, rightparentElement);
        Paragraph orgparagraph = Paragraph
            .getInstanceof((TextParagraphElementBase) rightparentElement);
        TextDocument document = (TextDocument) orgparagraph
            .getOwnerDocument();
        paragraphContainer = document.insertParagraph(orgparagraph,
            sourceParagraph, false);
        handlePageBreak(orgparagraph, pos, continued);
      }else{
        //at the middle of original Paragraph, split original Paragraph, insert before the second Paragraph.
        delete(index, leftLength, rightparentElement);
        Node leftparentElement = rightparentElement.cloneNode(true);
        rightparentElement.getParentNode().insertBefore(
            leftparentElement, rightparentElement);
        nodeLength = TextExtractor.getText(
            (OdfElement) leftparentElement).length();
        delete(index, nodeLength-index, leftparentElement);
        delete(0, index, rightparentElement);
        Paragraph orgparagraph = Paragraph
            .getInstanceof((TextParagraphElementBase) rightparentElement);
        TextDocument document = (TextDocument) orgparagraph
            .getOwnerDocument();
        paragraphContainer = document.insertParagraph(orgparagraph,
            sourceParagraph, true);
        if (!continued)
          cleanBreakProperty(orgparagraph);
       
      }
    } else{
      TextDocument document = (TextDocument) paragraphContainer
          .getOwnerDocument();
      Paragraph tmp = document.insertParagraph(paragraphContainer,
          sourceParagraph, true);
      paragraphContainer.remove();
      paragraphContainer=tmp;
    }
  }
View Full Code Here

          paraStyle = oddCellParagraphStyle;
        }
        cell.setCellStyleName(tableStyle);
        Iterator<Paragraph> paraIterator = cell.getParagraphIterator();
        while (paraIterator.hasNext()) {
          Paragraph t = paraIterator.next();
          t.getOdfElement().setStyleName(paraStyle);
        }
        cellIndex++;
      }
    }
  }
View Full Code Here

      }
      preparetableContainer(leftLength, index, continued);
      Selection.SelectionManager.unregisterItem(this.textSelection);
      if (textSearch != null) {
        textSearch.setReplacedItem(this.textSelection);
        Paragraph lastParagraph = getLastParagraphInTable(tableContainer);
        OdfElement newStartPoint;
        if (lastParagraph != null) {
          newStartPoint = lastParagraph.getOdfElement();
        } else {
          newStartPoint = tableContainer.getOdfElement();
        }
        String content = TextExtractor.getText(newStartPoint);
        TextSelection selected = newTextSelection(textSearch,
View Full Code Here

      int nodeLength = TextExtractor.getText(rightparentElement).length();
      if(index==0){
       
        if(leftLength==nodeLength){
          //Replace whole Paragraph
          Paragraph orgparagraph = Paragraph
              .getInstanceof((TextParagraphElementBase) rightparentElement);
          TextDocument document = (TextDocument) orgparagraph
              .getOwnerDocument();
          tableContainer = document.insertTable(orgparagraph,
              sourceTable, false);
          pos = "whole";
          handlePageBreak(orgparagraph, pos, continued);

          rightparentElement.getParentNode().removeChild(
              rightparentElement);
        }else{
          //at the start of original Paragraph, insert before original Paragraph
          delete(index, leftLength, rightparentElement);
          Paragraph orgparagraph = Paragraph
              .getInstanceof((TextParagraphElementBase) rightparentElement);
          TextDocument document = (TextDocument) orgparagraph
              .getOwnerDocument();
          tableContainer = document.insertTable(orgparagraph,
              sourceTable, true);
          pos = "head";
          handlePageBreak(orgparagraph, pos, continued);
      }
      } else if (nodeLength == (index + leftLength)) {
        //at the end of original Paragraph, insert after original Paragraph
        delete(index, leftLength, rightparentElement);
        Paragraph orgparagraph = Paragraph
            .getInstanceof((TextParagraphElementBase) rightparentElement);
        TextDocument document = (TextDocument) orgparagraph
            .getOwnerDocument();
        tableContainer = document.insertTable(orgparagraph,
            sourceTable, false);
        handlePageBreak(orgparagraph, pos, continued);
      }else{
        //at the middle of original Paragraph, split original Paragraph, insert before the second Paragraph.
        delete(index, leftLength, rightparentElement);
        Node leftparentElement = rightparentElement.cloneNode(true);
        rightparentElement.getParentNode().insertBefore(
            leftparentElement, rightparentElement);
        nodeLength = TextExtractor.getText(
            (OdfElement) leftparentElement).length();
        delete(index, nodeLength-index, leftparentElement);
        delete(0, index, rightparentElement);
        Paragraph orgparagraph = Paragraph
            .getInstanceof((TextParagraphElementBase) rightparentElement);
        TextDocument document = (TextDocument) orgparagraph
            .getOwnerDocument();
        tableContainer = document.insertTable(orgparagraph,
            sourceTable, true);
        if (!continued)
          textSelection.cleanBreakProperty(orgparagraph);
View Full Code Here

      Table table = Table.getInstance(newTEle);
      tableContainer=table;
    }
  }
  private Paragraph getLastParagraphInTable(Table table) {
    Paragraph paragraph = null;
    int rowCount = table.getRowCount();
    for (int i = rowCount - 1; i >= 0; i--) {
      Row row = table.getRowByIndex(i);
      int cellCount = row.getCellCount();
      for (int j = cellCount - 1; j >= 0; j--) {
View Full Code Here

   * @param text
   *            the text content of this paragraph
   * @return the new paragraph
   */
  public Paragraph addParagraph(String text) {
    Paragraph para = getParagraphContainerImpl().addParagraph(text);
    return para;
  }
View Full Code Here

      TextPElement texp = TextIndexTitle.newTextPElement();
      texp.setTextStyleNameAttribute("Contents_20_Heading");
      texp.setTextContent("Table of Contents");
      Iterator<Paragraph> paragraphIterator = getParagraphIterator();
      while (paragraphIterator.hasNext()) {
        Paragraph paragraph = paragraphIterator.next();
        String text = paragraph.getTextContent();
        String stylename = paragraph.getStyleName();
        // Outline support
        if (paragraph.isHeading()) {
          int headingLevel = paragraph.getHeadingLevel();
          if (stylename.length() <= 0) {
            stylename = "Contents_20_" + headingLevel;
          }
          ceateIndexBodyEntry(textIndexBody, stylename, text);
        }
        // end of Outline support
        // Index Makes support
        TextParagraphElementBase podf = paragraph.getOdfElement();
        NodeList cns = podf.getChildNodes();
        for (int i = 0; i < cns.getLength(); i++) {
          Node node = cns.item(i);
          if (node instanceof TextTocMarkElement) {
            TextTocMarkElement textTocMarkElement = (TextTocMarkElement) node;
View Full Code Here

      TextPElement texp = TextIndexTitle.newTextPElement();
      texp.setTextStyleNameAttribute("Contents_20_Heading");
      texp.setTextContent("Table of Contents");
      Iterator<Paragraph> paragraphIterator = getParagraphIterator();
      while (paragraphIterator.hasNext()) {
        Paragraph paragraph = paragraphIterator.next();
        String text = paragraph.getTextContent();
        String stylename = paragraph.getStyleName();
        // Outline support
        if (paragraph.isHeading()) {
          int headingLevel = paragraph.getHeadingLevel();
          if (stylename.length() <= 0) {
            stylename = "Contents_20_" + headingLevel;
          }
          ceateIndexBodyEntry(textIndexBody, stylename, text);
        }
        // end of Outline support
        // Additional Styles support
        if (tmptocstyleList.containsKey(stylename)) {
          int headingLevel = tmptocstyleList.get(stylename);
          stylename = "Contents_20_" + headingLevel;
          ceateIndexBodyEntry(textIndexBody, stylename, text);
        }
        // end of Additional Styles support
        // Index Makes support
        TextParagraphElementBase podf = paragraph.getOdfElement();
        NodeList cns = podf.getChildNodes();
        for (int i = 0; i < cns.getLength(); i++) {
          Node node = cns.item(i);
          if (node instanceof TextTocMarkElement) {
            TextTocMarkElement textTocMarkElement = (TextTocMarkElement) node;
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.text.Paragraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.