From e547c7c3e829b130db559b93513fee9aff0ce8b5 Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Sun, 13 Jun 2021 20:45:31 -0700 Subject: [PATCH] Restore 15.03 selection behavior for flight config Restore the behavior from the 15.03 version of the flight configuration panel. Selected flight configuration is synchronized with the rocket panel where the design is being done and vice versa. Fixes #916 Signed-off-by: Billy Olsen --- .../gui/components/ConfigurationComboBox.java | 42 ++++++----- .../FlightConfigurablePanel.java | 69 ++++++++++++++----- .../FlightConfigurationPanel.java | 19 +++-- 3 files changed, 89 insertions(+), 41 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/components/ConfigurationComboBox.java b/swing/src/net/sf/openrocket/gui/components/ConfigurationComboBox.java index 16eed7a4c..4785570c2 100644 --- a/swing/src/net/sf/openrocket/gui/components/ConfigurationComboBox.java +++ b/swing/src/net/sf/openrocket/gui/components/ConfigurationComboBox.java @@ -1,14 +1,17 @@ package net.sf.openrocket.gui.components; +import java.util.EventObject; + import javax.swing.JComboBox; import javax.swing.MutableComboBoxModel; -import javax.swing.event.PopupMenuEvent; import javax.swing.event.ListDataListener; +import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; -import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.util.StateChangeListener; // combobox for flight configurations // this is insane -- it appears the only way to reconstruct a @@ -17,7 +20,7 @@ import net.sf.openrocket.rocketcomponent.FlightConfigurationId; // to the combobox or to its model) is to reconstruct the model. This // is done quickly enough I might as well just do it every time the // combobox is opened, rather than trying to watch and see if it's needed. -public class ConfigurationComboBox extends JComboBox { +public class ConfigurationComboBox extends JComboBox implements StateChangeListener { public class ConfigurationModel implements MutableComboBoxModel { private final Rocket rkt; @@ -77,20 +80,25 @@ public class ConfigurationComboBox extends JComboBox { private final Rocket rkt; public ConfigurationComboBox(Rocket _rkt) { - rkt = _rkt; - setModel(new ConfigurationModel(rkt)); - - addPopupMenuListener(new PopupMenuListener() - { - public void popupMenuCanceled(PopupMenuEvent e) {} - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} - - public void popupMenuWillBecomeVisible(PopupMenuEvent e) - { - setModel(new ConfigurationModel(rkt)); - } - - }); + rkt = _rkt; + setModel(new ConfigurationModel(rkt)); + rkt.addChangeListener(this); + + addPopupMenuListener(new PopupMenuListener() { + public void popupMenuCanceled(PopupMenuEvent e) {} + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} + + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + setModel(new ConfigurationModel(rkt)); + } + + }); } + + @Override + public void stateChanged(EventObject e) { + this.repaint(); + this.revalidate(); + } } diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index 1d46fcc46..1a033a887 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -8,6 +8,7 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; +import javax.swing.ListSelectionModel; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; @@ -24,6 +25,7 @@ import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; +import net.sf.openrocket.rocketcomponent.ComponentChangeListener; import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.Rocket; @@ -32,7 +34,7 @@ import net.sf.openrocket.util.Pair; @SuppressWarnings("serial") -public abstract class FlightConfigurablePanel extends JPanel { +public abstract class FlightConfigurablePanel extends JPanel implements ComponentChangeListener { protected static final Translator trans = Application.getTranslator(); private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class); @@ -46,7 +48,7 @@ public abstract class FlightConfigurablePanel 1) ? 1 : 0; + for (int row = 0; row < table.getRowCount(); row++) { + FlightConfigurationId rowFCID = rocket.getId(row); + if (rowFCID.equals(current)) { + table.changeSelection(row, col, false, false); + break; + } + } + return table; + } protected final void synchronizeConfigurationSelection() { - FlightConfigurationId defaultFCID = rocket.getSelectedConfiguration().getFlightConfigurationID(); + FlightConfigurationId currentRocketFCID = rocket.getSelectedConfiguration().getFlightConfigurationID(); FlightConfigurationId selectedFCID = getSelectedConfigurationId(); - if ( selectedFCID == null ) { + if ( currentRocketFCID == FlightConfigurationId.DEFAULT_VALUE_FCID ) { // need to unselect table.clearSelection(); - } else if ( !defaultFCID.equals(selectedFCID)){ + } else if ( !currentRocketFCID.equals(selectedFCID)){ // Need to change selection // We'll select the correct row, in the currently selected column. int col = table.getSelectedColumn(); @@ -80,8 +108,8 @@ public abstract class FlightConfigurablePanel