Java LibreOffice Draw - Set text of a shape -


i'm using java , libreoffice api, , i'd draw rectangles , set names, or put text fields on them. drawing shapes relatively easy, adding text hard. didn't find solution, neither in documentation nor @ forums.

i declaring shape , text this:

object drawshape = xdrawfactory.createinstance("com.sun.star.drawing.rectangleshape"); xshape xdrawshape = unoruntime.queryinterface(xshape.class, drawshape); xdrawshape.setsize(new size(10000, 20000)); xdrawshape.setposition(new point(5000, 5000)); xdrawpage.add(xdrawshape);  xtext xshapetext = unoruntime.queryinterface(xtext.class, drawshape); xpropertyset xshapeprops = unoruntime.queryinterface(xpropertyset.class, drawshape); 

and trying set xtext:

xshapetext.setstring("abc"); 

and problem appears (this exception not clear me after reading explanation documentation):

com.sun.star.lang.disposedexception @ com.sun.star.lib.uno.environments.remote.jobqueue.removejob(jobqueue.java:210) @ com.sun.star.lib.uno.environments.remote.jobqueue.enter(jobqueue.java:330) @ com.sun.star.lib.uno.environments.remote.jobqueue.enter(jobqueue.java:303) @ com.sun.star.lib.uno.environments.remote.javathreadpool.enter(javathreadpool.java:87) @ com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendrequest(java_remote_bridge.java:636) @ com.sun.star.lib.uno.bridges.java_remote.proxyfactory$handler.request(proxyfactory.java:146) @ com.sun.star.lib.uno.bridges.java_remote.proxyfactory$handler.invoke(proxyfactory.java:128) @ com.sun.proxy.$proxy6.setstring(unknown source) @ com.ericsson.stpdiagramgenerator.presentation.core.hellotexttableshape.manipulatetext(hellotexttableshape.java:265) @ com.ericsson.stpdiagramgenerator.presentation.core.hellotexttableshape.usewriter(hellotexttableshape.java:65) @ com.ericsson.stpdiagramgenerator.presentation.core.hellotexttableshape.usedocuments(hellotexttableshape.java:52) @ com.ericsson.stpdiagramgenerator.presentation.core.hellotexttableshape.main(hellotexttableshape.java:42) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ com.intellij.rt.execution.application.appmain.main(appmain.java:147) caused by: java.io.ioexception: com.sun.star.io.ioexception: eof reached - socket,host=localhost,port=8100,localhost=localhost.localdomain,localport=34456,peerhost=localhost,peerport=8100 @ com.sun.star.lib.uno.bridges.java_remote.xconnectioninputstream_adapter.read(xconnectioninputstream_adapter.java:55) @ java.io.datainputstream.readint(datainputstream.java:387) @ com.sun.star.lib.uno.protocols.urp.urp.readblock(urp.java:355) @ com.sun.star.lib.uno.protocols.urp.urp.readmessage(urp.java:92) @ com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$messagedispatcher.run(java_remote_bridge.java:105)

maybe have solution inserting text/textbox/textfield on shape libreoffice api.

your code works fine on machine. tested in libreoffice 5.1.0.3 on windows. here code used:

com.sun.star.frame.xdesktop xdesktop = null; // getdesktop() // https://wiki.openoffice.org/wiki/api/samples/java/writer/bookmarkinsertion xdesktop = getdesktop(); com.sun.star.lang.xcomponent xcomponent = null; try {     xcomponent = xdesktop.getcurrentcomponent();     xdrawpagessupplier xdrawpagessupplier =          (xdrawpagessupplier)unoruntime.queryinterface(             xdrawpagessupplier.class, xcomponent);     object drawpages = xdrawpagessupplier.getdrawpages();     xindexaccess xindexeddrawpages = (xindexaccess)         unoruntime.queryinterface(         xindexaccess.class, drawpages);     object drawpage = xindexeddrawpages.getbyindex(0);     xmultiservicefactory xdrawfactory =          (xmultiservicefactory)unoruntime.queryinterface(             xmultiservicefactory.class, xcomponent);     object drawshape = xdrawfactory.createinstance(         "com.sun.star.drawing.rectangleshape");     xdrawpage xdrawpage = (xdrawpage)unoruntime.queryinterface(         xdrawpage.class, drawpage);     xshape xdrawshape = unoruntime.queryinterface(xshape.class, drawshape);     xdrawshape.setsize(new size(10000, 20000));     xdrawshape.setposition(new point(5000, 5000));     xdrawpage.add(xdrawshape);      xtext xshapetext = unoruntime.queryinterface(xtext.class, drawshape);     xpropertyset xshapeprops = unoruntime.queryinterface(         xpropertyset.class, drawshape);     xshapetext.setstring("def"); } catch( exception e) {     e.printstacktrace(system.err);     system.exit(1); } 

to run it, opened new libreoffice draw file, pressed "run project" in netbeans. result:

enter image description here

it looks exception may caused problem connecting document. how running macro?

related: question posted @ https://forum.openoffice.org/en/forum/viewtopic.php?f=20&p=395334, contains solution in basic.


Comments