From 2badfe850d04cc3f5dd372b7363ca2b059d6d7eb Mon Sep 17 00:00:00 2001 From: Jon Jagt Date: Mon, 25 Jul 2022 10:51:57 -0500 Subject: [PATCH] Change Diameter Filters to use Preferences Add preferences for "match diameter" filters in the Component Preset Chooser to Preferences; change filter pre-checks to use those preferences. --- .../sf/openrocket/startup/Preferences.java | 41 +++++++++++++++++++ .../preset/ComponentPresetChooserDialog.java | 9 +++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/core/src/net/sf/openrocket/startup/Preferences.java b/core/src/net/sf/openrocket/startup/Preferences.java index 3d750c651..90da3c320 100644 --- a/core/src/net/sf/openrocket/startup/Preferences.java +++ b/core/src/net/sf/openrocket/startup/Preferences.java @@ -63,6 +63,9 @@ public abstract class Preferences implements ChangeSource { public static final String MOTOR_DIAMETER_FILTER = "MotorDiameterMatch"; public static final String MOTOR_HIDE_SIMILAR = "MotorHideSimilar"; public static final String MOTOR_HIDE_UNAVAILABLE = "MotorHideUnavailable"; + + public static final String MATCH_FORE_DIAMETER = "MatchForeDiameter"; + public static final String MATCH_AFT_DIAMETER = "MatchAftDiameter"; // Node names public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors"; @@ -490,6 +493,44 @@ public abstract class Preferences implements ChangeSource { return this.getBoolean(SHOW_MARKERS, false); } + /** + * Set whether the component preset chooser dialog should filter by fore diameter when the window is opened. + * @param enabled true if the fore diameter filter should be enabled, + * false if it should be disabled. + */ + public final void setMatchForeDiameter(boolean enabled) { + this.putBoolean(MATCH_FORE_DIAMETER, enabled); + } + + /** + * Answer if the component preset chooser dialog should filter by fore diameter when the window is opened. + * + * @return true if the fore diameter filter should be enabled, + * false if it should be disabled. + */ + public final boolean isMatchForeDiameter() { + return this.getBoolean(MATCH_FORE_DIAMETER, true); + } + + /** + * Set whether the component preset chooser dialog should filter by aft diameter when the window is opened. + * @param enabled true if the aft diameter filter should be enabled, + * false if it should be disabled. + */ + public final void setMatchAftDiameter(boolean enabled) { + this.putBoolean(MATCH_AFT_DIAMETER, enabled); + } + + /** + * Answer if the component preset chooser dialog should filter by aft diameter when the window is opened. + * + * @return true if the aft diameter filter should be enabled, + * false if it should be disabled. + */ + public final boolean isMatchAftDiameter() { + return this.getBoolean(MATCH_AFT_DIAMETER, true); + } + /** * Return the OpenRocket unique ID. * diff --git a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java index 15be53e13..ae556b57b 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java @@ -26,6 +26,7 @@ import javax.swing.table.TableModel; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.gui.util.GUIUtil; +import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.TypedKey; @@ -43,6 +44,8 @@ public class ComponentPresetChooserDialog extends JDialog { private static final Translator trans = Application.getTranslator(); + private final SwingPreferences preferences = (SwingPreferences) Application.getPreferences(); + private final RocketComponent component; private ComponentPresetTable componentSelectionTable; @@ -222,13 +225,14 @@ public class ComponentPresetChooserDialog extends JDialog { foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent(); if (prevSym != null && foreDiameterColumnIndex >= 0) { - foreDiameterFilterCheckBox.setSelected(true); + foreDiameterFilterCheckBox.setSelected(preferences.isMatchForeDiameter()); foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex); panel.add(foreDiameterFilterCheckBox, "wrap"); foreDiameterFilterCheckBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateFilters(); + preferences.setMatchForeDiameter(foreDiameterFilterCheckBox.isSelected()); } }); } @@ -239,13 +243,14 @@ public class ComponentPresetChooserDialog extends JDialog { aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); final SymmetricComponent nextSym = curSym.getNextSymmetricComponent(); if (nextSym != null && aftDiameterColumnIndex >= 0) { - aftDiameterFilterCheckBox.setSelected(true); + aftDiameterFilterCheckBox.setSelected(preferences.isMatchAftDiameter()); aftDiameterFilter = new ComponentPresetRowFilter(nextSym.getForeRadius() * 2.0, aftDiameterColumnIndex); panel.add(aftDiameterFilterCheckBox, "wrap"); aftDiameterFilterCheckBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateFilters(); + preferences.setMatchAftDiameter(aftDiameterFilterCheckBox.isSelected()); } }); }