[fixes #724] Fixes unit-updating in rocket-motor-selection
This commit is contained in:
parent
1a261a7c75
commit
0a0fcc96a9
@ -45,30 +45,31 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private static Hashtable<Integer,JLabel> diameterLabels = new Hashtable<Integer,JLabel>();
|
private static final Hashtable<Integer,JLabel> diameterLabels = new Hashtable<Integer,JLabel>();
|
||||||
private static double[] diameterValues = new double[] {
|
private static final double[] motorDiameters = new double[] {
|
||||||
0,
|
0.0,
|
||||||
.013,
|
0.013,
|
||||||
.018,
|
0.018,
|
||||||
.024,
|
0.024,
|
||||||
.029,
|
0.029,
|
||||||
.038,
|
0.038,
|
||||||
.054,
|
0.054,
|
||||||
.075,
|
0.075,
|
||||||
.098,
|
0.098,
|
||||||
1.000
|
1.000
|
||||||
};
|
};
|
||||||
static {
|
|
||||||
for( int i = 0; i< diameterValues.length; i++ ) {
|
/**
|
||||||
if( i == diameterValues.length-1) {
|
* updates: motorDiameters, diameterLabels
|
||||||
diameterLabels.put( i, new JLabel("+"));
|
*/
|
||||||
} else {
|
private static void scaleDiameterLabels(){
|
||||||
diameterLabels.put( i, new JLabel(UnitGroup.UNITS_MOTOR_DIMENSIONS.toString(diameterValues[i])));
|
for( int i = 0; i < motorDiameters.length; i++ ) {
|
||||||
}
|
diameterLabels.put( i, new JLabel(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toString(motorDiameters[i])));
|
||||||
}
|
}
|
||||||
|
diameterLabels.get( motorDiameters.length-1).setText("+");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Hashtable<Integer,JLabel> impulseLabels = new Hashtable<Integer,JLabel>();
|
final private static Hashtable<Integer,JLabel> impulseLabels = new Hashtable<Integer,JLabel>();
|
||||||
static {
|
static {
|
||||||
int i =0;
|
int i =0;
|
||||||
for( ImpulseClass impulseClass : ImpulseClass.values() ) {
|
for( ImpulseClass impulseClass : ImpulseClass.values() ) {
|
||||||
@ -87,9 +88,16 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
private Double mountLength = null;
|
private Double mountLength = null;
|
||||||
|
|
||||||
private final JCheckBox limitDiameterCheckBox;
|
private final JCheckBox limitDiameterCheckBox;
|
||||||
|
final DoubleModel minLengthModel;
|
||||||
|
final JSpinner minLengthSpinner;
|
||||||
|
final UnitSelector minLengthUnitSelect;
|
||||||
|
final DoubleModel maxLengthModel;
|
||||||
|
final JSpinner maxLengthSpinner;
|
||||||
|
final UnitSelector maxLengthUnitSelect;
|
||||||
private boolean limitDiameter = false;
|
private boolean limitDiameter = false;
|
||||||
private Double mountDiameter = null;
|
private Double mountDiameter = null;
|
||||||
|
|
||||||
|
|
||||||
// Things we change the label on based on the MotorMount.
|
// Things we change the label on based on the MotorMount.
|
||||||
private final JLabel motorMountDimension;
|
private final JLabel motorMountDimension;
|
||||||
private final MultiSlider lengthSlider;
|
private final MultiSlider lengthSlider;
|
||||||
@ -97,7 +105,9 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
scaleDiameterLabels();
|
||||||
|
|
||||||
List<Manufacturer> unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers();
|
List<Manufacturer> unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers();
|
||||||
filter.setExcludedManufacturers(unselectedManusFromPreferences);
|
filter.setExcludedManufacturers(unselectedManusFromPreferences);
|
||||||
@ -187,7 +197,7 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
|
|
||||||
this.add(sub,"grow, wrap");
|
this.add(sub,"grow, wrap");
|
||||||
|
|
||||||
// Impulse selection
|
// Total Impulse selection
|
||||||
{
|
{
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
border = BorderFactory.createTitledBorder(trans.get("TCurveMotorCol.TOTAL_IMPULSE"));
|
border = BorderFactory.createTitledBorder(trans.get("TCurveMotorCol.TOTAL_IMPULSE"));
|
||||||
@ -225,7 +235,7 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
GUIUtil.changeFontSize(motorMountDimension, -1);
|
GUIUtil.changeFontSize(motorMountDimension, -1);
|
||||||
sub.add(motorMountDimension,"growx,wrap");
|
sub.add(motorMountDimension,"growx,wrap");
|
||||||
|
|
||||||
// Diameter selection
|
// Motor Dimension selection
|
||||||
{
|
{
|
||||||
sub.add( new JLabel(trans.get("TCMotorSelPan.Diameter")), "split 2, wrap");
|
sub.add( new JLabel(trans.get("TCMotorSelPan.Diameter")), "split 2, wrap");
|
||||||
limitDiameterCheckBox = new JCheckBox( trans.get("TCMotorSelPan.checkbox.limitdiameter"));
|
limitDiameterCheckBox = new JCheckBox( trans.get("TCMotorSelPan.checkbox.limitdiameter"));
|
||||||
@ -241,7 +251,7 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
});
|
});
|
||||||
sub.add( limitDiameterCheckBox, "gapleft para, spanx, growx, wrap" );
|
sub.add( limitDiameterCheckBox, "gapleft para, spanx, growx, wrap" );
|
||||||
|
|
||||||
diameterSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, diameterValues.length-1, 0, diameterValues.length-1);
|
diameterSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, diameterLabels.size()-1, 0, diameterLabels.size()-1);
|
||||||
diameterSlider.setBounded(true); // thumbs cannot cross
|
diameterSlider.setBounded(true); // thumbs cannot cross
|
||||||
diameterSlider.setMajorTickSpacing(1);
|
diameterSlider.setMajorTickSpacing(1);
|
||||||
diameterSlider.setPaintTicks(true);
|
diameterSlider.setPaintTicks(true);
|
||||||
@ -250,13 +260,13 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
diameterSlider.addChangeListener( new ChangeListener() {
|
diameterSlider.addChangeListener( new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
int minDiameter = diameterSlider.getValueAt(0);
|
final int minDiameter = diameterSlider.getValueAt(0);
|
||||||
MotorFilterPanel.this.filter.setMinimumDiameter(diameterValues[minDiameter]);
|
MotorFilterPanel.this.filter.setMinimumDiameter(motorDiameters[minDiameter]);
|
||||||
int maxDiameter = diameterSlider.getValueAt(1);
|
int maxDiameter = diameterSlider.getValueAt(1);
|
||||||
if( maxDiameter == diameterValues.length-1 ) {
|
if( maxDiameter == motorDiameters.length-1 ) {
|
||||||
MotorFilterPanel.this.filter.setMaximumDiameter(null);
|
MotorFilterPanel.this.filter.setMaximumDiameter(null);
|
||||||
} else {
|
} else {
|
||||||
MotorFilterPanel.this.filter.setMaximumDiameter(diameterValues[maxDiameter]);
|
MotorFilterPanel.this.filter.setMaximumDiameter(motorDiameters[maxDiameter]);
|
||||||
}
|
}
|
||||||
onSelectionChanged();
|
onSelectionChanged();
|
||||||
}
|
}
|
||||||
@ -284,32 +294,34 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
sub.add( limitByLengthCheckBox, "gapleft para, spanx, growx, wrap" );
|
sub.add( limitByLengthCheckBox, "gapleft para, spanx, growx, wrap" );
|
||||||
|
|
||||||
|
|
||||||
final DoubleModel minimumLength = new DoubleModel(filter, "MinimumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
minLengthModel = new DoubleModel(filter, "MinimumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
||||||
final DoubleModel maximumLength = new DoubleModel(filter, "MaximumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
maxLengthModel = new DoubleModel(filter, "MaximumLength", UnitGroup.UNITS_MOTOR_DIMENSIONS, 0);
|
||||||
|
|
||||||
JSpinner spin = new JSpinner(minimumLength.getSpinnerModel());
|
minLengthSpinner = new JSpinner(minLengthModel.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
minLengthSpinner.setEditor(new SpinnerEditor(minLengthSpinner));
|
||||||
minimumLength.addChangeListener( new ChangeListener() {
|
minLengthModel.addChangeListener( new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
lengthSlider.setValueAt(0, (int)(1000* minimumLength.getValue()));
|
lengthSlider.setValueAt(0, (int)(1000* minLengthModel.getValue()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sub.add(spin, "split 5, growx");
|
sub.add(minLengthSpinner, "split 5, growx");
|
||||||
limitByLengthModel.addEnableComponent(spin,false);
|
limitByLengthModel.addEnableComponent(minLengthSpinner,false);
|
||||||
sub.add(new UnitSelector(minimumLength), "");
|
minLengthUnitSelect = new UnitSelector(minLengthModel);
|
||||||
|
sub.add(minLengthUnitSelect, "");
|
||||||
|
|
||||||
spin = new JSpinner(maximumLength.getSpinnerModel());
|
maxLengthSpinner = new JSpinner(maxLengthModel.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
maxLengthSpinner.setEditor(new SpinnerEditor(maxLengthSpinner));
|
||||||
maximumLength.addChangeListener( new ChangeListener() {
|
maxLengthModel.addChangeListener( new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
lengthSlider.setValueAt(1, (int) (1000* maximumLength.getValue()));
|
lengthSlider.setValueAt(1, (int) (1000* maxLengthModel.getValue()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sub.add(spin, "growx");
|
sub.add(maxLengthSpinner, "growx");
|
||||||
limitByLengthModel.addEnableComponent(spin,false);
|
limitByLengthModel.addEnableComponent(maxLengthSpinner,false);
|
||||||
sub.add(new UnitSelector(maximumLength), "wrap");
|
maxLengthUnitSelect = new UnitSelector(maxLengthModel);
|
||||||
|
sub.add(maxLengthUnitSelect, "wrap");
|
||||||
|
|
||||||
lengthSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, 1000, 0, 1000);
|
lengthSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, 1000, 0, 1000);
|
||||||
lengthSlider.setBounded(true); // thumbs cannot cross
|
lengthSlider.setBounded(true); // thumbs cannot cross
|
||||||
@ -321,9 +333,9 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
|
||||||
int minLength = lengthSlider.getValueAt(0);
|
int minLength = lengthSlider.getValueAt(0);
|
||||||
minimumLength.setValue(minLength/1000.0);
|
minLengthModel.setValue(minLength/1000.0);
|
||||||
int maxLength = lengthSlider.getValueAt(1);
|
int maxLength = lengthSlider.getValueAt(1);
|
||||||
maximumLength.setValue(maxLength/1000.0);
|
maxLengthModel.setValue(maxLength/1000.0);
|
||||||
onSelectionChanged();
|
onSelectionChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -355,6 +367,9 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setLimitLength( ) {
|
private void setLimitLength( ) {
|
||||||
|
minLengthUnitSelect.setSelectedUnit(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit());
|
||||||
|
maxLengthUnitSelect.setSelectedUnit(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit());
|
||||||
|
|
||||||
boolean limitByLength = limitByLengthCheckBox.isSelected();
|
boolean limitByLength = limitByLengthCheckBox.isSelected();
|
||||||
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitLength", limitByLength);
|
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitLength", limitByLength);
|
||||||
if ( mountLength != null & limitByLength ) {
|
if ( mountLength != null & limitByLength ) {
|
||||||
@ -364,15 +379,20 @@ public abstract class MotorFilterPanel extends JPanel {
|
|||||||
|
|
||||||
private void setLimitDiameter( ) {
|
private void setLimitDiameter( ) {
|
||||||
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitDiameter", limitDiameter);
|
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitDiameter", limitDiameter);
|
||||||
|
|
||||||
|
// motorDiameters, diameterLabels =
|
||||||
|
scaleDiameterLabels();
|
||||||
|
diameterSlider.setLabelTable(diameterLabels);
|
||||||
|
|
||||||
if ( limitDiameter && mountDiameter != null) {
|
if ( limitDiameter && mountDiameter != null) {
|
||||||
// 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 < motorDiameters.length; i++ ) {
|
||||||
if ( mountDiameter< diameterValues[i] - 0.0005 ) {
|
if ( mountDiameter < motorDiameters[i] - 0.0005 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i >= diameterValues.length ) {
|
if (i >= motorDiameters.length ) {
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
diameterSlider.setValueAt(1, i-1);
|
diameterSlider.setValueAt(1, i-1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user