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.details = Show Details
|
||||||
TCMotorSelPan.btn.filter = Filter Motors
|
TCMotorSelPan.btn.filter = Filter Motors
|
||||||
TCMotorSelPan.MotorSize = Motor Dimensions
|
TCMotorSelPan.MotorSize = Motor Dimensions
|
||||||
TCMotorSelPan.limitByLength = Limit motors to motor mount length
|
TCMotorSelPan.Diameter = Daimeter
|
||||||
TCMotorSelPan.SHOW_DESCRIPTIONS.desc1 = Show all motors
|
TCMotorSelPan.Length = Length
|
||||||
TCMotorSelPan.SHOW_DESCRIPTIONS.desc2 = Show motors with diameter less than that of the motor mount
|
TCMotorSelPan.MotorMountDimensions = Motor mount dimensions:
|
||||||
TCMotorSelPan.SHOW_DESCRIPTIONS.desc3 = Show motors with diameter equal to that of the motor mount
|
|
||||||
TCMotorSelPan.lbl.Motormountdia = Motor mount diameter:
|
|
||||||
TCMotorSelPan.lbl.Search = Search:
|
TCMotorSelPan.lbl.Search = Search:
|
||||||
TCMotorSelPan.lbl.Selectthrustcurve = Select thrust curve:
|
TCMotorSelPan.lbl.Selectthrustcurve = Select thrust curve:
|
||||||
TCMotorSelPan.lbl.Ejectionchargedelay = Ejection charge delay:
|
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.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -11,12 +10,9 @@ import java.util.Hashtable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
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.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
@ -28,7 +24,6 @@ import javax.swing.event.ListDataListener;
|
|||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.gui.SpinnerEditor;
|
import net.sf.openrocket.gui.SpinnerEditor;
|
||||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
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.components.UnitSelector;
|
||||||
import net.sf.openrocket.gui.util.CheckList;
|
import net.sf.openrocket.gui.util.CheckList;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
@ -84,11 +79,10 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
private final MotorRowFilter filter;
|
private final MotorRowFilter filter;
|
||||||
|
|
||||||
// Things we change the label on based on the MotorMount.
|
// 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 final MultiSlider diameterSlider;
|
||||||
|
|
||||||
private Double mountLength;
|
|
||||||
|
|
||||||
public MotorFilterPanel(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) {
|
public MotorFilterPanel(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) {
|
||||||
super(new MigLayout("fill", "[grow]"));
|
super(new MigLayout("fill", "[grow]"));
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
@ -188,16 +182,19 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
sub.add( impulseSlider, "growx, wrap");
|
sub.add( impulseSlider, "growx, wrap");
|
||||||
}
|
}
|
||||||
this.add(sub,"grow, wrap");
|
this.add(sub,"grow, wrap");
|
||||||
|
|
||||||
|
|
||||||
// Diameter selection
|
// Diameter selection
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
TitledBorder diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCMotorSelPan.MotorSize"));
|
TitledBorder diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCMotorSelPan.MotorSize"));
|
||||||
GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD);
|
GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD);
|
||||||
sub.setBorder(diameterTitleBorder);
|
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 = new MultiSlider(MultiSlider.HORIZONTAL,0, diameterValues.length-1, 0, diameterValues.length-1);
|
||||||
diameterSlider.setBounded(true); // thumbs cannot cross
|
diameterSlider.setBounded(true); // thumbs cannot cross
|
||||||
diameterSlider.setMajorTickSpacing(1);
|
diameterSlider.setMajorTickSpacing(1);
|
||||||
@ -222,20 +219,49 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
maximumLengthCheckBox = new JCheckBox(trans.get("TCMotorSelPan.limitByLength"));
|
sub.add( new JLabel(trans.get("TCMotorSelPan.Length")), "split 2, wrap");
|
||||||
maximumLengthCheckBox.addChangeListener( new ChangeListener() {
|
|
||||||
|
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
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
if (maximumLengthCheckBox.isSelected() ) {
|
int minLength = lengthSlider.getValueAt(0);
|
||||||
MotorFilterPanel.this.filter.setMaximumLength( mountLength );
|
minimumLength.setValue(minLength/1000.0);
|
||||||
} else {
|
int maxLength = lengthSlider.getValueAt(1);
|
||||||
MotorFilterPanel.this.filter.setMaximumLength(null);
|
maximumLength.setValue(maxLength/1000.0);
|
||||||
}
|
|
||||||
onSelectionChanged();
|
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");
|
this.add(sub, "grow,wrap");
|
||||||
|
|
||||||
@ -246,27 +272,27 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
onSelectionChanged();
|
onSelectionChanged();
|
||||||
if ( mount == null ) {
|
if ( mount == null ) {
|
||||||
// Disable diameter controls?
|
// Disable diameter controls?
|
||||||
maximumLengthCheckBox.setText("Limit by length");
|
lengthSlider.setValueAt(1, 1000);
|
||||||
mountLength = null;
|
motorMountDimension.setText("");
|
||||||
} else {
|
} 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();
|
double mountDiameter = mount.getMotorMountDiameter();
|
||||||
// find the next largest diameter
|
// find the next largest diameter
|
||||||
int i;
|
int i;
|
||||||
for( i =0; i< diameterValues.length; i++ ) {
|
for( i =0; i< diameterValues.length; i++ ) {
|
||||||
if ( mountDiameter<= diameterValues[i] ) {
|
if ( mountDiameter< diameterValues[i] ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( i >= diameterValues.length-1 ) {
|
if (i >= diameterValues.length ) {
|
||||||
diameterSlider.setValueAt(1, diameterValues.length-1);
|
i--;
|
||||||
} else {
|
|
||||||
diameterSlider.setValueAt(1, i) ;
|
|
||||||
}
|
}
|
||||||
diameterSlider.setValueAt(1, i);
|
diameterSlider.setValueAt(1, i-1);
|
||||||
maximumLengthCheckBox.setText("Limit by length"
|
|
||||||
+ " (" + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(((RocketComponent)mount).getLength()) +")");
|
|
||||||
|
|
||||||
|
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.motor.ThrustCurveMotor;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
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
|
//////// Row filters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract adapter class.
|
* 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
|
// configuration data used in the filter process
|
||||||
private final ThrustCurveMotorDatabaseModel model;
|
private final ThrustCurveMotorDatabaseModel model;
|
||||||
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
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
|
// 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 minimumDiameter;
|
||||||
|
|
||||||
private Double maximumDiameter;
|
private Double maximumDiameter;
|
||||||
|
|
||||||
// Collection of strings which match text in the motor
|
// Collection of strings which match text in the motor
|
||||||
@ -47,7 +54,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
// Impulse class filtering
|
// Impulse class filtering
|
||||||
private ImpulseClass minimumImpulse;
|
private ImpulseClass minimumImpulse;
|
||||||
private ImpulseClass maximumImpulse;
|
private ImpulseClass maximumImpulse;
|
||||||
|
|
||||||
|
|
||||||
public MotorRowFilter(ThrustCurveMotorDatabaseModel model) {
|
public MotorRowFilter(ThrustCurveMotorDatabaseModel model) {
|
||||||
super();
|
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;
|
return maximumLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMaximumLength(Double maximumLength) {
|
public void setMaximumLength(double maximumLength) {
|
||||||
this.maximumLength = maximumLength;
|
if ( this.maximumLength != maximumLength ) {
|
||||||
|
this.maximumLength = maximumLength;
|
||||||
|
fireChangeEvent(change);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Double getMinimumDiameter() {
|
Double getMinimumDiameter() {
|
||||||
@ -165,13 +186,15 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( maximumLength != null ) {
|
if ( m.getLength() > maximumLength ) {
|
||||||
if ( m.getLength() > maximumLength ) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m.getLength() < minimumLength ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +217,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( maximumImpulse != null ) {
|
if ( maximumImpulse != null ) {
|
||||||
if( m.getTotalImpuse() > maximumImpulse.getHigh() ) {
|
if( m.getTotalImpuse() > maximumImpulse.getHigh() ) {
|
||||||
return false;
|
return false;
|
||||||
@ -204,4 +227,16 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
return true;
|
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