Hi Nicole,

Nicole Scholz escribió:
Hi Marc!

Thanks for your answer. I tried to insert a paragraph break and a line break 
but the textfield is inserted right to the other one and not below. Perhaps 
there is another possibility to change the position of the textfield.

Here is my code:

/* create a RectangleShape */
Shape = xDocFactory~createInstance("com.sun.star.drawing.RectangleShape")
xShape = Shape~xShape

size = .bsf~new("com.sun.star.awt.Size", 8000 /*width*/, 5000 /*height*/)
xShape~setSize(size)

xShapeProps=xShape~xPropertySet
at_para=bsf.getConstant("com.sun.star.text.TextContentAnchorType","AT_PARAGRAPH")
xShapeProps~setPropertyValue("AnchorType", at_para)
xShapeProps~setPropertyValue("FillColor", box("int", "C0 C0 C0"x ~c2d))
-- create a text field at the document factory
xTextFieldProps=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet
linebreak = "0a"x
text = "OpenOffice.org API Project"
xTextFieldProps~setPropertyValue("Representation",text  "0a0909"x)
xTextFieldProps~setPropertyValue("TargetFrame", "_blank")
xTextFieldProps~setPropertyValue("URL", "http://api.openoffice.org";)

xTextFieldProps1=xDocFactory~createInstance("com.sun.star.text.TextField.URL")~XPropertySet
xTextFieldProps1~setPropertyValue("Representation", "GMX")
xTextFieldProps1~setPropertyValue("TargetFrame", "_blank")
xTextFieldProps1~setPropertyValue("URL", "http://www.gmx.at";)


-- get the XTextContent of the shape and the field
xShapeTextContent=xShape~XTextContent
xFieldTextContent=xTextFieldProps~XTextContent
xFieldTextContent1=xTextFieldProps1~XTextContent

-- the shape is inserted at the DOCUMENT text
xDocText~insertTextContent(xDocTextCursor, xShapeTextContent, .false)

-- access the text inside the shape,
-- and create a text cursor
xShapeText       = xShape~XText
xShapeTextCursor = xShapeText~createTextCursor

call bsf.import "com.sun.star.text.ControlCharacter", "ctlChar"

-- insert the field at the SHAPE text
paraBreak=.CtlChar~paragraph_break     -- gets used multiple times in this 
routine
xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent, .false)
xShapeText~insertControlCharacter(xShapeTextCursor~getEnd, 
.CtlChar~paragraph_break, .false)
xShapeText~insertTextContent(xShapeTextCursor, xFieldTextContent1, .false)

the code I attach looks quite like yours. In Java the only problem is that

xShapeText.insertControlCharacter(xShapeTextCursor.getEnd(),
                    ControlCharacter.PARAGRAPH_BREAK, false);

does not insert the paragraph break, but any way the fields are inserted in the right order, one after the other.
See if translating line by line the Java code to ooRex solves the problem.

Regards
Ariel.

--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openoffice.sdk.drawing;

import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.ControlCharacter;
import com.sun.star.text.TextContentAnchorType;
import com.sun.star.text.XText;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime; 

/**
 *
 * @author ariel
 */
public class HyperlinkShape {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext == null) {
                System.err.println("ERROR: Could not bootstrap default Office.");
            }
            XMultiComponentFactory xMCF = xContext.getServiceManager();

            // get the XComponentLoader from the Desktop
            // to load a new document
            XComponentLoader xComponentLoader = (XComponentLoader)
                    UnoRuntime.queryInterface(
                        XComponentLoader.class,
                        xMCF.createInstanceWithContext(
                            "com.sun.star.frame.Desktop", xContext));

            // load a new Writer document
            XTextDocument xTextDocument = (XTextDocument)
                    UnoRuntime.queryInterface(
                        XTextDocument.class,
                        xComponentLoader.loadComponentFromURL(
                            "private:factory/swriter", "_blank",
                            0, new PropertyValue[]{} ) );

            // get the document text body
            XText xDocText = xTextDocument.getText();
            // create a text cursor
            XTextCursor xDocTextCursor = xDocText.createTextCursorByRange(
                    xDocText.getStart());

            // access the document factory to instantiate new objects
            XMultiServiceFactory xDocFactory = (XMultiServiceFactory)
                    UnoRuntime.queryInterface(
                        XMultiServiceFactory.class, xTextDocument);

            // create a shape
            XShape xShape = (XShape) UnoRuntime.queryInterface(
                    XShape.class, xDocFactory.createInstance(
                    "com.sun.star.drawing.EllipseShape"));

            // access the shape's properties
            XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xShape );

            xShape.setSize( new Size( 8000, 8000) );
            xShapeProps.setPropertyValue( "AnchorType",
                    TextContentAnchorType.AT_PARAGRAPH);

            // create a text field at the document factory
            XPropertySet xTextFieldProps = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xDocFactory.createInstance(
                    "com.sun.star.text.TextField.URL"));

            xTextFieldProps.setPropertyValue(
                    "Representation", "OpenOffice.org API Project");
            xTextFieldProps.setPropertyValue(
                    "TargetFrame", "_blank");
            xTextFieldProps.setPropertyValue(
                    "URL", "http://api.openoffice.org";);

            // get the XTextContent of the shape and the field
            XTextContent xShapeTextContent = (XTextContent) UnoRuntime.queryInterface(
                    XTextContent.class, xShape );
            XTextContent xFieldTextContent = (XTextContent) UnoRuntime.queryInterface(
                    XTextContent.class, xTextFieldProps );

            // the shape is inserted at the DOCUMENT text
            xDocText.insertTextContent(xDocTextCursor, xShapeTextContent, false);

            // access the text inside the shape,
            // and create a text cursor
            XText xShapeText = (XText) UnoRuntime.queryInterface(
                    XText.class, xShape);
            XTextCursor xShapeTextCursor = xShapeText.createTextCursor();

            // insert the field at the SHAPE text
            xShapeText.insertTextContent(xShapeTextCursor, xFieldTextContent, false);
            
            // both a space or a ctrl char. work
            // xShapeText.insertString(xShapeTextCursor, " ", false);
            xShapeText.insertControlCharacter(xShapeTextCursor, 
                    ControlCharacter.PARAGRAPH_BREAK, false);
            
            
            // create another text field at the document factory
            xTextFieldProps = (XPropertySet) UnoRuntime.queryInterface(
                    XPropertySet.class, xDocFactory.createInstance(
                    "com.sun.star.text.TextField.URL"));

            xTextFieldProps.setPropertyValue(
                    "Representation", "Another URL text field");
            xTextFieldProps.setPropertyValue(
                    "TargetFrame", "_blank");
            xTextFieldProps.setPropertyValue(
                    "URL", "http://api.openoffice.org";);
            
            xFieldTextContent = (XTextContent) UnoRuntime.queryInterface(
                    XTextContent.class, xTextFieldProps );
            
            xShapeText.insertTextContent(xShapeTextCursor, xFieldTextContent, false);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to