mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 21:35:44 +08:00
GT-2383 - tree focus, code review tweaks
This commit is contained in:
+11
-2
@@ -1,6 +1,5 @@
|
|||||||
/* ###
|
/* ###
|
||||||
* IP: GHIDRA
|
* IP: GHIDRA
|
||||||
* REVIEWED: YES
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,7 +25,7 @@ import javax.swing.tree.TreeSelectionModel;
|
|||||||
|
|
||||||
public class JTreeMouseListenerDelegate extends MouseAdapter {
|
public class JTreeMouseListenerDelegate extends MouseAdapter {
|
||||||
|
|
||||||
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<MouseListener>();
|
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<>();
|
||||||
private final JTree tree;
|
private final JTree tree;
|
||||||
|
|
||||||
private boolean consumedPressed;
|
private boolean consumedPressed;
|
||||||
@@ -87,6 +86,10 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
|
|||||||
if (isPotentialDragSelection(e)) {
|
if (isPotentialDragSelection(e)) {
|
||||||
e.consume();
|
e.consume();
|
||||||
consumedPressed = true;
|
consumedPressed = true;
|
||||||
|
|
||||||
|
// ensure the tree has focus in this case, since we consumed the event, which can
|
||||||
|
// prevent the normal focus updating done by Swing
|
||||||
|
fixFocus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
consumedPressed = false;
|
consumedPressed = false;
|
||||||
@@ -94,6 +97,12 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
|
|||||||
fireMousePressed(e);
|
fireMousePressed(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fixFocus() {
|
||||||
|
if (!tree.hasFocus()) {
|
||||||
|
tree.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
handlePopupTrigger(e);
|
handlePopupTrigger(e);
|
||||||
|
|||||||
@@ -1324,10 +1324,6 @@ public class GTree extends JPanel implements BusyListener {
|
|||||||
protected void setSelectedPathNow(TreePath path) {
|
protected void setSelectedPathNow(TreePath path) {
|
||||||
GTreeSelectionModel selectionModel = (GTreeSelectionModel) gTree.getSelectionModel();
|
GTreeSelectionModel selectionModel = (GTreeSelectionModel) gTree.getSelectionModel();
|
||||||
selectionModel.setSelectionPaths(new TreePath[] { path }, USER_GENERATED);
|
selectionModel.setSelectionPaths(new TreePath[] { path }, USER_GENERATED);
|
||||||
|
|
||||||
// If the user clicked on the same node as was already selected, no events are generated
|
|
||||||
// and the tree might be left unfocused. Force the focus to the tree.
|
|
||||||
gTree.requestFocus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user