diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index b48b42d5f..169cd9cdd 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1401,6 +1401,7 @@ TCurveMotorCol.DESIGNATION = Designation TCurveMotorCol.TYPE = Type TCurveMotorCol.DIAMETER = Diameter TCurveMotorCol.LENGTH = Length +TCurveMotorCol.TOTAL_IMPULSE = Total Impulse TCurveMotor.ttip.diameter = Diameter: TCurveMotor.ttip.length = Length: diff --git a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java index 14d190536..c15452ae3 100644 --- a/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java +++ b/core/src/net/sf/openrocket/database/motor/ThrustCurveMotorSet.java @@ -41,6 +41,7 @@ public class ThrustCurveMotorSet implements Comparable { private String simplifiedDesignation = null; private double diameter = -1; private double length = -1; + private long totalImpulse = 0; private Motor.Type type = Motor.Type.UNKNOWN; @@ -54,6 +55,7 @@ public class ThrustCurveMotorSet implements Comparable { simplifiedDesignation = simplifyDesignation(designation); diameter = motor.getDiameter(); length = motor.getLength(); + totalImpulse = Math.round((motor.getTotalImpulseEstimate())); } // Verify that the motor can be added @@ -218,7 +220,13 @@ public class ThrustCurveMotorSet implements Comparable { return type; } - + /** + * Return the estimated total impulse for this motor type. + * @return estimated total impulse + */ + public long getTotalImpuse() { + return totalImpulse; + } @Override diff --git a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java index c99c7b5b6..47d931dd9 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java +++ b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorColumns.java @@ -42,6 +42,22 @@ enum ThrustCurveMotorColumns { return new DesignationComparator(); } }, + //// TotalImpulse + TOTAL_IMPULSE("TCurveMotorCol.TOTAL_IMPULSE") { + @Override + public Object getValue(ThrustCurveMotorSet m) { + return m.getTotalImpuse(); + } + + @Override + public Comparator getComparator() { + return new Comparator() { + public int compare(Long o1, Long o2) { + return o1.compareTo(o2); + } + }; + } + }, //// Type TYPE("TCurveMotorCol.TYPE") { @Override @@ -79,7 +95,7 @@ enum ThrustCurveMotorColumns { } }; - + private final String title; private final int width; private static final Translator trans = Application.getTranslator(); diff --git a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index ef32897a6..e9781b210 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -12,6 +12,7 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -34,6 +35,8 @@ import javax.swing.JTextField; import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; +import javax.swing.RowSorter; +import javax.swing.SortOrder; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -262,6 +265,15 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec table.getColumnModel().getColumn(i).setPreferredWidth(column.getWidth()); } table.setRowSorter(sorter); + // force initial sort order to by diameter, total impulse, manufacturer + { + RowSorter.SortKey[] sortKeys = { + new RowSorter.SortKey(ThrustCurveMotorColumns.DIAMETER.ordinal(), SortOrder.ASCENDING), + new RowSorter.SortKey(ThrustCurveMotorColumns.TOTAL_IMPULSE.ordinal(), SortOrder.ASCENDING), + new RowSorter.SortKey(ThrustCurveMotorColumns.MANUFACTURER.ordinal(), SortOrder.ASCENDING) + }; + sorter.setSortKeys(Arrays.asList(sortKeys)); + } // Set selection and double-click listeners table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @@ -558,7 +570,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec } - @Override public Motor getSelectedMotor() { return selectedMotor;