IDEA-183801: move focus traversal policy from toolwindow to decorator because its header may contain action buttons

This commit is contained in:
Sergey Malenkov
2018-07-12 21:32:45 +03:00
parent a2573e94a5
commit b013e9ddca
2 changed files with 21 additions and 65 deletions
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.wm.impl;
import com.intellij.icons.AllIcons;
@@ -265,6 +263,7 @@ public final class InternalDecorator extends JPanel implements Queryable, DataPr
enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
final JPanel contentPane = new JPanel(new BorderLayout());
installFocusTraversalPolicy(contentPane, new LayoutFocusTraversalPolicy());
contentPane.add(myHeader, BorderLayout.NORTH);
JPanel innerPanel = new JPanel(new BorderLayout());
@@ -903,4 +902,23 @@ public final class InternalDecorator extends JPanel implements Queryable, DataPr
return name;
}
}
/**
* Installs a focus traversal policy for the tool window.
* If the policy cannot handle a keystroke, it delegates the handling to
* the nearest ancestors focus traversal policy. For instance,
* this policy does not handle KeyEvent.VK_ESCAPE, so it can delegate the handling
* to a ThreeComponentSplitter instance.
*/
private static void installFocusTraversalPolicy(@NotNull Container container, @NotNull FocusTraversalPolicy policy) {
container.setFocusCycleRoot(true);
container.setFocusTraversalPolicyProvider(true);
container.setFocusTraversalPolicy(policy);
installDefaultFocusTraversalKeys(container, KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
installDefaultFocusTraversalKeys(container, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
}
private static void installDefaultFocusTraversalKeys(@NotNull Container container, int id) {
container.setFocusTraversalKeys(id, KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalKeys(id));
}
}
@@ -36,13 +36,9 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @author Anton Katilin
@@ -67,18 +63,6 @@ public final class ToolWindowImpl implements ToolWindowEx {
private boolean myPlaceholderMode;
private ToolWindowFactory myContentFactory;
private static final Set<KeyStroke> FORWARD_TRAVERSAL_KEYSTROKES = new HashSet<>(Arrays.asList(
new KeyStroke[]{
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)
}
));
private static final Set<KeyStroke> BACKWARD_TRAVERSAL_KEYSTROKES = new HashSet<>(Arrays.asList(
new KeyStroke[]{
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK)
}
));
private final BusyObject.Impl myShowing = new BusyObject.Impl() {
@Override
public boolean isReady() {
@@ -106,8 +90,6 @@ public final class ToolWindowImpl implements ToolWindowEx {
myComponent = myContentManager.getComponent();
installToolwindowFocusPolicy();
UiNotifyConnector notifyConnector = new UiNotifyConnector(myComponent, new Activatable.Adapter() {
@Override
public void showNotify() {
@@ -117,50 +99,6 @@ public final class ToolWindowImpl implements ToolWindowEx {
Disposer.register(myContentManager, notifyConnector);
}
/**
* Installs a focus traversal policy for the tool window.
* If the policy cannot handle a keystroke, it delegates the handling to
* the nearest ancestors focus traversal policy. For instance,
* this policy does not handle KeyEvent.VK_ESCAPE, so it can delegate the handling
* to a ThreeComponentSplitter instance.
*/
private void installToolwindowFocusPolicy() {
myComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, FORWARD_TRAVERSAL_KEYSTROKES);
myComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYSTROKES);
FocusTraversalPolicy layoutFocusTraversalPolicy = new LayoutFocusTraversalPolicy();
myComponent.setFocusCycleRoot(true);
myComponent.setFocusTraversalPolicyProvider(true);
myComponent.setFocusTraversalPolicy(new FocusTraversalPolicy() {
@Override
public Component getComponentAfter(Container container, Component component) {
return layoutFocusTraversalPolicy.getComponentAfter(container, component);
}
@Override
public Component getComponentBefore(Container container, Component component) {
return layoutFocusTraversalPolicy.getComponentBefore(container, component);
}
@Override
public Component getFirstComponent(Container container) {
return layoutFocusTraversalPolicy.getFirstComponent(container);
}
@Override
public Component getLastComponent(Container container) {
return layoutFocusTraversalPolicy.getLastComponent(container);
}
@Override
public Component getDefaultComponent(Container container) {
return layoutFocusTraversalPolicy.getDefaultComponent(container);
}
});
}
public final void addPropertyChangeListener(final PropertyChangeListener l) {
myChangeSupport.addPropertyChangeListener(l);
}