From 54ca2bbe0e3c72546873304c6e1e5258b1112855 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 8 Sep 2022 23:31:05 +0200 Subject: [PATCH 1/4] [#1643] Round motor filter panel diameter labels --- .../gui/dialogs/motor/thrustcurve/MotorFilterPanel.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index 8dc619ac8..ac61bd458 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -38,6 +38,7 @@ import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.unit.Unit; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.gui.widgets.SelectColorButton; @@ -64,8 +65,13 @@ public abstract class MotorFilterPanel extends JPanel { * updates: motorDiameters, diameterLabels */ private static void scaleDiameterLabels(){ + Unit unit = UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit(); for( int i = 0; i < motorDiameters.length; i++ ) { - diameterLabels.put( i, new JLabel(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toString(motorDiameters[i]))); + // Round the labels, because for imperial units, the labels can otherwise overlap + double diam = unit.toUnit(motorDiameters[i]); + diam = unit.round(diam); + diam = unit.fromUnit(diam); + diameterLabels.put( i, new JLabel(unit.toString(diam))); } diameterLabels.get( motorDiameters.length-1).setText("+"); } From 9d3c6d83643a2ed9743f1e201f43eeacc589669e Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 21 Sep 2022 01:04:06 +0200 Subject: [PATCH 2/4] Clean up limit by length & diameter checkbox model --- .../motor/thrustcurve/MotorFilterPanel.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index ac61bd458..42907a5d3 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -102,6 +102,7 @@ public abstract class MotorFilterPanel extends JPanel { final JSpinner maxLengthSpinner; final UnitSelector maxLengthUnitSelect; private boolean limitDiameter = false; + boolean limitByLength = false; private Double mountDiameter = null; @@ -119,7 +120,7 @@ public abstract class MotorFilterPanel extends JPanel { List unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers(); filter.setExcludedManufacturers(unselectedManusFromPreferences); - boolean limitByLengthPref = ((SwingPreferences) Application.getPreferences()).getBoolean("motorFilterLimitLength", false); + limitByLength = ((SwingPreferences) Application.getPreferences()).getBoolean("motorFilterLimitLength", false); limitDiameter = ((SwingPreferences) Application.getPreferences()).getBoolean("motorFilterLimitDiameter", false); //// Hide used motor files @@ -245,9 +246,10 @@ public abstract class MotorFilterPanel extends JPanel { // Motor Dimension selection { sub.add( new JLabel(trans.get("TCMotorSelPan.Diameter")), "split 2, wrap"); - limitDiameterCheckBox = new JCheckBox( trans.get("TCMotorSelPan.checkbox.limitdiameter")); + final BooleanModel limitByDiameterModel = new BooleanModel(limitDiameter); + limitDiameterCheckBox = new JCheckBox(limitByDiameterModel); + limitDiameterCheckBox.setText(trans.get("TCMotorSelPan.checkbox.limitdiameter")); GUIUtil.changeFontSize(limitDiameterCheckBox, -1); - limitDiameterCheckBox.setSelected(limitDiameter); limitDiameterCheckBox.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { @@ -279,12 +281,13 @@ public abstract class MotorFilterPanel extends JPanel { } }); sub.add( diameterSlider, "growx, wrap"); + limitByDiameterModel.addEnableComponent(diameterSlider, false); } { // length selection sub.add( new JLabel(trans.get("TCMotorSelPan.Length")), "split 2, wrap"); - final BooleanModel limitByLengthModel = new BooleanModel(limitByLengthPref); + final BooleanModel limitByLengthModel = new BooleanModel(limitByLength); limitByLengthCheckBox = new JCheckBox( limitByLengthModel ); limitByLengthCheckBox.setText( trans.get("TCMotorSelPan.checkbox.limitlength")); GUIUtil.changeFontSize(limitByLengthCheckBox, -1); @@ -292,7 +295,7 @@ public abstract class MotorFilterPanel extends JPanel { limitByLengthCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - //boolean limitByLength = limitByLengthCheckBox.isSelected(); + limitByLength = limitByLengthCheckBox.isSelected(); MotorFilterPanel.this.setLimitLength(); onSelectionChanged(); } @@ -377,7 +380,6 @@ public abstract class MotorFilterPanel extends JPanel { minLengthUnitSelect.setSelectedUnit(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit()); maxLengthUnitSelect.setSelectedUnit(UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit()); - boolean limitByLength = limitByLengthCheckBox.isSelected(); ((SwingPreferences) Application.getPreferences()).putBoolean("motorFilterLimitLength", limitByLength); if ( mountLength != null & limitByLength ) { lengthSlider.setValueAt(1, (int) Math.min(1000,Math.round(1000*mountLength))); From 5cafd876089280d6b963a630bd6552c6a54611b5 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 21 Sep 2022 01:57:48 +0200 Subject: [PATCH 3/4] Use double-precision diameter labels --- .../dialogs/motor/thrustcurve/MotorFilterPanel.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index 42907a5d3..5276daa8d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -69,9 +69,14 @@ public abstract class MotorFilterPanel extends JPanel { for( int i = 0; i < motorDiameters.length; i++ ) { // Round the labels, because for imperial units, the labels can otherwise overlap double diam = unit.toUnit(motorDiameters[i]); - diam = unit.round(diam); - diam = unit.fromUnit(diam); - diameterLabels.put( i, new JLabel(unit.toString(diam))); + double diamRounded = unit.round(diam * 10) / 10; // 10 multiplication for 2-decimal precision + diam = unit.fromUnit(diamRounded); + String formatted = unit.toString(diam); + // Remove the leading zero for numbers between 0 and 1 + if (diamRounded > 0 && diamRounded < 1) { + formatted = formatted.substring(1); + } + diameterLabels.put( i, new JLabel(formatted)); } diameterLabels.get( motorDiameters.length-1).setText("+"); } From 582021e3747b7ae7acc54a8d5dfbae74d95bf3f7 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 22 Sep 2022 23:13:40 +0200 Subject: [PATCH 4/4] Don't paint ticks in length slider --- .../gui/dialogs/motor/thrustcurve/MotorFilterPanel.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index 5276daa8d..49674d686 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -340,9 +340,6 @@ public abstract class MotorFilterPanel extends JPanel { 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) {