java - Debugging UI and pause when a key is pressed -


i'm no debugging expert , lately came across problem has easy solution. when test , debug mathematica plugin idea, write code, build , run in sandbox idea.

for not familiar writing plugins idea: main problem is, ui code there because comes idea. plugin implements specific interfaces required make idea understand mathematica language. therefore, setting breakpoint or throwing in onclicklistener suggested @jeroen not possible, because virtually haven't written single line of ui code*.

now had situation works fine, when cancel specific action, weird happens. have no idea specific method (it none of mine!) called @ moment when press esc cancel action. current point deep inside sources of idea have , can navigate debugger!.

question: easiest way in java make debugger break, wherever might when press esc in ui-program debug?

*this not entirely true, sake of general solution think of way.

as discussed in this question, can create own subclass of eventqueue inspects events, , create place in code can set break point , catch kinds of events. might 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 hit breakpoint, can step super.postevent() call , see goes, component(s) receive it, , when begin interact part of code. forewarned may long slog, though -- awt/swing event dispatching can pretty complex.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -