Page 1 of 1

AuthorDnDListener - multiple DropTargetDropEvent managment

Posted: Thu Jun 18, 2015 11:26 am
by Johann
Hi,

In my application I need to drag'n drop a swing object to an oxygen XML document. I'm using an ro.sync.exml.editor.xmleditor.pageauthor.AuthorDnDListener to catch the drop action with the authorDrop(Transferable transferable, DropTargetDropEvent dropTargetDropEvent) method. It works perfectly.

My issue is that when I drop my object to my XML document, I have to write different actions according to the drag'n drop :
- "normal" drag'n drop
- drag'n drop + CTRL
- drag'n drop + ALT etc..

I succeeded in catching "normal" and "CTRL" drag'n drop with the DropTargetDropEvent :
- "normal" drag'n drop => dropTargetDropEvent.getDropAction() = 2
- drag'n drop + CTRL => dropTargetDropEvent.getDropAction() = 1

But these are the only different drag'n drops I differentiate.

How can I have other drag'n drops ? Is it possible ? Are there options somewhere ?

Thanks for your help,

Johann

Re: AuthorDnDListener - multiple DropTargetDropEvent managme

Posted: Thu Jun 18, 2015 1:37 pm
by Radu
Hi Johann,

I think that the only official modifiers for DND are Ctrl and Shift. For example if you press Ctrl+Shift and drag you should receive on the getDropAction() a java.awt.dnd.DnDConstants.ACTION_LINK value.

So the Swing drop event does not seem to be able to tell you if the ALT key is pressed when the drag is done.

Possibly you could add a static listener (a static block in your class) which listens for all key events in the application:

Code: Select all

		Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent ev) {
if (ev.getClass() == KeyEvent.class) {
............
and if the last key event has the ALT DOWN modifier consider that the drag and drop is done using that.

Regards,
Radu

Re: AuthorDnDListener - multiple DropTargetDropEvent managme

Posted: Thu Jun 18, 2015 5:03 pm
by Johann
Hi Radu,

You were right about the official modifiers. These are CTRL and SHIFT.

I was able to detect only CTRL because my swing source forced SourceActions at COPY_OR_MOVE.
I put COPY | MOVE | LINK instead. Now I'm able to detect CTRL+SHIFT when the drag is done which suits me perfectly. The ALT key was not mandatory.

Thanks for your response,

Johann