From 7ee5a17af994d159781327266982193bcf172cb6 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 27 Jun 2022 22:35:09 +0200 Subject: [PATCH 1/3] [#1490] Select recovery device/stage after config panel select --- .../RecoveryConfigurationPanel.java | 37 ++++++++++++++++++ .../SeparationConfigurationPanel.java | 38 +++++++++++++++++++ 2 files changed, 75 insertions(+) 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 fb174692a..4e45d9a29 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -1,9 +1,12 @@ package net.sf.openrocket.gui.main.flightconfigpanel; import java.awt.event.ActionEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; import java.util.List; import javax.swing.AbstractAction; @@ -162,6 +165,30 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel devices = getSelectedComponents(); List fcIds = getSelectedConfigurationIds(); @@ -239,6 +266,16 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel components = new ArrayList<>(getSelectedComponents()); + if (components.size() == 0) return; + + flightConfigurationPanel.setSelectedComponents(components); + } + public void updateButtonState() { boolean componentSelected = getSelectedComponent() != null; selectDeploymentButton.setEnabled(componentSelected); 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 6ae182dcd..1c3854b45 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java @@ -1,9 +1,12 @@ package net.sf.openrocket.gui.main.flightconfigpanel; import java.awt.event.ActionEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; import java.util.List; import javax.swing.AbstractAction; @@ -27,6 +30,7 @@ import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent; import net.sf.openrocket.startup.Application; @@ -170,6 +174,30 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel stages = getSelectedComponents(); List fcIds = getSelectedConfigurationIds(); @@ -248,6 +276,16 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel components = new ArrayList<>(getSelectedComponents()); + if (components.size() == 0) return; + + flightConfigurationPanel.setSelectedComponents(components); + } + public void updateButtonState() { boolean componentSelected = getSelectedComponent() != null; selectSeparationButton.setEnabled(componentSelected); From d82058417a80b3c895ea90e7953e1f3e33114772 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 27 Jun 2022 22:55:11 +0200 Subject: [PATCH 2/3] Fix multi-select for stages --- .../sf/openrocket/gui/main/BasicFrame.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index f83ef3fb4..b5304eba3 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -19,6 +19,7 @@ import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.concurrent.ExecutionException; @@ -300,23 +301,28 @@ public class BasicFrame extends JFrame { componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { - TreePath selPath = e.getNewLeadSelectionPath(); - if (selPath == null) return; - RocketComponent c = (RocketComponent) selPath.getLastPathComponent(); + if (tree == null || tree.getSelectionPaths() == null || tree.getSelectionPaths().length == 0 + || rocketpanel == null) return; - if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) { - if (rocketpanel == null) return; - - List children = new LinkedList<>(); - for (RocketComponent child : c) { - children.add(child); + // Get all the components that need to be selected = currently selected components + children of stages/boosters/podsets + List children = new ArrayList<>(Arrays.asList(rocketpanel.getFigure().getSelection())); + for (TreePath p : tree.getSelectionPaths()) { + if (p != null) { + RocketComponent c = (RocketComponent) p.getLastPathComponent(); + if (c instanceof AxialStage || c instanceof Rocket || c instanceof PodSet) { + Iterator iter = c.iterator(false); + while (iter.hasNext()) { + RocketComponent child = iter.next(); + children.add(child); + } + } } + } - // Select all the child components - if (rocketpanel.getFigure() != null && rocketpanel.getFigure3d() != null) { - rocketpanel.getFigure().setSelection(children.toArray(new RocketComponent[0])); - rocketpanel.getFigure3d().setSelection(children.toArray(new RocketComponent[0])); - } + // Select all the child components + if (rocketpanel.getFigure() != null && rocketpanel.getFigure3d() != null) { + rocketpanel.getFigure().setSelection(children.toArray(new RocketComponent[0])); + rocketpanel.getFigure3d().setSelection(children.toArray(new RocketComponent[0])); } } }); From 186772fe3bbe76d85e25fb647c77da46a39cdec1 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 28 Jun 2022 01:00:56 +0200 Subject: [PATCH 3/3] Fix NullPointerExceptions --- .../gui/main/flightconfigpanel/RecoveryConfigurationPanel.java | 2 +- .../main/flightconfigpanel/SeparationConfigurationPanel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 4e45d9a29..11c991e1f 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/RecoveryConfigurationPanel.java @@ -267,7 +267,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel components = new ArrayList<>(getSelectedComponents()); 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 1c3854b45..ccf27e1d1 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/SeparationConfigurationPanel.java @@ -277,7 +277,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel components = new ArrayList<>(getSelectedComponents());