From 7b9deff18095aa0faeccb7922874fca81a0fd737 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 3 May 2020 15:30:43 -0400 Subject: [PATCH] [refactor] ComponentPresetChooserDialog now calls SymmetricComponent.get{Next|Prev}SymmetricComponent(...) --- .../preset/ComponentPresetChooserDialog.java | 91 +++++++------------ 1 file changed, 34 insertions(+), 57 deletions(-) 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 31b16d956..3ad6283e6 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/preset/ComponentPresetChooserDialog.java @@ -172,8 +172,6 @@ public class ComponentPresetChooserDialog extends JDialog { private JPanel getFilterCheckboxes() { - SymmetricComponent sc; - JPanel panel = new JPanel(new MigLayout("ins 0")); /* @@ -197,37 +195,40 @@ public class ComponentPresetChooserDialog extends JDialog { } }); } - - /* - * Add filter by fore diameter - */ - foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); - sc = getPreviousSymmetricComponent(); - if (sc != null && foreDiameterColumnIndex >= 0) { - foreDiameterFilter = new ComponentPresetRowFilter(sc.getAftRadius() * 2.0, foreDiameterColumnIndex); - panel.add(foreDiameterFilterCheckBox, "wrap"); - foreDiameterFilterCheckBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateFilters(); - } - }); - } - - /* - * Add filter by aft diameter - */ - aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); - sc = getNextSymmetricComponent(); - if (sc != null && aftDiameterColumnIndex >= 0) { - aftDiameterFilter = new ComponentPresetRowFilter(sc.getForeRadius() * 2.0, aftDiameterColumnIndex); - panel.add(aftDiameterFilterCheckBox, "wrap"); - aftDiameterFilterCheckBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateFilters(); - } - }); + + if(component instanceof SymmetricComponent) { + final SymmetricComponent curSym = (SymmetricComponent) component; + /* + * Add filter by fore diameter + */ + foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); + final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent(); + if (prevSym != null && foreDiameterColumnIndex >= 0) { + foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex); + panel.add(foreDiameterFilterCheckBox, "wrap"); + foreDiameterFilterCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + updateFilters(); + } + }); + } + + /* + * Add filter by aft diameter + */ + aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); + final SymmetricComponent nextSym = curSym.getNextSymmetricComponent(); + if (nextSym != null && aftDiameterColumnIndex >= 0) { + aftDiameterFilter = new ComponentPresetRowFilter(nextSym.getForeRadius() * 2.0, aftDiameterColumnIndex); + panel.add(aftDiameterFilterCheckBox, "wrap"); + aftDiameterFilterCheckBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + updateFilters(); + } + }); + } } return panel; @@ -275,28 +276,4 @@ public class ComponentPresetChooserDialog extends JDialog { componentSelectionTable.setRowFilter(RowFilter.andFilter(filters)); } - - - private SymmetricComponent getPreviousSymmetricComponent() { - RocketComponent c = component; - while (c != null) { - c = c.getPreviousComponent(); - if (c instanceof SymmetricComponent) { - return (SymmetricComponent) c; - } - } - return null; - } - - - private SymmetricComponent getNextSymmetricComponent() { - RocketComponent c = component; - while (c != null) { - c = c.getNextComponent(); - if (c instanceof SymmetricComponent) { - return (SymmetricComponent) c; - } - } - return null; - } }