Search in sources :

Example 1 with FocusRequestInfo

use of com.intellij.openapi.wm.impl.FocusRequestInfo in project intellij-community by JetBrains.

the class FocusTracesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
    if (!(manager instanceof FocusManagerImpl))
        return;
    final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
    myActive = !myActive;
    if (myActive) {
        myFocusTracker = new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
                if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
                    focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
                }
            }
        };
        Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
    }
    if (!myActive) {
        final List<FocusRequestInfo> requests = focusManager.getRequests();
        new FocusTracesDialog(project, new ArrayList<>(requests)).show();
        Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
        myFocusTracker = null;
        requests.clear();
    }
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Project(com.intellij.openapi.project.Project) AWTEventListener(java.awt.event.AWTEventListener) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ArrayList(java.util.ArrayList) FocusEvent(java.awt.event.FocusEvent) FocusRequestInfo(com.intellij.openapi.wm.impl.FocusRequestInfo)

Aggregations

Project (com.intellij.openapi.project.Project)1 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)1 FocusManagerImpl (com.intellij.openapi.wm.impl.FocusManagerImpl)1 FocusRequestInfo (com.intellij.openapi.wm.impl.FocusRequestInfo)1 AWTEventListener (java.awt.event.AWTEventListener)1 FocusEvent (java.awt.event.FocusEvent)1 ArrayList (java.util.ArrayList)1