Merge pull request #1547 from JonathanJagt23/issue-1480

[#1480] Pre-check diameter filters in component preset chooser
This commit is contained in:
SiboVG 2022-07-27 21:41:57 +02:00 committed by GitHub
commit 949c1cb08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -63,6 +63,9 @@ public abstract class Preferences implements ChangeSource {
public static final String MOTOR_DIAMETER_FILTER = "MotorDiameterMatch"; public static final String MOTOR_DIAMETER_FILTER = "MotorDiameterMatch";
public static final String MOTOR_HIDE_SIMILAR = "MotorHideSimilar"; public static final String MOTOR_HIDE_SIMILAR = "MotorHideSimilar";
public static final String MOTOR_HIDE_UNAVAILABLE = "MotorHideUnavailable"; 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 // Node names
public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors"; 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); 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. * Return the OpenRocket unique ID.
* *

View File

@ -26,6 +26,7 @@ import javax.swing.table.TableModel;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.preset.TypedKey; import net.sf.openrocket.preset.TypedKey;
@ -43,6 +44,8 @@ public class ComponentPresetChooserDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
private final RocketComponent component; private final RocketComponent component;
private ComponentPresetTable componentSelectionTable; private ComponentPresetTable componentSelectionTable;
@ -222,12 +225,14 @@ public class ComponentPresetChooserDialog extends JDialog {
foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter"));
final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent(); final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent();
if (prevSym != null && foreDiameterColumnIndex >= 0) { if (prevSym != null && foreDiameterColumnIndex >= 0) {
foreDiameterFilterCheckBox.setSelected(preferences.isMatchForeDiameter());
foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex); foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex);
panel.add(foreDiameterFilterCheckBox, "wrap"); panel.add(foreDiameterFilterCheckBox, "wrap");
foreDiameterFilterCheckBox.addItemListener(new ItemListener() { foreDiameterFilterCheckBox.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
updateFilters(); updateFilters();
preferences.setMatchForeDiameter(foreDiameterFilterCheckBox.isSelected());
} }
}); });
} }
@ -238,12 +243,14 @@ public class ComponentPresetChooserDialog extends JDialog {
aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter"));
final SymmetricComponent nextSym = curSym.getNextSymmetricComponent(); final SymmetricComponent nextSym = curSym.getNextSymmetricComponent();
if (nextSym != null && aftDiameterColumnIndex >= 0) { if (nextSym != null && aftDiameterColumnIndex >= 0) {
aftDiameterFilterCheckBox.setSelected(preferences.isMatchAftDiameter());
aftDiameterFilter = new ComponentPresetRowFilter(nextSym.getForeRadius() * 2.0, aftDiameterColumnIndex); aftDiameterFilter = new ComponentPresetRowFilter(nextSym.getForeRadius() * 2.0, aftDiameterColumnIndex);
panel.add(aftDiameterFilterCheckBox, "wrap"); panel.add(aftDiameterFilterCheckBox, "wrap");
aftDiameterFilterCheckBox.addItemListener(new ItemListener() { aftDiameterFilterCheckBox.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
updateFilters(); updateFilters();
preferences.setMatchAftDiameter(aftDiameterFilterCheckBox.isSelected());
} }
}); });
} }