From 34b2a0a2213bb527bfa7be5d108da97054d450d8 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 1 Jun 2022 22:09:03 +0200 Subject: [PATCH] Add click action for right-click --- .../sf/openrocket/gui/main/BasicFrame.java | 7 +++ .../MotorConfigurationPanel.java | 16 ++++++ .../RecoveryConfigurationPanel.java | 16 ++++++ .../SeparationConfigurationPanel.java | 16 ++++++ .../gui/scalefigure/RocketPanel.java | 53 ++++++++++++------- 5 files changed, 89 insertions(+), 19 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index f5b09c622..880713cfa 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -304,8 +304,15 @@ public class BasicFrame extends JFrame { ComponentConfigDialog.showDialog(BasicFrame.this, BasicFrame.this.document, c); } else if ((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) { + if (!tree.isPathSelected(selPath)) { + // Select new path + tree.setSelectionPath(selPath); + } + doComponentTreePopup(e); } + } else { + tree.clearSelection(); } } }; diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 9d7a798ad..6050f84f6 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -222,6 +222,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel selectMotor(); } } else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) { + // Get the row and column of the selected cell + int r = configurationTable.rowAtPoint(e.getPoint()); + int c = configurationTable.columnAtPoint(e.getPoint()); + + // Select new cell + if (!configurationTable.isCellSelected(r, c)) { + if (r >= 0 && r < configurationTable.getRowCount() && + c >= 0 && c < configurationTable.getColumnCount()) { + configurationTable.setRowSelectionInterval(r, r); + configurationTable.setColumnSelectionInterval(c, c); + } else { + configurationTable.clearSelection(); + return; + } + } + if (selectedColumn > 0) { doPopupFull(e); } else { diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java index 6f355e340..bcd37bba9 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -120,6 +120,22 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel= 0 && r < recoveryTable.getRowCount() && + c >= 0 && c < recoveryTable.getColumnCount()) { + recoveryTable.setRowSelectionInterval(r, r); + recoveryTable.setColumnSelectionInterval(c, c); + } else { + recoveryTable.clearSelection(); + return; + } + } + if (selectedColumn > 0) { doPopupFull(e); } else { diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java index ba9a96281..de4c05831 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java @@ -140,6 +140,22 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel= 0 && r < separationTable.getRowCount() && + c >= 0 && c < separationTable.getColumnCount()) { + separationTable.setRowSelectionInterval(r, r); + separationTable.setColumnSelectionInterval(c, c); + } else { + separationTable.clearSelection(); + return; + } + } + if (selectedColumn > 0) { doPopupFull(e); } else { diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index f3250aa7b..01f57a6a4 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -554,33 +554,48 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change public static final int CYCLE_SELECTION_MODIFIER = InputEvent.SHIFT_DOWN_MASK; private void handleMouseClick(MouseEvent event) { - if (event.getButton() == MouseEvent.BUTTON1) { - // Get the component that is clicked on - Point p0 = event.getPoint(); - Point p1 = scrollPane.getViewport().getViewPosition(); - int x = p0.x + p1.x; - int y = p0.y + p1.y; + // Get the component that is clicked on + Point p0 = event.getPoint(); + Point p1 = scrollPane.getViewport().getViewPosition(); + int x = p0.x + p1.x; + int y = p0.y + p1.y; - RocketComponent[] clicked = figure.getComponentsByPoint(x, y); + RocketComponent[] clicked = figure.getComponentsByPoint(x, y); - handleComponentClick(clicked, event); - } else if (event.getButton() == MouseEvent.BUTTON3) { - List selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) - .map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); - - if (selectedComponents.size() == 0) return; - - basicFrame.doComponentTreePopup(event); - } - } - - private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) { // If no component is clicked, do nothing if (clicked.length == 0) { selectionModel.setSelectionPath(null); return; } + if (event.getButton() == MouseEvent.BUTTON1) { + handleComponentClick(clicked, event); + } else if (event.getButton() == MouseEvent.BUTTON3) { + List selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) + .map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList()); + + boolean newClick = true; + for (RocketComponent component : clicked) { + if (selectedComponents.contains(component)) { + newClick = false; + break; + } + } + + if (newClick) { + for (RocketComponent rocketComponent : clicked) { + if (!selectedComponents.contains(rocketComponent)) { + TreePath path = ComponentTreeModel.makeTreePath(rocketComponent); + selectionModel.setSelectionPath(path); + } + } + } + + basicFrame.doComponentTreePopup(event); + } + } + + private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) { List selectedComponents = Arrays.stream(selectionModel.getSelectionPaths()) .map(c -> (RocketComponent) c.getLastPathComponent()).collect(Collectors.toList());