Package org.odftoolkit.simple.draw

Examples of org.odftoolkit.simple.draw.Image


  public Image setImage(URI imageUri) {
    if (imageUri == null)
      return null;

    splitRepeatedCells();
    Image newImage;
    try {
      NodeList cellPs = mCellElement.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      if (cellPs != null && cellPs.getLength() > 0) {
        for (int i = 0; i < cellPs.getLength(); i++) {
          mCellElement.removeChild(cellPs.item(i));
        }
      }

      if (mOwnerTable.mIsSpreadsheet) {
        newImage = Image.newImage(this, imageUri);
      } else {
        OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
        TextPElement pElement = dom.newOdfElement(TextPElement.class);
        mCellElement.appendChild(pElement);
        newImage = Image.newImage(Paragraph.getInstanceof(pElement), imageUri);
      }
      if (imageUri != null) {
        FrameRectangle rect = newImage.getRectangle();
        double height = rect.getHeight();
        double width = rect.getWidth();
        long widthInMI = new Double(width / 100).longValue();
        Column column = getTableColumn();
        if (widthInMI > column.getWidth()) {
View Full Code Here


  public Image setImage(URI imageUri) {
    if (imageUri == null)
      return null;

    splitRepeatedCells();
    Image newImage;
    try {
      NodeList cellPs = mCellElement.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      if (cellPs != null && cellPs.getLength() > 0) {
        for (int i = 0; i < cellPs.getLength(); i++) {
          mCellElement.removeChild(cellPs.item(i));
        }
      }

      if (mOwnerTable.mIsSpreadsheet) {
        newImage = Image.newImage(this, imageUri);
      } else {
        OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
        TextPElement pElement = dom.newOdfElement(TextPElement.class);
        mCellElement.appendChild(pElement);
        newImage = Image.newImage(Paragraph.getInstanceof(pElement), imageUri);
      }
      if (imageUri != null) {
        FrameRectangle rect = newImage.getRectangle();
        double height = rect.getHeight();
        double width = rect.getWidth();
        long widthInMI = new Double(width / 100).longValue();
        Column column = getTableColumn();
        if (widthInMI > column.getWidth()) {
View Full Code Here

  public void setUp() {
    try {
      doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
      sourcedoc=TextDocument.newTextDocument();
      Paragraph para = sourcedoc.addParagraph("helloImage");
      Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
      image.setName("this image 1");
      image.setHyperlink(new URI("http://odftoolkit.org"));
     
      Paragraph para2 = sourcedoc.addParagraph("helloImage2");
      image2 = Image.newImage(para2, ResourceUtilities.getURI("testA.jpg"));
      image2.setName("this image 2");
      image2.setHyperlink(new URI("http://odftoolkit.org"));
View Full Code Here

        Paragraph paragraph=sourcedoc.getParagraphByIndex(0, true);
        TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
        NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
        Node nodeImage = nodeImages.item(0);
        DrawImageElement im = (DrawImageElement)nodeImage;
        Image ima = Image.getInstanceof(im);
        Image image = nextImageSelection.replaceWithImage(ima);
        Assert.assertNotNull(image);
        if(image.getName().startsWith("replace")){
          Assert.assertTrue(true);
        }else{
          Assert.fail();
        }
        String name="simple"+(i++);
        image.setName(name);
        Assert.assertEquals(name,image.getName());
    }
      Image image =nextImageSelection.replaceWithImage(image2);
      image.setName("simpletwice");
      Assert.assertEquals("simpletwice",image.getName());
    doc.save(ResourceUtilities.newTestOutputFile("TestImageSelectionImageResult.odt"));
    } catch (Exception e) {
      Logger.getLogger(ImageSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
View Full Code Here

      ImageSelection nextImageSelection=null;
      while (search.hasNext()) {
        TextSelection item= (TextSelection) search.nextSelection();
        nextImageSelection=new ImageSelection(item);
        URI imageuri = ResourceUtilities.getURI("image_list_item.png");
        Image image = nextImageSelection.replaceWithImage(imageuri);
        Assert.assertNotNull(image);
        if(image.getName().startsWith("replace")){
          Assert.assertTrue(true);
        }else{
          Assert.fail();
        }
        String name="simple"+(i++);
        image.setName(name);
        Assert.assertEquals(name,image.getName());
    }
      URI imageuri =  ResourceUtilities.getURI("testA.jpg");
      Image image =nextImageSelection.replaceWithImage(imageuri);
      image.setName("simpletwice");
      Assert.assertEquals("simpletwice",image.getName());
    doc.save(ResourceUtilities.newTestOutputFile("TestImageSelectionURIResult.odt"));
    } catch (Exception e) {
      Logger.getLogger(ImageSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
View Full Code Here

  @Test
  public void testReplacewithImage() throws Exception {
    // create source image
    TextDocument sourcedoc = TextDocument.newTextDocument();
    Paragraph para = sourcedoc.addParagraph("helloImage");
    Image image = Image.newImage(para, ResourceUtilities.getURI("image_list_item.png"));
    image.setName("this image 1");
    image.setHyperlink(new URI("http://odftoolkit.org"));
    Paragraph para2 = sourcedoc.addParagraph("helloImage2");
    Image image2 = Image.newImage(para2, ResourceUtilities.getURI("testA.jpg"));
    image2.setName("this image 2");
    image2.setHyperlink(new URI("http://odftoolkit.org"));
    search = null;
    // 6 Simple, at the middle of original Paragraph, split original
    // Paragraph, insert before the second Paragraph.
    doc = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(TEXT_FILE));
    search = new TextNavigation("SIMPLE", doc);
    int i = 0;
    TextSelection item = null;
    while (search.hasNext()) {
      item = (TextSelection) search.nextSelection();
      Paragraph paragraph = sourcedoc.getParagraphByIndex(0, true);
      TextParagraphElementBase textParaEleBase = paragraph.getOdfElement();
      NodeList nodeImages = textParaEleBase.getElementsByTagName("draw:image");
      Node nodeImage = nodeImages.item(0);
      DrawImageElement im = (DrawImageElement) nodeImage;
      Image ima = Image.getInstanceof(im);
      image = item.replaceWith(ima);
      Assert.assertNotNull(image);
      if (image.getName().startsWith("replace")) {
        Assert.assertTrue(true);
      } else {
View Full Code Here

      try {
    // new image in a table
    TextDocument sDoc = TextDocument.newTextDocument();
    Table table1 = sDoc.addTable(2, 2);
    Cell cell1 = table1.getCellByPosition(0, 0);
    Image image3 = cell1.setImage(ResourceUtilities.getURI("image_list_item.png"));
    image3.setVerticalPosition(FrameVerticalPosition.BELOW);
   
    //validate
    Assert.assertEquals(FrameVerticalPosition.BELOW, image3.getVerticalPosition());
   
    //
    FrameVerticalPosition ver = FrameVerticalPosition.enumValueOf("");
    Assert.assertEquals("middle", ver.toString());
   
View Full Code Here

    try {
      // new image in a table
      TextDocument sDoc = TextDocument.newTextDocument();
      Table table1 = sDoc.addTable(2, 2);
      Cell cell1 = table1.getCellByPosition(0, 0);
      Image image3 = cell1.setImage(ResourceUtilities.getURI("image_list_item.png"));
      image3.setHorizontalPosition(FrameHorizontalPosition.LEFT);
      Assert.assertEquals(FrameHorizontalPosition.LEFT, image3.getHorizontalPosition());
     
      //
      FrameHorizontalPosition hor = FrameHorizontalPosition.enumValueOf("");
      Assert.assertEquals("center", hor.toString());
      FrameHorizontalPosition hor1 = FrameHorizontalPosition.enumValueOf("inside");
View Full Code Here

  public Image setImage(URI imageUri) {
    if (imageUri == null)
      return null;

    splitRepeatedCells();
    Image newImage;
    try {
      NodeList cellPs = mCellElement.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      if (cellPs != null && cellPs.getLength() > 0) {
        for (int i = 0; i < cellPs.getLength(); i++) {
          mCellElement.removeChild(cellPs.item(i));
        }
      }

      if (mOwnerTable.mIsSpreadsheet) {
        newImage = Image.newImage(this, imageUri);
      } else {
        OdfFileDom dom = (OdfFileDom) mCellElement.getOwnerDocument();
        TextPElement pElement = dom.newOdfElement(TextPElement.class);
        mCellElement.appendChild(pElement);
        newImage = Image.newImage(Paragraph.getInstanceof(pElement), imageUri);
      }
      if (imageUri != null) {
        FrameRectangle rect = newImage.getRectangle();
        double height = rect.getHeight();
        double width = rect.getWidth();
        long widthInMI = new Double(width / 100).longValue();
        Column column = getTableColumn();
        if (widthInMI > column.getWidth()) {
View Full Code Here

   *  
   * @return the new Image in the TextDocument,the image name is set to "replace" + System.currentTimeMillis(), please update the name to others by yourself.
   *
   */
  public Image replaceWithImage(Image image) {
    Image mImage =null;
    if(search instanceof TextNavigation){
      TextNavigation textSearch = (TextNavigation) search;
    int leftLength = textSelection.getText().length();
    int index = textSelection.getIndex();
    mIsInserted = false;
    OdfElement parentElement = textSelection.getContainerElement();
    OdfFileDom ownerDom = (OdfFileDom) parentElement.getOwnerDocument();
   
      int nodeLength = TextExtractor.getText(
          this.textSelection.getContainerElement()).length();
      if (this.textSelection.getText().length() != nodeLength)
        this.textSelection.setSelectionReplaced(true);
    try {
      if (imageContainer == null) {
        delete(index, leftLength, parentElement);
        // PrepareContainer
        imageContainer = ownerDom.newOdfElement(DrawFrameElement.class);
        insertOdfElement(imageContainer, index, parentElement);
      } else {
        NodeList nodeImages = imageContainer.getElementsByTagName("draw:image");
        Node nodeImage = nodeImages.item(0);
        DrawImageElement im = (DrawImageElement) nodeImage;
        Image oldimage = Image.getInstanceof(im);
        oldimage.remove();
        // PrepareContainer
        imageContainer = ownerDom.newOdfElement(DrawFrameElement.class);
        insertOdfElement(imageContainer, index, parentElement);
      }
      // Insert Image resource to package
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.draw.Image

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.