diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 55f9ece1a..09e96ae34 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1090,6 +1090,8 @@ TCMotorSelPan.checkbox.hideSimilar = Hide very similar thrust curves TCMotorSelPan.checkbox.hideUsed = Hide motors already used in the mount TCMotorSelPan.btn.details = Show Details TCMotorSelPan.btn.filter = Filter Motors +TCMotorSelPan.MotorSize = Motor Dimensions +TCMotorSelPan.limitByLength = Limit motors to motor mount length TCMotorSelPan.SHOW_DESCRIPTIONS.desc1 = Show all motors TCMotorSelPan.SHOW_DESCRIPTIONS.desc2 = Show motors with diameter less than that of the motor mount TCMotorSelPan.SHOW_DESCRIPTIONS.desc3 = Show motors with diameter equal to that of the motor mount diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index 3c706c430..f39f4f7e8 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -12,6 +12,7 @@ import java.util.List; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -34,6 +35,7 @@ import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; @@ -48,7 +50,13 @@ public abstract class MotorFilterPanel extends JPanel { private final CheckList impulseCheckList; private final MotorRowFilter filter; - private final TitledBorder diameterTitleBorder; + + // Things we change the label on based on the MotorMount. + private final JCheckBox maximumLengthCheckBox; + private final JRadioButton showSmallerDiametersButton; + private final JRadioButton showExactDiametersButton; + + private Double mountLength; private final DoubleModel mountDiameter = new DoubleModel(1); private int showMode = SHOW_ALL; @@ -194,7 +202,7 @@ public abstract class MotorFilterPanel extends JPanel { // Diameter selection sub = new JPanel(new MigLayout("fill")); - diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCurveMotorCol.DIAMETER")); + TitledBorder diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCMotorSelPan.MotorSize")); GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD); sub.setBorder(diameterTitleBorder); @@ -211,7 +219,7 @@ public abstract class MotorFilterPanel extends JPanel { showAllDiametersButton.setSelected( showMode == SHOW_ALL); sub.add(showAllDiametersButton, "growx,wrap"); - JRadioButton showSmallerDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2") ); + showSmallerDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2") ); showSmallerDiametersButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -224,7 +232,7 @@ public abstract class MotorFilterPanel extends JPanel { showSmallerDiametersButton.setSelected( showMode == SHOW_SMALLER); sub.add(showSmallerDiametersButton, "growx,wrap"); - JRadioButton showExactDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3") ); + showExactDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3") ); showExactDiametersButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -258,6 +266,23 @@ public abstract class MotorFilterPanel extends JPanel { sub.add(new UnitSelector(minDiameter)); sub.add(new BasicSlider(minDiameter.getSliderModel(0,0.5, mountDiameter)), "w 100lp, wrap"); } + + { + maximumLengthCheckBox = new JCheckBox(trans.get("TCMotorSelPan.limitByLength")); + maximumLengthCheckBox.addChangeListener( new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if (maximumLengthCheckBox.isSelected() ) { + MotorFilterPanel.this.filter.setMaximumLength( mountLength ); + } else { + MotorFilterPanel.this.filter.setMaximumLength(null); + } + onSelectionChanged(); + } + + }); + sub.add(maximumLengthCheckBox); + } this.add(sub, "grow,wrap"); } @@ -267,13 +292,20 @@ public abstract class MotorFilterPanel extends JPanel { onSelectionChanged(); if ( mount == null ) { // Disable diameter controls? - diameterTitleBorder.setTitle(trans.get("TCurveMotorCol.DIAMETER")); + showSmallerDiametersButton.setText(trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2")); + showExactDiametersButton.setText(trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3")); + maximumLengthCheckBox.setText("Limit by length"); mountDiameter.setValue(1.0); + mountLength = null; } else { mountDiameter.setValue(mount.getMotorMountDiameter()); - diameterTitleBorder.setTitle(trans.get("TCurveMotorCol.DIAMETER") + " " - + trans.get("TCMotorSelPan.lbl.Motormountdia") + " " + - UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(mount.getMotorMountDiameter())); + mountLength = ((RocketComponent)mount).getLength(); + showSmallerDiametersButton.setText(trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2") + + " " + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(mount.getMotorMountDiameter())+ ")"); + showExactDiametersButton.setText(trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3") + + " (" + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(mount.getMotorMountDiameter())+ ")"); + maximumLengthCheckBox.setText("Limit by length" + + " (" + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(((RocketComponent)mount).getLength()) +")"); } } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java index 568dd31e1..513179f5f 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java @@ -21,43 +21,45 @@ import net.sf.openrocket.rocketcomponent.MotorMount; * Abstract adapter class. */ class MotorRowFilter extends RowFilter { - + public enum DiameterFilterControl { ALL, EXACT, SMALLER }; - + // configuration data used in the filter process private final ThrustCurveMotorDatabaseModel model; private Double diameter; private List usedMotors = new ArrayList(); - + // things which can be changed to modify filter behavior - + + private Double maximumLength; + // Limit motors based on minimum diameter private Double minimumDiameter; - + // Collection of strings which match text in the motor private List searchTerms = Collections. emptyList(); - + // Limit motors based on diameter of the motor mount private DiameterFilterControl diameterControl = DiameterFilterControl.ALL; - + // Boolean which hides motors in the usedMotors list private boolean hideUsedMotors = false; - + // List of manufacturers to exclude. private List excludedManufacturers = new ArrayList(); - + // List of ImpulseClasses to exclude. private List excludedImpulseClass = new ArrayList(); - + public MotorRowFilter(ThrustCurveMotorDatabaseModel model) { super(); this.model = model; } - + public void setMotorMount( MotorMount mount ) { if (mount != null) { this.diameter = mount.getMotorMountDiameter(); @@ -68,7 +70,7 @@ class MotorRowFilter extends RowFilter { this.diameter = null; } } - + public void setSearchTerms(final List searchTerms) { this.searchTerms = new ArrayList(); for (String s : searchTerms) { @@ -78,7 +80,15 @@ class MotorRowFilter extends RowFilter { } } } - + + Double getMaximumLength() { + return maximumLength; + } + + void setMaximumLength(Double maximumLength) { + this.maximumLength = maximumLength; + } + Double getMinimumDiameter() { return minimumDiameter; } @@ -94,11 +104,11 @@ class MotorRowFilter extends RowFilter { void setDiameterControl(DiameterFilterControl diameterControl) { this.diameterControl = diameterControl; } - + void setHideUsedMotors(boolean hideUsedMotors) { this.hideUsedMotors = hideUsedMotors; } - + List getExcludedManufacturers() { return excludedManufacturers; } @@ -107,19 +117,19 @@ class MotorRowFilter extends RowFilter { this.excludedManufacturers.clear(); this.excludedManufacturers.addAll(excludedManufacturers); } - + void setExcludedImpulseClasses(Collection excludedImpulseClasses ) { this.excludedImpulseClass.clear(); this.excludedImpulseClass.addAll(excludedImpulseClasses); } - + @Override public boolean include(RowFilter.Entry entry) { int index = entry.getIdentifier(); ThrustCurveMotorSet m = model.getMotorSet(index); - return filterManufacturers(m) && filterUsed(m) && filterByDiameter(m) && filterByString(m) && filterByImpulseClass(m); + return filterManufacturers(m) && filterUsed(m) && filterBySize(m) && filterByString(m) && filterByImpulseClass(m); } - + private boolean filterManufacturers(ThrustCurveMotorSet m) { if (excludedManufacturers.contains(m.getManufacturer())) { return false; @@ -127,7 +137,7 @@ class MotorRowFilter extends RowFilter { return true; } } - + private boolean filterUsed(ThrustCurveMotorSet m) { if (!hideUsedMotors) { return true; @@ -139,30 +149,43 @@ class MotorRowFilter extends RowFilter { } return true; } - - private boolean filterByDiameter(ThrustCurveMotorSet m) { - + + private boolean filterBySize(ThrustCurveMotorSet m) { + if ( minimumDiameter != null ) { if ( m.getDiameter() <= minimumDiameter - 0.0015 ) { return false; } } + + if (diameter != null) { + switch (diameterControl) { + default: + case ALL: + break; + case EXACT: + if ((m.getDiameter() <= diameter + 0.0004) && (m.getDiameter() >= diameter - 0.0015)) { + break; + } + return false; + case SMALLER: + if (m.getDiameter() <= diameter + 0.0004) { + break; + } + return false; + } + } - if (diameter == null) { - return true; - } - switch (diameterControl) { - default: - case ALL: - return true; - case EXACT: - return ((m.getDiameter() <= diameter + 0.0004) && (m.getDiameter() >= diameter - 0.0015)); - case SMALLER: - return (m.getDiameter() <= diameter + 0.0004); + if ( maximumLength != null ) { + if ( m.getLength() > maximumLength ) { + return false; + } } + + return true; } - - + + private boolean filterByString(ThrustCurveMotorSet m) { main: for (String s : searchTerms) { for (ThrustCurveMotorColumns col : ThrustCurveMotorColumns.values()) { @@ -172,9 +195,9 @@ class MotorRowFilter extends RowFilter { } return false; } - return true; + return true; } - + private boolean filterByImpulseClass(ThrustCurveMotorSet m) { for( ImpulseClass c : excludedImpulseClass ) { if (c.isIn(m) ) { diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index 83b5e5b62..8e2016b07 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -305,7 +305,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(table); - panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para"); + panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap"); } @@ -321,7 +321,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec scrollSelectionVisible(); } }); - panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap para"); + panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap"); } //// Hide very similar thrust curves @@ -336,7 +336,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec updateData(); } }); - panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap para"); + panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap"); } // Vertical split