where is the handler for middle button pasting under X?

Hi!

I am new to java, and I would like to have a tip as how to search an answer to my question. I'm trying to fix a bug in a program, and I need to intercept the pasting from middle button mouse to verify if it can be done (only certain parts of the document should accept new text). Keyboard and other mouse actions are handled by overriding processKeyEvent and implementing MouseListener.

I've tried to consume() mouse events with the middle button but the text is pasted the same, so I think there is another listener registered for this event, but where is it? How do I search for it?

Tiago.

[622 byte] By [tifosacaa] at [2007-11-27 8:44:18]
# 1

I'm not sure, but because middle button pasting seems to work for every X app, I can imagine that the middle button pasting in X is implemented by sending keyboard events to the application. So then the application will never be able to make a difference between typed and pasted characters. The app will never receive the middle click event because X substitudes it for the key events.

But I'm not sure.

tom_jansena at 2007-7-12 20:45:02 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks for the reply!

Unfortunately it's not the case, as keyboard events are already monitored and handled. The application receives the middle button event, and I can take actions when the middle button is pressed, but even if I consume this event the text is pasted where the click was done. So there is another handler for the middle mouse button event, but where?

tifosacaa at 2007-7-12 20:45:02 > top of Java-index,Java Essentials,New To Java...
# 3

Of course, it was easy. The default handler for JEditorPane calls the replaceSelection. I just override this method and I can handle the pasting to my liking.

I found this answer at:

http://www.kbs.twi.tudelft.nl/Documentation/Programming/Java/jdk1.4/guide/swing/1.4/dnd.html

But this does not answer the more general question: how am I supposed to find what is the handler responsible for this event? And it raises another one: is there a way to extend the default handler, i.e., BasicTransferHandler?

tifosacaa at 2007-7-12 20:45:02 > top of Java-index,Java Essentials,New To Java...