Package org.odftoolkit.simple.text

Examples of org.odftoolkit.simple.text.Paragraph


      // test append paragraph
      TextDocument doc = TextDocument.newTextDocument();
      Table table = Table.newTable(doc, 2, 2);
      Cell cell = table.getCellByPosition(0, 0);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
      }

      // test set paragraph content
      cell = table.getCellByPosition(0, 1);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
        String content = para.getTextContent();
        Assert.assertEquals(plainText[i], content);
      }

      // test remove paragraph content
      cell = table.getCellByPosition(1, 0);
      for (int i = 0; i < plainText.length; i++) {
        Paragraph para = cell.addParagraph(plainText[i]);
        String content = para.getTextContent();
        Assert.assertEquals(plainText[i], content);
        para.removeTextContent();
        content = para.getTextContent();
        Assert.assertEquals("", content);
      }

      // test get paragraph by index
      cell = table.getCellByPosition(1, 1);
      Paragraph paragraph1 = cell.addParagraph("paragraph1");
      Paragraph paragraphE = cell.addParagraph(null);
      Paragraph paragraph2 = cell.addParagraph("p2");

      Paragraph t1 = cell.getParagraphByIndex(0, false);
      Assert.assertEquals(t1, paragraph1);
      t1 = cell.getParagraphByIndex(2, false);
      Assert.assertEquals(t1, paragraph2);
      t1 = cell.getParagraphByIndex(1, true);
      Assert.assertEquals(t1, paragraph2);
View Full Code Here


      // label2
      Label label = (Label) form.createLabel(doc, labelRtg, "Label2",
          "Label2");
      label.setAnchorType(AnchorType.TO_CHARACTER);
      // label3
      Paragraph para = doc.addParagraph("Insert a Label here.");
      form.createLabel(para, labelRtg, "Label3", "Label3");
      // label4
      Table table1 = Table.newTable(doc, 2, 2);
      Cell cell = table1.getCellByPosition("B1");
      para = cell.addParagraph("Insert a Label here.");
View Full Code Here

  @Test
  public void testSet() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.CM);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

  @Test
  public void testSetAchorTypeAs_character() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.CM);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

  @Test
  public void testSetAchorTypeTo_page() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.IN);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

  @Test
  public void testSetHorizontalPosition() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.IN);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

  @Test
  public void testSetVerticalRelative() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.IN);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

  @Test
  public void testSetHorizontalRelative() {
    String content = "This is a text box";
    try {
      TextDocument textDoc = TextDocument.newTextDocument();
      Paragraph p = textDoc.addParagraph("paragraph");
      FrameRectangle frameR = new FrameRectangle(4.21, 1.32, 4.41, 3.92, SupportedLinearMeasure.IN);
     
      Textbox box = p.addTextbox(frameR);
      box.setName("tbox name");
      box.setTextContent(content);
     
      FrameStyleHandler frameStyleHandler = new FrameStyleHandler(box);
      frameStyleHandler.setBackgroundColor(Color.YELLOW);
View Full Code Here

   * @throws Exception
   *             if the file DOM could not be created.
   * @since 0.5.5
   */
  public Paragraph addParagraph(String text) {
    Paragraph para = getParagraphContainerImpl().addParagraph(text);
    return para;
  }
View Full Code Here

  }
 
  private void prepareParagraphContainer(int leftLength, int index) throws Exception {
    OdfElement rightparentElement = textSelection.getContainerElement();
    int nodeLength = TextExtractor.getText(rightparentElement).length();
    Paragraph orgparagraph = Paragraph.getInstanceof((TextParagraphElementBase) rightparentElement);
   
    TextDocument document = (TextDocument) orgparagraph.getOwnerDocument();
    OfficeTextElement sroot = sourceDocument.getContentRoot();
    NodeList clist = sroot.getChildNodes();
   
    try {
      OfficeTextElement documentRoot = document.getContentRoot();
      Node rootNode = rightparentElement.getParentNode();
      if (!rootNode.equals(documentRoot)) {
        throw new RuntimeException(
            "The ParentNode of text content's ContainerElement which will be replaced is not Document ContentRoot, TextDocument only can be insert to the Docuemnt ContentRoot");
      }
    } catch (Exception e) {
      Logger.getLogger(TextDocumentSelection.class.getName()).log(Level.SEVERE, e.getMessage(), e);
    }
   
    if (index == 0) {
      if (leftLength == nodeLength) {
        // Replace whole Paragraph
        OdfElement refElement = orgparagraph.getOdfElement();
        for (int i = 0; i < clist.getLength(); i++) {
          OdfElement node = (OdfElement) clist.item(i);
          refElement = document.insertOdfElement(refElement,
              sourceDocument, node, false);
        }
        rightparentElement.getParentNode().removeChild(
            rightparentElement);
      } else {
        // at the start of original Paragraph, insert before original
        // Paragraph
        delete(index, leftLength, rightparentElement);
        for (int i = 0; i < clist.getLength(); i++) {
          OdfElement node = (OdfElement) clist.item(i);
          document.insertOdfElement(orgparagraph.getOdfElement(), sourceDocument, node, true);
        }
      }
    } else if (nodeLength == (index + leftLength)) {
      // at the end of original Paragraph, insert after original Paragraph
      delete(index, leftLength, rightparentElement);
      for (int i = 0; i < clist.getLength(); i++) {
        OdfElement node = (OdfElement) clist.item(i);
        document.insertOdfElement(orgparagraph.getOdfElement(), sourceDocument, node, false);
      }
    } 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);
      for (int i = 0; i < clist.getLength(); i++) {
        OdfElement node = (OdfElement) clist.item(i);
        document.insertOdfElement(orgparagraph.getOdfElement(), sourceDocument, node, true);
      }
      int offset = 0 - leftLength - index;
      SelectionManager.refresh(rightparentElement, offset, offset);
    }
  }
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.