More cleanup.

This commit is contained in:
kruland2607 2013-10-04 21:33:46 -05:00
parent e6755e0e84
commit 7221b6558e
4 changed files with 106 additions and 49 deletions

View File

@ -1090,6 +1090,8 @@ TCMotorSelPan.checkbox.hideSimilar = Hide very similar thrust curves
TCMotorSelPan.checkbox.hideUsed = Hide motors already used in the mount TCMotorSelPan.checkbox.hideUsed = Hide motors already used in the mount
TCMotorSelPan.btn.details = Show Details TCMotorSelPan.btn.details = Show Details
TCMotorSelPan.btn.filter = Filter Motors 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.desc1 = Show all motors
TCMotorSelPan.SHOW_DESCRIPTIONS.desc2 = Show motors with diameter less than that of the motor mount 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 TCMotorSelPan.SHOW_DESCRIPTIONS.desc3 = Show motors with diameter equal to that of the motor mount

View File

@ -12,6 +12,7 @@ import java.util.List;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JRadioButton; 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.l10n.Translator;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
@ -48,7 +50,13 @@ public abstract class MotorFilterPanel extends JPanel {
private final CheckList<ImpulseClass> impulseCheckList; private final CheckList<ImpulseClass> impulseCheckList;
private final MotorRowFilter filter; 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 final DoubleModel mountDiameter = new DoubleModel(1);
private int showMode = SHOW_ALL; private int showMode = SHOW_ALL;
@ -194,7 +202,7 @@ public abstract class MotorFilterPanel extends JPanel {
// Diameter selection // Diameter selection
sub = new JPanel(new MigLayout("fill")); 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); GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD);
sub.setBorder(diameterTitleBorder); sub.setBorder(diameterTitleBorder);
@ -211,7 +219,7 @@ public abstract class MotorFilterPanel extends JPanel {
showAllDiametersButton.setSelected( showMode == SHOW_ALL); showAllDiametersButton.setSelected( showMode == SHOW_ALL);
sub.add(showAllDiametersButton, "growx,wrap"); 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() { showSmallerDiametersButton.addActionListener( new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -224,7 +232,7 @@ public abstract class MotorFilterPanel extends JPanel {
showSmallerDiametersButton.setSelected( showMode == SHOW_SMALLER); showSmallerDiametersButton.setSelected( showMode == SHOW_SMALLER);
sub.add(showSmallerDiametersButton, "growx,wrap"); 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() { showExactDiametersButton.addActionListener( new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -258,6 +266,23 @@ public abstract class MotorFilterPanel extends JPanel {
sub.add(new UnitSelector(minDiameter)); sub.add(new UnitSelector(minDiameter));
sub.add(new BasicSlider(minDiameter.getSliderModel(0,0.5, mountDiameter)), "w 100lp, wrap"); 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"); this.add(sub, "grow,wrap");
} }
@ -267,13 +292,20 @@ public abstract class MotorFilterPanel extends JPanel {
onSelectionChanged(); onSelectionChanged();
if ( mount == null ) { if ( mount == null ) {
// Disable diameter controls? // 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); mountDiameter.setValue(1.0);
mountLength = null;
} else { } else {
mountDiameter.setValue(mount.getMotorMountDiameter()); mountDiameter.setValue(mount.getMotorMountDiameter());
diameterTitleBorder.setTitle(trans.get("TCurveMotorCol.DIAMETER") + " " mountLength = ((RocketComponent)mount).getLength();
+ trans.get("TCMotorSelPan.lbl.Motormountdia") + " " + showSmallerDiametersButton.setText(trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2")
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(mount.getMotorMountDiameter())); + " " + 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()) +")");
} }
} }

View File

@ -21,43 +21,45 @@ import net.sf.openrocket.rocketcomponent.MotorMount;
* Abstract adapter class. * Abstract adapter class.
*/ */
class MotorRowFilter extends RowFilter<TableModel, Integer> { class MotorRowFilter extends RowFilter<TableModel, Integer> {
public enum DiameterFilterControl { public enum DiameterFilterControl {
ALL, ALL,
EXACT, EXACT,
SMALLER SMALLER
}; };
// configuration data used in the filter process // configuration data used in the filter process
private final ThrustCurveMotorDatabaseModel model; private final ThrustCurveMotorDatabaseModel model;
private Double diameter; private Double diameter;
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>(); private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
// things which can be changed to modify filter behavior // things which can be changed to modify filter behavior
private Double maximumLength;
// Limit motors based on minimum diameter // Limit motors based on minimum diameter
private Double minimumDiameter; private Double minimumDiameter;
// Collection of strings which match text in the motor // Collection of strings which match text in the motor
private List<String> searchTerms = Collections.<String> emptyList(); private List<String> searchTerms = Collections.<String> emptyList();
// Limit motors based on diameter of the motor mount // Limit motors based on diameter of the motor mount
private DiameterFilterControl diameterControl = DiameterFilterControl.ALL; private DiameterFilterControl diameterControl = DiameterFilterControl.ALL;
// Boolean which hides motors in the usedMotors list // Boolean which hides motors in the usedMotors list
private boolean hideUsedMotors = false; private boolean hideUsedMotors = false;
// List of manufacturers to exclude. // List of manufacturers to exclude.
private List<Manufacturer> excludedManufacturers = new ArrayList<Manufacturer>(); private List<Manufacturer> excludedManufacturers = new ArrayList<Manufacturer>();
// List of ImpulseClasses to exclude. // List of ImpulseClasses to exclude.
private List<ImpulseClass> excludedImpulseClass = new ArrayList<ImpulseClass>(); private List<ImpulseClass> excludedImpulseClass = new ArrayList<ImpulseClass>();
public MotorRowFilter(ThrustCurveMotorDatabaseModel model) { public MotorRowFilter(ThrustCurveMotorDatabaseModel model) {
super(); super();
this.model = model; this.model = model;
} }
public void setMotorMount( MotorMount mount ) { public void setMotorMount( MotorMount mount ) {
if (mount != null) { if (mount != null) {
this.diameter = mount.getMotorMountDiameter(); this.diameter = mount.getMotorMountDiameter();
@ -68,7 +70,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
this.diameter = null; this.diameter = null;
} }
} }
public void setSearchTerms(final List<String> searchTerms) { public void setSearchTerms(final List<String> searchTerms) {
this.searchTerms = new ArrayList<String>(); this.searchTerms = new ArrayList<String>();
for (String s : searchTerms) { for (String s : searchTerms) {
@ -78,7 +80,15 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
} }
} }
} }
Double getMaximumLength() {
return maximumLength;
}
void setMaximumLength(Double maximumLength) {
this.maximumLength = maximumLength;
}
Double getMinimumDiameter() { Double getMinimumDiameter() {
return minimumDiameter; return minimumDiameter;
} }
@ -94,11 +104,11 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
void setDiameterControl(DiameterFilterControl diameterControl) { void setDiameterControl(DiameterFilterControl diameterControl) {
this.diameterControl = diameterControl; this.diameterControl = diameterControl;
} }
void setHideUsedMotors(boolean hideUsedMotors) { void setHideUsedMotors(boolean hideUsedMotors) {
this.hideUsedMotors = hideUsedMotors; this.hideUsedMotors = hideUsedMotors;
} }
List<Manufacturer> getExcludedManufacturers() { List<Manufacturer> getExcludedManufacturers() {
return excludedManufacturers; return excludedManufacturers;
} }
@ -107,19 +117,19 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
this.excludedManufacturers.clear(); this.excludedManufacturers.clear();
this.excludedManufacturers.addAll(excludedManufacturers); this.excludedManufacturers.addAll(excludedManufacturers);
} }
void setExcludedImpulseClasses(Collection<ImpulseClass> excludedImpulseClasses ) { void setExcludedImpulseClasses(Collection<ImpulseClass> excludedImpulseClasses ) {
this.excludedImpulseClass.clear(); this.excludedImpulseClass.clear();
this.excludedImpulseClass.addAll(excludedImpulseClasses); this.excludedImpulseClass.addAll(excludedImpulseClasses);
} }
@Override @Override
public boolean include(RowFilter.Entry<? extends TableModel, ? extends Integer> entry) { public boolean include(RowFilter.Entry<? extends TableModel, ? extends Integer> entry) {
int index = entry.getIdentifier(); int index = entry.getIdentifier();
ThrustCurveMotorSet m = model.getMotorSet(index); 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) { private boolean filterManufacturers(ThrustCurveMotorSet m) {
if (excludedManufacturers.contains(m.getManufacturer())) { if (excludedManufacturers.contains(m.getManufacturer())) {
return false; return false;
@ -127,7 +137,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
return true; return true;
} }
} }
private boolean filterUsed(ThrustCurveMotorSet m) { private boolean filterUsed(ThrustCurveMotorSet m) {
if (!hideUsedMotors) { if (!hideUsedMotors) {
return true; return true;
@ -139,30 +149,43 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
} }
return true; return true;
} }
private boolean filterByDiameter(ThrustCurveMotorSet m) { private boolean filterBySize(ThrustCurveMotorSet m) {
if ( minimumDiameter != null ) { if ( minimumDiameter != null ) {
if ( m.getDiameter() <= minimumDiameter - 0.0015 ) { if ( m.getDiameter() <= minimumDiameter - 0.0015 ) {
return false; 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) { if ( maximumLength != null ) {
return true; if ( m.getLength() > maximumLength ) {
} return false;
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);
} }
return true;
} }
private boolean filterByString(ThrustCurveMotorSet m) { private boolean filterByString(ThrustCurveMotorSet m) {
main: for (String s : searchTerms) { main: for (String s : searchTerms) {
for (ThrustCurveMotorColumns col : ThrustCurveMotorColumns.values()) { for (ThrustCurveMotorColumns col : ThrustCurveMotorColumns.values()) {
@ -172,9 +195,9 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
} }
return false; return false;
} }
return true; return true;
} }
private boolean filterByImpulseClass(ThrustCurveMotorSet m) { private boolean filterByImpulseClass(ThrustCurveMotorSet m) {
for( ImpulseClass c : excludedImpulseClass ) { for( ImpulseClass c : excludedImpulseClass ) {
if (c.isIn(m) ) { if (c.isIn(m) ) {

View File

@ -305,7 +305,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
JScrollPane scrollpane = new JScrollPane(); JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(table); 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(); scrollSelectionVisible();
} }
}); });
panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap para"); panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap");
} }
//// Hide very similar thrust curves //// Hide very similar thrust curves
@ -336,7 +336,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
updateData(); updateData();
} }
}); });
panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap para"); panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap");
} }
// Vertical split // Vertical split