Draw/Java/ adding label/text in XShape

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jarssonn
Posts: 2
Joined: Wed Aug 31, 2016 11:16 am

Draw/Java/ adding label/text in XShape

Post by jarssonn »

Hello everyone,
I'm creating some app to draw scheme using rectangle XShapes. I'd like to name every shape and show the label inside it. I went through the documentation and I didn't find how to put text label into shape and show it. I've been stuck for 2 days with this problem, so I'd really happy if you can take a look and write some example :( . Thank you in advance.
OpenOffice 3.1 on Red Hat Enterprise 6.6
FJCC
Moderator
Posts: 9549
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Draw/Java/ adding label/text in XShape

Post by FJCC »

I don't write Java macros but here is how I would insert a rectangle and add text in Basic. I hope that helps.

Code: Select all

Dim oSize as New com.sun.star.awt.Size
Dim oPos as New com.sun.star.awt.Point
oRect = ThisComponent.createInstance("com.sun.star.drawing.RectangleShape")
oSize.Width = 7000
oSize.Height = 2000
oPos.X = 5000
oPos.Y =6000
oRect.setSize(oSize)
oRect.setPosition(oPos)
oDPages = ThisComponent.getDrawPages()
oDP = oDPages.getByIndex(0)
oDP.add(oRect)
oRect.setString("The Name")
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
jarssonn
Posts: 2
Joined: Wed Aug 31, 2016 11:16 am

Re: Draw/Java/ adding label/text in XShape

Post by jarssonn »

Unfortunately this didn't help. XShape doesn't have setString method. What's more, I used another solution and there's one more problem.
I am declaring shape like this:

Code: Select all

         
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 then I am trying to set XText

Code: Select all

xShapeText.setString("ABC"); 
The problem is when I start the app, and get this exception:
com.sun.star.lang.DisposedException
at com.sun.star.lib.uno.environments.remote.JobQueue.removeJob(JobQueue.java:210)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:330)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:303)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:87)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:636)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:146)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:128)
at com.sun.proxy.$Proxy6.setString(Unknown Source)
at com.ericsson.stpdiagramgenerator.presentation.core.HelloTextTableShape.manipulateText(HelloTextTableShape.java:265)
at com.ericsson.stpdiagramgenerator.presentation.core.HelloTextTableShape.useWriter(HelloTextTableShape.java:65)
at com.ericsson.stpdiagramgenerator.presentation.core.HelloTextTableShape.useDocuments(HelloTextTableShape.java:52)
at com.ericsson.stpdiagramgenerator.presentation.core.HelloTextTableShape.main(HelloTextTableShape.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 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
at com.sun.star.lib.uno.bridges.java_remote.XConnectionInputStream_Adapter.read(XConnectionInputStream_Adapter.java:55)
at java.io.DataInputStream.readInt(DataInputStream.java:387)
at com.sun.star.lib.uno.protocols.urp.urp.readBlock(urp.java:355)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:92)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.run(java_remote_bridge.java:105)
I don't know what to do else. Thanks for help anyway.
OpenOffice 3.1 on Red Hat Enterprise 6.6
UnklDonald418
Volunteer
Posts: 1566
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Draw/Java/ adding label/text in XShape

Post by UnklDonald418 »

I'm not really conversant in JAVA but comparing your code and what FJCC posted I wonder if this might work

Code: Select all

drawShape.setString("ABC"); 
instead of trying to set the Properties
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply