Search in sources :

Example 1 with FocusWatcher

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

the class WindowWatcher method getFocusedComponent.

public final Component getFocusedComponent(@NotNull final Window window) {
    synchronized (myLock) {
        final WindowInfo info = myWindow2Info.get(window);
        if (info == null) {
            // TODO[vova,anton] usage of getMostRecentFocusOwner is experimental. But it seems suitable here.
            return window.getMostRecentFocusOwner();
        }
        final FocusWatcher focusWatcher = info.myFocusWatcherRef.get();
        if (focusWatcher != null) {
            final Component focusedComponent = focusWatcher.getFocusedComponent();
            if (focusedComponent != null && focusedComponent.isShowing()) {
                return focusedComponent;
            } else {
                return null;
            }
        } else {
            // info isn't valid, i.e. window was garbage collected, so we need the remove invalid info
            // and return null
            myWindow2Info.remove(window);
            return null;
        }
    }
}
Also used : FocusWatcher(com.intellij.openapi.wm.FocusWatcher)

Example 2 with FocusWatcher

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

the class WindowWatcher method dispatchHiddenOrClosed.

private void dispatchHiddenOrClosed(final Window window) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("enter: dispatchClosed(" + window + ")");
    }
    synchronized (myLock) {
        final WindowInfo info = myWindow2Info.get(window);
        if (info != null) {
            final FocusWatcher focusWatcher = info.myFocusWatcherRef.get();
            if (focusWatcher != null) {
                focusWatcher.deinstall(window);
            }
            myWindow2Info.remove(window);
        }
    }
    // window is being closed.
    if (myFocusedWindow == window) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("currently active window should be closed");
        }
        myFocusedWindow = myFocusedWindow.getOwner();
        if (LOG.isDebugEnabled()) {
            LOG.debug("new active window is " + myFocusedWindow);
        }
    }
    for (Iterator i = myFocusedWindows.iterator(); i.hasNext(); ) {
        final Window activeWindow = (Window) i.next();
        if (activeWindow == window) {
            final Window newActiveWindow = activeWindow.getOwner();
            i.remove();
            if (newActiveWindow != null) {
                myFocusedWindows.add(newActiveWindow);
            }
            break;
        }
    }
    // Remove invalid infos for garbage collected windows
    for (Iterator i = myWindow2Info.values().iterator(); i.hasNext(); ) {
        final WindowInfo info = (WindowInfo) i.next();
        if (info.myFocusWatcherRef.get() == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("remove collected info");
            }
            i.remove();
        }
    }
}
Also used : FocusWatcher(com.intellij.openapi.wm.FocusWatcher) Iterator(java.util.Iterator)

Example 3 with FocusWatcher

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

the class RequestFocusInToolWindowCmd method updateFocusedComponentForWatcher.

private static void updateFocusedComponentForWatcher(final Component c) {
    final WindowWatcher watcher = ((WindowManagerImpl) WindowManager.getInstance()).getWindowWatcher();
    final FocusWatcher focusWatcher = watcher.getFocusWatcherFor(c);
    if (focusWatcher != null && c.isFocusOwner()) {
        focusWatcher.setFocusedComponentImpl(c);
    }
}
Also used : FocusWatcher(com.intellij.openapi.wm.FocusWatcher) WindowManagerImpl(com.intellij.openapi.wm.impl.WindowManagerImpl) WindowWatcher(com.intellij.openapi.wm.impl.WindowWatcher)

Aggregations

FocusWatcher (com.intellij.openapi.wm.FocusWatcher)3 WindowManagerImpl (com.intellij.openapi.wm.impl.WindowManagerImpl)1 WindowWatcher (com.intellij.openapi.wm.impl.WindowWatcher)1 Iterator (java.util.Iterator)1