User Interface Debugging and Pause Key Press

I'm really not a debugging expert, and lately I have run into a problem which hopefully has a simple solution. When I test and debug the Mathematica plugin for IDEA , I write code, create it, and run it in the IDEA sandbox.

For those who are not familiar with writing plugins for IDEA: The main problem is that all the user interface code already exists, because it comes with IDEA. My plugin implements only certain interfaces necessary for IDEA to understand Mathematica. Therefore, setting a breakpoint or throwing something in onClickListener , as suggested by @Jeroen, is impossible, because I practically did not write a single line of user interface code *.

Now I had a situation that everything works fine, but when I cancel a specific action, something strange happens. I do not know which specific method (this is not mine!) Is called at the moment when I press Esc to cancel this action. The current point is very likely deep inside the IDEA sources that I have and that I can move with the debugger!

Question:. What is the easiest way in Java to make the debugger break, wherever it is, when I press Esc in the user program that I am currently debugging?

* This is not entirely true, but for a general solution, I would like to think about it this way.

+6
source share
2 answers

As discussed in this question , you can create your own subclass of EventQueue , which checks events and creates a place in the code where you can set a breakpoint and only catch certain types of events. It might look something like this:

  EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); eventQueue.push(new EventQueue(){ public void postEvent(AWTEvent theEvent) { if(theEvent instanceof KeyEvent){ KeyEvent kEvent = (KeyEvent)theEvent; if(kEvent.getKeyCode() == KeyEvent.VK_ESCAPE){ System.out.println("escape pressed, set breakpoint here"); } } super.postEvent(theEvent); } }); 

Then, when you hit this breakpoint, you can go into the super.postEvent() call and see where it goes, which component will receive it, and when they start interacting with some part of your code. Be warned that this may be a long show, though - the AWT / Swing event dispatcher can become quite complex.

+3
source

If you work in Netbeans (or you can port), you can use a visual debugger that is specifically designed for these GUI problems. It can direct you to a specific source code when you interact with a GUI element so that it can tell you the secret code that runs when you press escape. I believe other IDEs have similar features, but Netbeans is the only one I know from my head.

+1
source

All Articles