How with minimum code uglification can I write a debugging hook in a Swing program that would tell me which component in the hierarchy is actually handling each KeyStroke or mouse click and performing the action mapped to it in the component's action map? We are writing a complicated GUI and it would be very useful to know this information.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Put in a custom event dispatcher: http://tips4java.wordpress.com/2009/09/06/global-event-dispatching/
Also look up AWTEvent.getID(), MouseEvent, KeyEvent in the API docs.
This is how the software I work on monitors mouse and keyboard to see if the user is busy working, and locks the window if they're not.
Using AspectJ to weave a logging aspect into your code base can be done. Below is an example of advice on a joinpoint within execution of any objects with the method
actionPerformed(ActionEvent)
you have in your code base. Similar constructions can be used to advise other Listeners.Below is the aspect to advise button presses and other components having ActionListeners. It simply outputs the class name of the source of the action and the signature of the actionPerformed method.
A test class which produces two buttons of different classes (in file StackTraceExample.java):