| View previous topic :: View next topic |
| Author |
Message |
Biermo General User

Joined: 08 Dec 2011 Posts: 6
|
Posted: Thu Dec 08, 2011 5:26 am Post subject: Uno -> Create event-listener for GraphicObjectShape |
|
|
Hello everybody!
I want to use the Java UNO-API to add a graphic to a shape with an interaction.
I am as far as I get an Image on an shape, but I don't know how to add the event listener:
| Code: |
private void insertImage(String file, String name) {
System.out.println("Image: file [" + file + "] / name [" + name + "]");
try {
XComponent document = getCurrentDoc();
com.sun.star.frame.XModel aDrawDoc = (XModel) UnoRuntime.queryInterface(XModel.class, document);
XMultiServiceFactory xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
XDrawPagesSupplier pagesSupplier = (com.sun.star.drawing.XDrawPagesSupplier) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, aDrawDoc);
XDrawPages xPages = pagesSupplier.getDrawPages();
XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, xPages.getByIndex(0));
XShape pictureShape = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, xMSFDoc.createInstance("com.sun.star.drawing.GraphicObjectShape"));
XPropertySet propSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, pictureShape);
propSet.setPropertyValue("GraphicURL", "file://" + file);
propSet.setPropertyValue("Name", name);
propSet.setPropertyValue("AsLink", false);
// Set Default-Size (10x10 cm)
Size picSize = new Size(10000, 10000);
pictureShape.setSize(picSize);
pictureShape.setPosition(new Point(1000, 2000));
page.add(pictureShape);
...
|
When I save the shape I get the right context.xml, but I want to add the event-part of the following code:
| Code: |
<draw:frame draw:style-name="gr1" draw:text-style-name="P1"
draw:layer="layout" svg:width="10.146cm" svg:height="6.752cm"
svg:x="5.785cm" svg:y="5cm">
<draw:image xlink:href="Pictures/1000000000000137000000CF58C318AD.jpg"
xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad">
<text:p />
</draw:image>
<office:event-listeners>
<presentation:event-listener
script:event-name="dom:click" presentation:action="execute"
xlink:href="../putty.exe" xlink:type="simple" xlink:show="embed"
xlink:actuate="onRequest" />
</office:event-listeners>
</draw:frame>
|
Does anybody know how to use Jave UNO library to add the <office:event-listener> logic to my image? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Thu Dec 08, 2011 6:19 am Post subject: |
|
|
I do not know Java library to do it but it can be as follows in OOo Basic:
| Code: | Sub SetInteraction
oDoc = ThisComponent
oShape = oDoc.getCurrentSelection().getByIndex(0)
oShape.OnClick = com.sun.star.presentation.ClickAction.PROGRAM
oShape.Bookmark = "lua"
End Sub |
|
|
| Back to top |
|
 |
Biermo General User

Joined: 08 Dec 2011 Posts: 6
|
Posted: Fri Dec 09, 2011 1:45 am Post subject: |
|
|
Thanks for your response, I will try it later, I have another problem now
Perhaps it works like the way with the Name-Property:
| Code: |
propSet.setPropertyValue("Name", "Testname");
propSet.setPropertyValue("OnClick",com.sun.star.presentation.ClickAction.PROGRAM);
propSet.setPropertyValue("Bookmark","../putty.exe");
|
At least I will try it that way. By the way:
Do you have a good (online) manual? I have looked at the API (http://api.openoffice.org/docs/common/ref/com/sun/star/drawing/XShape.html), but I can't find the properties I am allowed to set... |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri Dec 09, 2011 5:09 am Post subject: |
|
|
| Quote: | | Do you have a good (online) manual? | Try:
http://www.oooforum.org/forum/viewtopic.phtml?t=123053
There is no comprehensive documentation about the api I have seen. I have some documents on my homepage over five hundred pages but it seems you can not read it because of they are written in Japanese language. |
|
| Back to top |
|
 |
Biermo General User

Joined: 08 Dec 2011 Posts: 6
|
Posted: Mon Dec 12, 2011 10:25 pm Post subject: |
|
|
I finally got it! After hours of desperations I found out that the order of commands makes the difference:
My first try was this:
| Code: |
...
XShape xShape2 = ShapeHelper.createShape(xDrawDoc, new Point(10000, 3000), new Size(5000, 5000),
"com.sun.star.drawing.GraphicObjectShape");
xPropSet2 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape2);
xPropSet2.setPropertyValue("OnClick", ClickAction.PROGRAM);
xPropSet2.setPropertyValue("Bookmark", "C:/Windows/System32/notepad.exe");
xPropSet2.setPropertyValue("Name", "x2");
xPropSet2.setPropertyValue("GraphicURL", "file:///c:/MyShare/Bild01.jpg");
xPropSet2.setPropertyValue("Name", "Testname");
xShapes.add(xShape2);
...
|
but you first have to add the shape AND THEN you can set the OnClick Event.... crazy stuff!
| Code: |
...
XShape xShape2 = ShapeHelper.createShape(xDrawDoc, new Point(10000, 3000), new Size(5000, 5000),
"com.sun.star.drawing.GraphicObjectShape");
xShapes.add(xShape2);
xPropSet2 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape2);
xPropSet2.setPropertyValue("OnClick", ClickAction.PROGRAM);
xPropSet2.setPropertyValue("Bookmark", "C:/Windows/System32/notepad.exe");
xPropSet2.setPropertyValue("Name", "x2");
xPropSet2.setPropertyValue("GraphicURL", "file:///c:/MyShare/Bild01.jpg");
xPropSet2.setPropertyValue("Name", "Testname");
...
|
|
|
| Back to top |
|
 |
Biermo General User

Joined: 08 Dec 2011 Posts: 6
|
Posted: Mon Dec 12, 2011 10:30 pm Post subject: |
|
|
But I still have a -hopefully small- problem:
I set the bookmark to "../putty.exe" for example. So when putty.exe is in the same directory as the final odp file, it should be started this way (when I do edit the content.xml directly it reacts in this way). But when I save the file with the API, the API seems to resolve the ref :
When I startet the process from "/home/user" I got "file:///home/putty.exe" in the content.xml
Is there a chance to keep the link in the way I want? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Tue Dec 13, 2011 8:48 am Post subject: |
|
|
| Try to specify in URL form, you can get the same result specified by the UI. |
|
| Back to top |
|
 |
Biermo General User

Joined: 08 Dec 2011 Posts: 6
|
Posted: Tue Dec 13, 2011 12:21 pm Post subject: |
|
|
When I Use the UI and save the file, I get the same result
At first the interaction Element shows the right path, but when I save the file and look into the contet.xml, there is the absolute path... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|