Page 1 of 1
listerner for java
Posted: 09 Mar 2015, 12:37
by StefzX
Hello I'm using CadEditorX in Java via OLE.
I know i can execute some commands from code by submitting xml strings.
My question is: is it possible to know (for example with a listerner) where I'm clicking with the mouse? (on the drawing)
Thanks in advice
Re: listerner for java
Posted: 13 Mar 2015, 20:53
by support
Hello Stefano,
It is possible to handle the OnProcess event (which is common for all events - OnMouseDown, OnSelectEntity, etc.) in Java code with a created OleListener. Have a look at the code snippet below. The event.arguments[0] returns the output XML string which can contain some information depending on what event has been fired.
Code: Select all
OleControlSite sgCADEditor = null;
try
{
sgCADEditor = new OleControlSite(frame, SWT.NONE, "CADEditorLib.SgCADEditor");
int OnProcess = 224; // or 0x000000e0 - the identifier for the OnProcess event obtained from the type library
sgCADEditor.addEventListener(OnProcess, new OleListener() {
public void handleEvent(OleEvent event) {
if (event.detail != OnProcess) return;
Variant aXML = event.arguments[0];
if (aXML == null) return;
String outputXML = aXML.getString();
}
});
sgCADEditor.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
}
The OnMouseDown event returns X and Y coordinates of the location where you click with the mouse. This event is disabled by default, in order to be able to handle this event with a created listener, you should enable it (or "sign to the event" in terms of CADEditorX) by processing the following XML command:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<cadsofttools version="2">
<signtoevent Event="OnMouseDown" Enabled="True"/>
</cadsofttools>
Mikhail
Re: listerner for java
Posted: 15 Mar 2015, 22:24
by StefzX
Hello,
Thanks a lot, it worked!
Otherwise i had to change "event.detail" into "event.type" to get it to work, just in case anybody else will look forward this feature in the future
Kind regards,
Stefano Franchini