mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-4466 consolidated focus handling between ComponentProvider and DockableComponent
This commit is contained in:
parent
c131adc670
commit
495dc4df66
8 changed files with 41 additions and 84 deletions
|
@ -20,7 +20,6 @@ import java.awt.dnd.*;
|
|||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.FocusManager;
|
||||
|
||||
import docking.action.DockingActionIf;
|
||||
import ghidra.util.CascadedDropTarget;
|
||||
|
@ -46,7 +45,7 @@ public class DockableComponent extends JPanel implements ContainerListener {
|
|||
private MouseListener popupListener;
|
||||
private ComponentPlaceholder placeholder;
|
||||
private JComponent providerComp;
|
||||
private Component focusedComponent;
|
||||
private Component lastFocusedComponent;
|
||||
private DockingWindowManager winMgr;
|
||||
private ActionToGuiMapper actionMgr;
|
||||
private DropTarget dockableDropTarget;
|
||||
|
@ -142,10 +141,6 @@ public class DockableComponent extends JPanel implements ContainerListener {
|
|||
return helpLocation;
|
||||
}
|
||||
|
||||
public Component getFocusedComponent() {
|
||||
return focusedComponent;
|
||||
}
|
||||
|
||||
void showContextMenu(PopupMenuContext popupContext) {
|
||||
actionMgr.showPopupMenu(placeholder, popupContext);
|
||||
}
|
||||
|
@ -448,15 +443,16 @@ public class DockableComponent extends JPanel implements ContainerListener {
|
|||
@Override
|
||||
// we aren't focusable, so pass focus to a valid child component
|
||||
public void requestFocus() {
|
||||
focusedComponent = findFocusedComponent();
|
||||
if (focusedComponent != null) {
|
||||
DockingWindowManager.requestFocus(focusedComponent);
|
||||
if (lastFocusedComponent != null && lastFocusedComponent.isShowing()) {
|
||||
lastFocusedComponent.requestFocus();
|
||||
return;
|
||||
}
|
||||
placeholder.getProvider().requestFocus();
|
||||
}
|
||||
|
||||
void setFocusedComponent(Component newFocusedComponet) {
|
||||
// remember it so we can restore it later when necessary
|
||||
focusedComponent = newFocusedComponet;
|
||||
lastFocusedComponent = newFocusedComponet;
|
||||
}
|
||||
|
||||
private void componentSelected(Component component) {
|
||||
|
@ -467,22 +463,6 @@ public class DockableComponent extends JPanel implements ContainerListener {
|
|||
}
|
||||
}
|
||||
|
||||
// find the first available component that can take focus
|
||||
private Component findFocusedComponent() {
|
||||
if (focusedComponent != null && focusedComponent.isShowing()) {
|
||||
return focusedComponent;
|
||||
}
|
||||
|
||||
DefaultFocusManager dfm = (DefaultFocusManager) FocusManager.getCurrentManager();
|
||||
Component component = dfm.getComponentAfter(this, this);
|
||||
|
||||
// component must be a child of this DockableComponent
|
||||
if (component != null && SwingUtilities.isDescendingFrom(component, this)) {
|
||||
return component;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentAdded(ContainerEvent e) {
|
||||
initializeComponents(e.getChild());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue