Merge pull request #1499 from SiboVG/issue-1490

[#1490] Select recovery device/stage after config panel select
This commit is contained in:
SiboVG 2022-07-05 01:06:06 +02:00 committed by GitHub
commit 3444a968f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 14 deletions

View File

@ -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<RocketComponent> 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<RocketComponent> 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<RocketComponent> 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]));
}
}
});

View File

@ -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<Recovery
return recoveryTable;
}
@Override
protected void installTableListener() {
super.installTableListener();
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateComponentSelection(e);
}
});
table.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateComponentSelection(new ListSelectionEvent(this, 0, 0, false));
}
@Override
public void focusLost(FocusEvent e) {
}
});
}
public void selectDeployment() {
List<RecoveryDevice> devices = getSelectedComponents();
List<FlightConfigurationId> fcIds = getSelectedConfigurationIds();
@ -239,6 +266,16 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
}
public void updateComponentSelection(ListSelectionEvent e) {
if (e.getValueIsAdjusting() || getSelectedComponents() == null) {
return;
}
List<RocketComponent> components = new ArrayList<>(getSelectedComponents());
if (components.size() == 0) return;
flightConfigurationPanel.setSelectedComponents(components);
}
public void updateButtonState() {
boolean componentSelected = getSelectedComponent() != null;
selectDeploymentButton.setEnabled(componentSelected);

View File

@ -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<AxialS
return separationTable;
}
@Override
protected void installTableListener() {
super.installTableListener();
table.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateComponentSelection(e);
}
});
table.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateComponentSelection(new ListSelectionEvent(this, 0, 0, false));
}
@Override
public void focusLost(FocusEvent e) {
}
});
}
public void selectSeparation() {
List<AxialStage> stages = getSelectedComponents();
List<FlightConfigurationId> fcIds = getSelectedConfigurationIds();
@ -248,6 +276,16 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
popupMenuFull.show(e.getComponent(), e.getX(), e.getY());
}
public void updateComponentSelection(ListSelectionEvent e) {
if (e.getValueIsAdjusting() || getSelectedComponents() == null) {
return;
}
List<RocketComponent> components = new ArrayList<>(getSelectedComponents());
if (components.size() == 0) return;
flightConfigurationPanel.setSelectedComponents(components);
}
public void updateButtonState() {
boolean componentSelected = getSelectedComponent() != null;
selectSeparationButton.setEnabled(componentSelected);