AuthorDnDListener - multiple DropTargetDropEvent managment

Post here questions and problems related to oXygen frameworks/document types.
Johann
Posts: 198
Joined: Wed Jun 17, 2015 12:46 pm

AuthorDnDListener - multiple DropTargetDropEvent managment

Post 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
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: AuthorDnDListener - multiple DropTargetDropEvent managme

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Johann
Posts: 198
Joined: Wed Jun 17, 2015 12:46 pm

Re: AuthorDnDListener - multiple DropTargetDropEvent managme

Post 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
Post Reply