Wire up motor length filter using ChangeListener and DoubleModel.
This commit is contained in:
parent
3e57ef205d
commit
2127908b2a
@ -1091,11 +1091,9 @@ 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
|
||||
TCMotorSelPan.lbl.Motormountdia = Motor mount diameter:
|
||||
TCMotorSelPan.Diameter = Daimeter
|
||||
TCMotorSelPan.Length = Length
|
||||
TCMotorSelPan.MotorMountDimensions = Motor mount dimensions:
|
||||
TCMotorSelPan.lbl.Search = Search:
|
||||
TCMotorSelPan.lbl.Selectthrustcurve = Select thrust curve:
|
||||
TCMotorSelPan.lbl.Ejectionchargedelay = Ejection charge delay:
|
||||
|
@ -3,7 +3,6 @@ package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@ -11,12 +10,9 @@ import java.util.Hashtable;
|
||||
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;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.border.TitledBorder;
|
||||
@ -28,7 +24,6 @@ import javax.swing.event.ListDataListener;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.gui.SpinnerEditor;
|
||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
import net.sf.openrocket.gui.util.CheckList;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
@ -84,11 +79,10 @@ public abstract class MotorFilterPanel extends JPanel {
|
||||
private final MotorRowFilter filter;
|
||||
|
||||
// Things we change the label on based on the MotorMount.
|
||||
private final JCheckBox maximumLengthCheckBox;
|
||||
private final JLabel motorMountDimension;
|
||||
private final MultiSlider lengthSlider;
|
||||
private final MultiSlider diameterSlider;
|
||||
|
||||
private Double mountLength;
|
||||
|
||||
public MotorFilterPanel(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) {
|
||||
super(new MigLayout("fill", "[grow]"));
|
||||
this.filter = filter;
|
||||
@ -188,16 +182,19 @@ public abstract class MotorFilterPanel extends JPanel {
|
||||
sub.add( impulseSlider, "growx, wrap");
|
||||
}
|
||||
this.add(sub,"grow, wrap");
|
||||
|
||||
|
||||
|
||||
|
||||
// Diameter selection
|
||||
sub = new JPanel(new MigLayout("fill"));
|
||||
TitledBorder diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCMotorSelPan.MotorSize"));
|
||||
GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD);
|
||||
sub.setBorder(diameterTitleBorder);
|
||||
|
||||
motorMountDimension = new JLabel();
|
||||
GUIUtil.changeFontSize(motorMountDimension, -1);
|
||||
sub.add(motorMountDimension,"growx,wrap");
|
||||
{
|
||||
sub.add( new JLabel("Minimum diameter"), "split 2, wrap");
|
||||
sub.add( new JLabel("Diameter"), "split 2, wrap");
|
||||
diameterSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, diameterValues.length-1, 0, diameterValues.length-1);
|
||||
diameterSlider.setBounded(true); // thumbs cannot cross
|
||||
diameterSlider.setMajorTickSpacing(1);
|
||||
@ -222,20 +219,49 @@ public abstract class MotorFilterPanel extends JPanel {
|
||||
}
|
||||
|
||||
{
|
||||
maximumLengthCheckBox = new JCheckBox(trans.get("TCMotorSelPan.limitByLength"));
|
||||
maximumLengthCheckBox.addChangeListener( new ChangeListener() {
|
||||
sub.add( new JLabel(trans.get("TCMotorSelPan.Length")), "split 2, wrap");
|
||||
|
||||
final DoubleModel minimumLength = new DoubleModel(filter, "MinimumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
||||
final DoubleModel maximumLength = new DoubleModel(filter, "MaximumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
||||
|
||||
JSpinner spin = new JSpinner(minimumLength.getSpinnerModel());
|
||||
spin.setEditor(new SpinnerEditor(spin));
|
||||
sub.add(spin, "split 5, growx");
|
||||
|
||||
sub.add(new UnitSelector(minimumLength), "");
|
||||
|
||||
lengthSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, 1000, 0, 1000);
|
||||
lengthSlider.setBounded(true); // thumbs cannot cross
|
||||
lengthSlider.setMajorTickSpacing(100);
|
||||
lengthSlider.setPaintTicks(true);
|
||||
lengthSlider.setLabelTable(diameterLabels);
|
||||
lengthSlider.addChangeListener( new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (maximumLengthCheckBox.isSelected() ) {
|
||||
MotorFilterPanel.this.filter.setMaximumLength( mountLength );
|
||||
} else {
|
||||
MotorFilterPanel.this.filter.setMaximumLength(null);
|
||||
}
|
||||
int minLength = lengthSlider.getValueAt(0);
|
||||
minimumLength.setValue(minLength/1000.0);
|
||||
int maxLength = lengthSlider.getValueAt(1);
|
||||
maximumLength.setValue(maxLength/1000.0);
|
||||
onSelectionChanged();
|
||||
}
|
||||
});
|
||||
|
||||
minimumLength.addChangeListener( new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
lengthSlider.setValueAt(0, (int)(1000* minimumLength.getValue()));
|
||||
lengthSlider.setValueAt(1, (int) (1000* maximumLength.getValue()));
|
||||
}
|
||||
|
||||
});
|
||||
sub.add(maximumLengthCheckBox);
|
||||
|
||||
sub.add( lengthSlider, "growx");
|
||||
|
||||
spin = new JSpinner(maximumLength.getSpinnerModel());
|
||||
spin.setEditor(new SpinnerEditor(spin));
|
||||
sub.add(spin, "growx");
|
||||
|
||||
sub.add(new UnitSelector(maximumLength), "wrap");
|
||||
}
|
||||
this.add(sub, "grow,wrap");
|
||||
|
||||
@ -246,27 +272,27 @@ public abstract class MotorFilterPanel extends JPanel {
|
||||
onSelectionChanged();
|
||||
if ( mount == null ) {
|
||||
// Disable diameter controls?
|
||||
maximumLengthCheckBox.setText("Limit by length");
|
||||
mountLength = null;
|
||||
lengthSlider.setValueAt(1, 1000);
|
||||
motorMountDimension.setText("");
|
||||
} else {
|
||||
mountLength = ((RocketComponent)mount).getLength();
|
||||
double mountLength = ((RocketComponent)mount).getLength();
|
||||
lengthSlider.setValueAt(1, (int) Math.min(1000,Math.round(1000*mountLength)));
|
||||
|
||||
double mountDiameter = mount.getMotorMountDiameter();
|
||||
// find the next largest diameter
|
||||
int i;
|
||||
for( i =0; i< diameterValues.length; i++ ) {
|
||||
if ( mountDiameter<= diameterValues[i] ) {
|
||||
if ( mountDiameter< diameterValues[i] ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( i >= diameterValues.length-1 ) {
|
||||
diameterSlider.setValueAt(1, diameterValues.length-1);
|
||||
} else {
|
||||
diameterSlider.setValueAt(1, i) ;
|
||||
if (i >= diameterValues.length ) {
|
||||
i--;
|
||||
}
|
||||
diameterSlider.setValueAt(1, i);
|
||||
maximumLengthCheckBox.setText("Limit by length"
|
||||
+ " (" + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(((RocketComponent)mount).getLength()) +")");
|
||||
diameterSlider.setValueAt(1, i-1);
|
||||
|
||||
motorMountDimension.setText( trans.get("TCMotorSelPan.MotorMountDimensions") + " " +
|
||||
UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountDiameter)+ "x" + UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountLength));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,25 +14,32 @@ import net.sf.openrocket.motor.Manufacturer;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||
import net.sf.openrocket.util.AbstractChangeSource;
|
||||
import net.sf.openrocket.util.ChangeSource;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
//////// Row filters
|
||||
|
||||
/**
|
||||
* Abstract adapter class.
|
||||
*/
|
||||
class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
public class MotorRowFilter extends RowFilter<TableModel, Integer> implements ChangeSource {
|
||||
|
||||
// configuration data used in the filter process
|
||||
private final ThrustCurveMotorDatabaseModel model;
|
||||
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
||||
|
||||
private final AbstractChangeSource changeSourceDelegate = new AbstractChangeSource();
|
||||
private final Object change = new Object();
|
||||
|
||||
// things which can be changed to modify filter behavior
|
||||
|
||||
private Double maximumLength;
|
||||
// Limit motors based on length
|
||||
private double minimumLength = 0;
|
||||
private double maximumLength = Double.MAX_VALUE;
|
||||
|
||||
// Limit motors based on minimum diameter
|
||||
// Limit motors based on diameter
|
||||
private Double minimumDiameter;
|
||||
|
||||
private Double maximumDiameter;
|
||||
|
||||
// Collection of strings which match text in the motor
|
||||
@ -47,7 +54,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
// Impulse class filtering
|
||||
private ImpulseClass minimumImpulse;
|
||||
private ImpulseClass maximumImpulse;
|
||||
|
||||
|
||||
|
||||
public MotorRowFilter(ThrustCurveMotorDatabaseModel model) {
|
||||
super();
|
||||
@ -72,12 +79,26 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
Double getMaximumLength() {
|
||||
public double getMinimumLength() {
|
||||
return minimumLength;
|
||||
}
|
||||
|
||||
public void setMinimumLength(double minimumLength) {
|
||||
if ( this.minimumLength != minimumLength ) {
|
||||
this.minimumLength = minimumLength;
|
||||
fireChangeEvent(change);
|
||||
}
|
||||
}
|
||||
|
||||
public double getMaximumLength() {
|
||||
return maximumLength;
|
||||
}
|
||||
|
||||
void setMaximumLength(Double maximumLength) {
|
||||
this.maximumLength = maximumLength;
|
||||
public void setMaximumLength(double maximumLength) {
|
||||
if ( this.maximumLength != maximumLength ) {
|
||||
this.maximumLength = maximumLength;
|
||||
fireChangeEvent(change);
|
||||
}
|
||||
}
|
||||
|
||||
Double getMinimumDiameter() {
|
||||
@ -165,13 +186,15 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( maximumLength != null ) {
|
||||
if ( m.getLength() > maximumLength ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m.getLength() > maximumLength ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( m.getLength() < minimumLength ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -194,7 +217,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( maximumImpulse != null ) {
|
||||
if( m.getTotalImpuse() > maximumImpulse.getHigh() ) {
|
||||
return false;
|
||||
@ -204,4 +227,16 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final void addChangeListener(StateChangeListener listener) {
|
||||
changeSourceDelegate.addChangeListener(listener);
|
||||
}
|
||||
|
||||
public final void removeChangeListener(StateChangeListener listener) {
|
||||
changeSourceDelegate.removeChangeListener(listener);
|
||||
}
|
||||
|
||||
public void fireChangeEvent(Object source) {
|
||||
changeSourceDelegate.fireChangeEvent(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user