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 no component is clicked, do nothing
if (clicked.length == 0) { if (clicked.length == 0) {
selectionModel.setSelectionPath(null); selectionModel.setSelectionPath(null);
ComponentConfigDialog.disposeDialog();
return; return;
} }
@ -655,13 +656,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
if (clicked == null || clicked.length == 0) { if (clicked == null || clicked.length == 0) {
selectionModel.setSelectionPaths(null); selectionModel.setSelectionPaths(null);
ComponentConfigDialog.disposeDialog();
return; return;
} }
// Check for double-click. // 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 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 (clickCount == 2) {
if (event.isShiftDown() || event.isMetaDown()) { if (!selectedComponents.isEmpty() && (event.isShiftDown() || event.isMetaDown())) {
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
RocketComponent component = selectedComponents.get(selectedComponents.size() - 1); RocketComponent component = selectedComponents.get(selectedComponents.size() - 1);
component.clearConfigListeners(); component.clearConfigListeners();
@ -673,7 +675,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
paths.add(path); paths.add(path);
selectionModel.setSelectionPaths(paths.toArray(new TreePath[0])); selectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) selectedComponents = Arrays.stream(selectionModel.getSelectionPaths())
.map(c1 -> (RocketComponent) c1.getLastPathComponent()).collect(Collectors.toList()); .map(c1 -> (RocketComponent) c1.getLastPathComponent()).toList();
component = c; component = c;
break; break;
} }
@ -703,27 +705,34 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
} }
} }
// If the shift-button is held, add a newly clicked component to the selection path
if (clickCount == 1 && (event.isShiftDown() || event.isMetaDown())) { if (clickCount == 1) {
List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); // If the shift-button is held, add a newly clicked component to the selection path
for (int i = 0; i < clicked.length; i++) { if (event.isShiftDown() || event.isMetaDown()) {
if (!selectedComponents.contains(clicked[i])) { List<TreePath> paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths()));
TreePath path = ComponentTreeModel.makeTreePath(clicked[i]); for (int i = 0; i < clicked.length; i++) {
paths.add(path); if (!selectedComponents.contains(clicked[i])) {
break; TreePath path = ComponentTreeModel.makeTreePath(clicked[i]);
paths.add(path);
break;
}
// If all the clicked components are already in the selection, then deselect an object
if (i == clicked.length - 1) {
paths.removeIf(path -> path.getLastPathComponent() == clicked[0]);
}
} }
// If all the clicked components are already in the selection, then deselect an object try {
if (i == clicked.length - 1) { selectionModel.setSelectionPaths(paths.toArray(new TreePath[0]));
paths.removeIf(path -> path.getLastPathComponent() == clicked[0]); } catch (Exception e) {
System.out.println(e);
} }
} }
selectionModel.setSelectionPaths(paths.toArray(new TreePath[0])); // Single click, so set the selection to the first clicked component
} else {
// Single click, so set the selection to the first clicked component if (!selectedComponents.contains(clicked[0])) {
else { TreePath path = ComponentTreeModel.makeTreePath(clicked[0]);
if (!selectedComponents.contains(clicked[0])) { selectionModel.setSelectionPath(path);
TreePath path = ComponentTreeModel.makeTreePath(clicked[0]); }
selectionModel.setSelectionPath(path);
} }
} }
} }
@ -1102,9 +1111,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
@Override @Override
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
TreePath[] paths = selectionModel.getSelectionPaths(); TreePath[] paths = selectionModel.getSelectionPaths();
if (paths == null) { if (paths == null || paths.length == 0) {
figure.setSelection(null); figure.setSelection(null);
figure3d.setSelection(null); figure3d.setSelection(null);
ComponentConfigDialog.disposeDialog();
return; return;
} }