Merge pull request #2506 from SiboVG/issue-2500

[#2500] Fix issues with double-clicking
This commit is contained in:
Joe Pfeiffer 2024-07-11 15:48:38 -06:00 committed by GitHub
commit 22faae42ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -619,6 +619,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
// If no component is clicked, do nothing
if (clicked.length == 0) {
selectionModel.setSelectionPath(null);
ComponentConfigDialog.disposeDialog();
return;
}
@ -655,13 +656,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
if (clicked == null || clicked.length == 0) {
selectionModel.setSelectionPaths(null);
ComponentConfigDialog.disposeDialog();
return;
}
// Check for double-click.
// If the shift/meta key is not pressed and the component was not already selected, ignore the double click and treat it as a single click
if (clickCount == 2) {
if (event.isShiftDown() || event.isMetaDown()) {
if (!selectedComponents.isEmpty() && (event.isShiftDown() || event.isMetaDown())) {
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
RocketComponent component = selectedComponents.get(selectedComponents.size() - 1);
component.clearConfigListeners();
@ -673,7 +675,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
paths.add(path);
selectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
.map(c1 -> (RocketComponent) c1.getLastPathComponent()).collect(Collectors.toList());
.map(c1 -> (RocketComponent) c1.getLastPathComponent()).toList();
component = c;
break;
}
@ -703,8 +705,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
}
}
if (clickCount == 1) {
// If the shift-button is held, add a newly clicked component to the selection path
if (clickCount == 1 && (event.isShiftDown() || event.isMetaDown())) {
if (event.isShiftDown() || event.isMetaDown()) {
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
for (int i = 0; i < clicked.length; i++) {
if (!selectedComponents.contains(clicked[i])) {
@ -717,7 +721,11 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
paths.removeIf(path -> path.getLastPathComponent() == clicked[0]);
}
}
try {
selectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
} catch (Exception e) {
System.out.println(e);
}
}
// Single click, so set the selection to the first clicked component
else {
@ -727,6 +735,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
}
}
}
}
/**
* Updates the extra data included in the figure. Currently this includes
@ -1102,9 +1111,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath[] paths = selectionModel.getSelectionPaths();
if (paths == null) {
if (paths == null || paths.length == 0) {
figure.setSelection(null);
figure3d.setSelection(null);
ComponentConfigDialog.disposeDialog();
return;
}