diff --git a/swing/src/main/java/info/openrocket/swing/gui/simulation/FlightDataComboBox.java b/swing/src/main/java/info/openrocket/swing/gui/simulation/FlightDataComboBox.java index 8fad7baaa..b1e0932e9 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/simulation/FlightDataComboBox.java +++ b/swing/src/main/java/info/openrocket/swing/gui/simulation/FlightDataComboBox.java @@ -7,12 +7,7 @@ import info.openrocket.core.simulation.FlightDataTypeGroup; import info.openrocket.core.startup.Application; import javax.swing.JComboBox; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; public class FlightDataComboBox extends JComboBox { private static final Translator trans = Application.getTranslator(); @@ -20,33 +15,4 @@ public class FlightDataComboBox extends JComboBox { public static GroupableAndSearchableComboBox createComboBox(List types) { return new GroupableAndSearchableComboBox<>(types, trans.get("FlightDataComboBox.placeholder")); } - - /** - * Create a map of flight data group and corresponding flight data types. - * @param groups the groups - * @param types the types - * @return the map linking the types to their groups - */ - private static Map> createFlightDataGroupMap( - FlightDataTypeGroup[] groups, FlightDataType[] types) { - // Sort the groups based on priority (lower number = higher priority) - FlightDataTypeGroup[] sortedGroups = groups.clone(); - Arrays.sort(sortedGroups, Comparator.comparingInt(FlightDataTypeGroup::getPriority)); - - Map> map = new LinkedHashMap<>(); - for (FlightDataTypeGroup group : sortedGroups) { - List itemsForGroup = new ArrayList<>(); - for (FlightDataType type : types) { - if (type.getGroup().equals(group)) { - itemsForGroup.add(type); - } - } - // Sort the types within each group based on priority - itemsForGroup.sort(Comparator.comparingInt(FlightDataType::getGroupPriority)); - - map.put(group, itemsForGroup); - } - - return map; - } } diff --git a/swing/src/main/java/info/openrocket/swing/gui/simulation/SimulationPlotPanel.java b/swing/src/main/java/info/openrocket/swing/gui/simulation/SimulationPlotPanel.java index 396d2d901..c9dab7191 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/simulation/SimulationPlotPanel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/simulation/SimulationPlotPanel.java @@ -35,6 +35,7 @@ import info.openrocket.core.preferences.ApplicationPreferences; import info.openrocket.core.unit.Unit; import info.openrocket.core.util.Utils; +import info.openrocket.swing.gui.widgets.GroupableAndSearchableComboBox; import net.miginfocom.swing.MigLayout; import info.openrocket.swing.gui.components.DescriptionArea; import info.openrocket.swing.gui.components.UnitSelector; @@ -101,7 +102,7 @@ public class SimulationPlotPanel extends JPanel { private JComboBox configurationSelector; - private JComboBox domainTypeSelector; + private GroupableAndSearchableComboBox domainTypeSelector; private UnitSelector domainUnitSelector; private JPanel typeSelectorPanel; @@ -487,7 +488,7 @@ public class SimulationPlotPanel extends JPanel { private final String[] POSITIONS = { AUTO_NAME, LEFT_NAME, RIGHT_NAME }; private final int index; - private final JComboBox typeSelector; + private final GroupableAndSearchableComboBox typeSelector; private UnitSelector unitSelector; private JComboBox axisSelector; diff --git a/swing/src/main/java/info/openrocket/swing/gui/widgets/GroupableAndSearchableComboBox.java b/swing/src/main/java/info/openrocket/swing/gui/widgets/GroupableAndSearchableComboBox.java index 7fef1cf9a..f8118a9d6 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/widgets/GroupableAndSearchableComboBox.java +++ b/swing/src/main/java/info/openrocket/swing/gui/widgets/GroupableAndSearchableComboBox.java @@ -152,6 +152,9 @@ public class GroupableAndSearchableComboBox(itemGroupMap); // Create a copy to avoid external modifications this.allItems = extractItemsFromMap(itemGroupMap); - // Update the existing model instead of creating a new one + // Update the model if (getModel() instanceof DefaultComboBoxModel) { + T selectedItem = (T) getModel().getSelectedItem(); ComboBoxModel model = new DefaultComboBoxModel<>(new Vector<>(allItems)); + model.setSelectedItem(selectedItem); setModel(model); setupModelListener(model); } @@ -267,7 +272,6 @@ public class GroupableAndSearchableComboBox { setSelectedItem(item); - fireActionEvent(); }); groupMenu.add(itemMenu); } @@ -365,7 +369,7 @@ public class GroupableAndSearchableComboBox model) { - if (model == null) { + /*if (model == null) { return; } model.addListDataListener(this); @@ -448,7 +452,7 @@ public class GroupableAndSearchableComboBox