Added limit diameter checkbox and preference. Refactored some code in

MotorFilterPanel to make it nicer.
This commit is contained in:
kruland2607 2013-10-11 13:56:13 -05:00
parent 42e70d3552
commit 858291de7c
2 changed files with 47 additions and 25 deletions

View File

@ -1086,6 +1086,7 @@ TCMotorSelPan.lbl.Selrocketmotor = Select rocket motor:
TCMotorSelPan.checkbox.hideSimilar = Hide very similar thrust curves
TCMotorSelPan.checkbox.hideUsed = Hide motors already used in the mount
TCMotorSelPan.checkbox.limitlength = Limit motor length to mount length
TCMotorSelPan.checkbox.limitdiameter = Limit motor diameter to mount diameter
TCMotorSelPan.btn.details = Show Details
TCMotorSelPan.btn.filter = Filter Motors
TCMotorSelPan.MotorSize = Motor Dimensions

View File

@ -83,6 +83,10 @@ public abstract class MotorFilterPanel extends JPanel {
private boolean limitLength = false;
private Double mountLength = null;
private final JCheckBox limitDiameterCheckBox;
private boolean limitDiameter = false;
private Double mountDiameter = null;
// Things we change the label on based on the MotorMount.
private final JLabel motorMountDimension;
private final MultiSlider lengthSlider;
@ -96,6 +100,7 @@ public abstract class MotorFilterPanel extends JPanel {
filter.setExcludedManufacturers(unselectedManusFromPreferences);
limitLength = ((SwingPreferences) Application.getPreferences()).getBoolean("motorFilterLimitLength", false);
limitDiameter = ((SwingPreferences) Application.getPreferences()).getBoolean("motorFilterLimitDiameter", false);
//// Hide used motor files
{
@ -111,7 +116,6 @@ public abstract class MotorFilterPanel extends JPanel {
this.add(hideUsedBox, "gapleft para, spanx, growx, wrap");
}
// Manufacturer selection
JPanel sub = new JPanel(new MigLayout("fill"));
TitledBorder border = BorderFactory.createTitledBorder(trans.get("TCurveMotorCol.MANUFACTURER"));
@ -206,7 +210,7 @@ public abstract class MotorFilterPanel extends JPanel {
this.add(sub,"grow, wrap");
// Diameter selection
// Motor Dimensions
sub = new JPanel(new MigLayout("fill"));
TitledBorder diameterTitleBorder = BorderFactory.createTitledBorder(trans.get("TCMotorSelPan.MotorSize"));
GUIUtil.changeFontStyle(diameterTitleBorder, Font.BOLD);
@ -215,8 +219,23 @@ public abstract class MotorFilterPanel extends JPanel {
motorMountDimension = new JLabel();
GUIUtil.changeFontSize(motorMountDimension, -1);
sub.add(motorMountDimension,"growx,wrap");
// Diameter selection
{
sub.add( new JLabel("Diameter"), "split 2, wrap");
sub.add( new JLabel(trans.get("TCMotorSelPan.Diameter")), "split 2, wrap");
limitDiameterCheckBox = new JCheckBox( trans.get("TCMotorSelPan.checkbox.limitdiameter"));
GUIUtil.changeFontSize(limitDiameterCheckBox, -1);
limitDiameterCheckBox.setSelected(limitDiameter);
limitDiameterCheckBox.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
limitDiameter = limitDiameterCheckBox.isSelected();
MotorFilterPanel.this.setLimitDiameter();
onSelectionChanged();
}
});
sub.add( limitDiameterCheckBox, "gapleft para, spanx, growx, wrap" );
diameterSlider = new MultiSlider(MultiSlider.HORIZONTAL,0, diameterValues.length-1, 0, diameterValues.length-1);
diameterSlider.setBounded(true); // thumbs cannot cross
diameterSlider.setMajorTickSpacing(1);
@ -242,14 +261,14 @@ public abstract class MotorFilterPanel extends JPanel {
{
sub.add( new JLabel(trans.get("TCMotorSelPan.Length")), "split 2, wrap");
limitLengthCheckBox = new JCheckBox( trans.get("TCMotorSelPan.checkbox.limitlength"));
GUIUtil.changeFontSize(limitLengthCheckBox, -1);
limitLengthCheckBox.setSelected(limitLength);
limitLengthCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MotorFilterPanel.this.setLimitLength( limitLengthCheckBox.isSelected());
limitLength = limitLengthCheckBox.isSelected();
MotorFilterPanel.this.setLimitLength();
onSelectionChanged();
}
});
@ -309,17 +328,30 @@ public abstract class MotorFilterPanel extends JPanel {
if ( mount == null ) {
// Disable diameter controls?
mountLength = null;
lengthSlider.setValueAt(1, 1000);
mountDiameter = null;
motorMountDimension.setText("");
} else {
mountLength = ((RocketComponent)mount).getLength();
if ( limitLength ) {
lengthSlider.setValueAt(1, (int) Math.min(1000,Math.round(1000*mountLength)));
} else {
lengthSlider.setValueAt(1, 1000);
}
mountDiameter = mount.getMotorMountDiameter();
motorMountDimension.setText( trans.get("TCMotorSelPan.MotorMountDimensions") + " " +
UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountDiameter)+ " x " + UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountLength));
}
setLimitLength();
setLimitDiameter();
}
double mountDiameter = mount.getMotorMountDiameter();
private void setLimitLength( ) {
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitLength", limitLength);
if ( mountLength != null & limitLength ) {
lengthSlider.setValueAt(1, (int) Math.min(1000,Math.round(1000*mountLength)));
} else {
lengthSlider.setValueAt(1, 1000);
}
}
private void setLimitDiameter( ) {
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitDiameter", limitDiameter);
if ( limitDiameter && mountDiameter != null) {
// find the next largest diameter
int i;
for( i =0; i< diameterValues.length; i++ ) {
@ -331,22 +363,11 @@ public abstract class MotorFilterPanel extends JPanel {
i--;
}
diameterSlider.setValueAt(1, i-1);
motorMountDimension.setText( trans.get("TCMotorSelPan.MotorMountDimensions") + " " +
UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountDiameter)+ " x " + UnitGroup.UNITS_MOTOR_DIMENSIONS.toStringUnit(mountLength));
}
}
private void setLimitLength( boolean limitLength ) {
this.limitLength = limitLength;
((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitLength", limitLength);
if ( mountLength != null & limitLength ) {
lengthSlider.setValueAt(1, (int) Math.min(1000,Math.round(1000*mountLength)));
} else {
lengthSlider.setValueAt(1, 1000);
diameterSlider.setValueAt(1, diameterValues.length-1);
}
}
public abstract void onSelectionChanged();
}