From 5cc793fc9d6082f0da5adedf663888db7434547c Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 27 Jun 2022 02:05:14 +0200 Subject: [PATCH] [#1489] Visually select child components of selected rocket/stage/podset --- .../sf/openrocket/gui/main/BasicFrame.java | 24 +++++++++++++++++++ .../gui/scalefigure/RocketPanel.java | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java index d99ba0fea..758936890 100644 --- a/swing/src/net/sf/openrocket/gui/main/BasicFrame.java +++ b/swing/src/net/sf/openrocket/gui/main/BasicFrame.java @@ -74,6 +74,7 @@ import net.sf.openrocket.logging.Markers; import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.ComponentChangeListener; +import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; @@ -294,7 +295,30 @@ public class BasicFrame extends JFrame { im.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_KEY), null); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, SHORTCUT_KEY), null); + // Visually select all child components of a stage/rocket/podset when it is selected + componentSelectionModel.addTreeSelectionListener(new TreeSelectionListener() { + @Override + public void valueChanged(TreeSelectionEvent e) { + TreePath selPath = e.getNewLeadSelectionPath(); + if (selPath == null) return; + RocketComponent c = (RocketComponent) selPath.getLastPathComponent(); + 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); + } + + // 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])); + } + } + } + }); // Double-click opens config dialog MouseListener ml = new MouseAdapter() { diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index c7b48bc35..92df95906 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -421,6 +421,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change return figure; } + public RocketFigure3d getFigure3d() { + return figure3d; + } + public AerodynamicCalculator getAerodynamicCalculator() { return aerodynamicCalculator; }