GT-2383 - tree focus, code review tweaks

This commit is contained in:
dev747368
2019-08-06 16:55:21 -04:00
parent 8461e91758
commit bcba73fdce
2 changed files with 11 additions and 6 deletions
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (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 {
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<MouseListener>();
private final Set<MouseListener> listeners = new CopyOnWriteArraySet<>();
private final JTree tree;
private boolean consumedPressed;
@@ -87,6 +86,10 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
if (isPotentialDragSelection(e)) {
e.consume();
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 {
consumedPressed = false;
@@ -94,6 +97,12 @@ public class JTreeMouseListenerDelegate extends MouseAdapter {
fireMousePressed(e);
}
private void fixFocus() {
if (!tree.hasFocus()) {
tree.requestFocus();
}
}
@Override
public void mouseClicked(MouseEvent e) {
handlePopupTrigger(e);
@@ -1324,10 +1324,6 @@ public class GTree extends JPanel implements BusyListener {
protected void setSelectedPathNow(TreePath path) {
GTreeSelectionModel selectionModel = (GTreeSelectionModel) gTree.getSelectionModel();
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();
}
}