[refactor] ComponentPresetChooserDialog now calls SymmetricComponent.get{Next|Prev}SymmetricComponent(...)

This commit is contained in:
Daniel_M_Williams 2020-05-03 15:30:43 -04:00
parent d8a8c14449
commit 7b9deff180

View File

@ -172,8 +172,6 @@ public class ComponentPresetChooserDialog extends JDialog {
private JPanel getFilterCheckboxes() { private JPanel getFilterCheckboxes() {
SymmetricComponent sc;
JPanel panel = new JPanel(new MigLayout("ins 0")); JPanel panel = new JPanel(new MigLayout("ins 0"));
/* /*
@ -198,36 +196,39 @@ public class ComponentPresetChooserDialog extends JDialog {
}); });
} }
/* if(component instanceof SymmetricComponent) {
* Add filter by fore diameter final SymmetricComponent curSym = (SymmetricComponent) component;
*/ /*
foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter")); * Add filter by fore diameter
sc = getPreviousSymmetricComponent(); */
if (sc != null && foreDiameterColumnIndex >= 0) { foreDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterForeDiameter"));
foreDiameterFilter = new ComponentPresetRowFilter(sc.getAftRadius() * 2.0, foreDiameterColumnIndex); final SymmetricComponent prevSym = curSym.getPreviousSymmetricComponent();
panel.add(foreDiameterFilterCheckBox, "wrap"); if (prevSym != null && foreDiameterColumnIndex >= 0) {
foreDiameterFilterCheckBox.addItemListener(new ItemListener() { foreDiameterFilter = new ComponentPresetRowFilter(prevSym.getAftRadius() * 2.0, foreDiameterColumnIndex);
@Override panel.add(foreDiameterFilterCheckBox, "wrap");
public void itemStateChanged(ItemEvent e) { foreDiameterFilterCheckBox.addItemListener(new ItemListener() {
updateFilters(); @Override
} public void itemStateChanged(ItemEvent e) {
}); updateFilters();
} }
});
}
/* /*
* Add filter by aft diameter * Add filter by aft diameter
*/ */
aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter")); aftDiameterFilterCheckBox = new JCheckBox(trans.get("ComponentPresetChooserDialog.checkbox.filterAftDiameter"));
sc = getNextSymmetricComponent(); final SymmetricComponent nextSym = curSym.getNextSymmetricComponent();
if (sc != null && aftDiameterColumnIndex >= 0) { if (nextSym != null && aftDiameterColumnIndex >= 0) {
aftDiameterFilter = new ComponentPresetRowFilter(sc.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();
} }
}); });
}
} }
return panel; return panel;
@ -275,28 +276,4 @@ public class ComponentPresetChooserDialog extends JDialog {
componentSelectionTable.setRowFilter(RowFilter.andFilter(filters)); 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;
}
} }