Merge pull request #163 from kruland2607/master
Added sorting to simulation list.
This commit is contained in:
commit
d1efbdf766
@ -1090,7 +1090,7 @@ TCMotorSelPan.checkbox.limitdiameter = Limit motor diameter to mount diameter
|
||||
TCMotorSelPan.btn.details = Show Details
|
||||
TCMotorSelPan.btn.filter = Filter Motors
|
||||
TCMotorSelPan.MotorSize = Motor Dimensions
|
||||
TCMotorSelPan.Diameter = Daimeter
|
||||
TCMotorSelPan.Diameter = Diameter
|
||||
TCMotorSelPan.Length = Length
|
||||
TCMotorSelPan.MotorMountDimensions = Motor mount dimensions:
|
||||
TCMotorSelPan.lbl.Search = Search:
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.sf.openrocket.gui.adaptors;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.table.TableColumnModel;
|
||||
|
||||
public abstract class Column {
|
||||
@ -75,4 +77,15 @@ public abstract class Column {
|
||||
public void setValueAt(int row, Object value ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Comparator to use with this column.
|
||||
*
|
||||
* If null, the assumption is the default comparator will be used for this column
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Comparator getComparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ public abstract class ColumnTableModel extends AbstractTableModel {
|
||||
}
|
||||
}
|
||||
|
||||
public Column getColumn(int i) {
|
||||
return columns[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columns.length;
|
||||
|
@ -0,0 +1,37 @@
|
||||
package net.sf.openrocket.gui.adaptors;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.table.TableRowSorter;
|
||||
|
||||
public class ColumnTableRowSorter extends TableRowSorter {
|
||||
|
||||
private final ColumnTableModel columnTableModel;
|
||||
|
||||
public ColumnTableRowSorter(ColumnTableModel model) {
|
||||
super(model);
|
||||
this.columnTableModel = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator(int column) {
|
||||
Comparator c = columnTableModel.getColumn(column).getComparator();
|
||||
return (c!= null) ? c : super.getComparator(column);
|
||||
}
|
||||
|
||||
/*
|
||||
* We have to override this function because the base class (TableRowSorter) calls
|
||||
* super.getComparator( int ) to determine if string comparison is required.
|
||||
* Since the super class is DefaultRowSorter, it determines incorrectly that we are defining
|
||||
* our own sorter.
|
||||
*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.table.TableRowSorter#useToString(int)
|
||||
*/
|
||||
@Override
|
||||
protected boolean useToString(int column) {
|
||||
Comparator c = columnTableModel.getColumn(column).getComparator();
|
||||
return ( c != null ) ? false : super.useToString(column);
|
||||
}
|
||||
|
||||
}
|
39
swing/src/net/sf/openrocket/gui/adaptors/ValueColumn.java
Normal file
39
swing/src/net/sf/openrocket/gui/adaptors/ValueColumn.java
Normal file
@ -0,0 +1,39 @@
|
||||
package net.sf.openrocket.gui.adaptors;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.unit.Value;
|
||||
import net.sf.openrocket.unit.ValueComparator;
|
||||
|
||||
public abstract class ValueColumn extends Column {
|
||||
|
||||
private final UnitGroup unit;
|
||||
|
||||
public ValueColumn( String name, UnitGroup unit ) {
|
||||
super(name);
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
Double d = valueAt(row);
|
||||
return (d == null ) ? null : new Value( valueAt( row ) , unit );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return ValueComparator.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the double value to show in the Value object
|
||||
*
|
||||
* If the row index is out of bounds of the model, return null.
|
||||
*
|
||||
* @param row
|
||||
* @return
|
||||
*/
|
||||
public abstract Double valueAt( int row );
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
@ -35,6 +36,8 @@ import net.sf.openrocket.document.events.SimulationChangeEvent;
|
||||
import net.sf.openrocket.formatting.RocketDescriptor;
|
||||
import net.sf.openrocket.gui.adaptors.Column;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableRowSorter;
|
||||
import net.sf.openrocket.gui.adaptors.ValueColumn;
|
||||
import net.sf.openrocket.gui.components.StyledLabel;
|
||||
import net.sf.openrocket.gui.simulation.SimulationEditDialog;
|
||||
import net.sf.openrocket.gui.simulation.SimulationRunDialog;
|
||||
@ -48,6 +51,7 @@ import net.sf.openrocket.simulation.FlightData;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.startup.Preferences;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.AlphanumComparator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -316,6 +320,11 @@ public class SimulationPanel extends JPanel {
|
||||
public int getDefaultWidth() {
|
||||
return 125;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator getComparator() {
|
||||
return new AlphanumComparator();
|
||||
}
|
||||
},
|
||||
|
||||
//// Simulation configuration
|
||||
@ -335,9 +344,9 @@ public class SimulationPanel extends JPanel {
|
||||
},
|
||||
|
||||
//// Launch rod velocity
|
||||
new Column(trans.get("simpanel.col.Velocityoffrod")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Velocityoffrod"), UnitGroup.UNITS_VELOCITY) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -345,15 +354,15 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_VELOCITY.getDefaultUnit().toStringUnit(
|
||||
data.getLaunchRodVelocity());
|
||||
return data.getLaunchRodVelocity();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
//// Apogee
|
||||
new Column(trans.get("simpanel.col.Apogee")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Apogee"), UnitGroup.UNITS_DISTANCE) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -361,15 +370,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_DISTANCE.getDefaultUnit().toStringUnit(
|
||||
data.getMaxAltitude());
|
||||
return data.getMaxAltitude();
|
||||
}
|
||||
},
|
||||
|
||||
//// Velocity at deployment
|
||||
new Column(trans.get("simpanel.col.Velocityatdeploy")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Velocityatdeploy"), UnitGroup.UNITS_VELOCITY) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -377,15 +385,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_VELOCITY.getDefaultUnit().toStringUnit(
|
||||
data.getDeploymentVelocity());
|
||||
return data.getDeploymentVelocity();
|
||||
}
|
||||
},
|
||||
|
||||
//// Maximum velocity
|
||||
new Column(trans.get("simpanel.col.Maxvelocity")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Maxvelocity"), UnitGroup.UNITS_VELOCITY) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -393,15 +400,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_VELOCITY.getDefaultUnit().toStringUnit(
|
||||
data.getMaxVelocity());
|
||||
return data.getMaxVelocity();
|
||||
}
|
||||
},
|
||||
|
||||
//// Maximum acceleration
|
||||
new Column(trans.get("simpanel.col.Maxacceleration")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Maxacceleration"), UnitGroup.UNITS_ACCELERATION) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -409,15 +415,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_ACCELERATION.getDefaultUnit().toStringUnit(
|
||||
data.getMaxAcceleration());
|
||||
return data.getMaxAcceleration();
|
||||
}
|
||||
},
|
||||
|
||||
//// Time to apogee
|
||||
new Column(trans.get("simpanel.col.Timetoapogee")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Timetoapogee"), UnitGroup.UNITS_FLIGHT_TIME) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -425,15 +430,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_FLIGHT_TIME.getDefaultUnit().toStringUnit(
|
||||
data.getTimeToApogee());
|
||||
return data.getTimeToApogee();
|
||||
}
|
||||
},
|
||||
|
||||
//// Flight time
|
||||
new Column(trans.get("simpanel.col.Flighttime")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Flighttime"), UnitGroup.UNITS_FLIGHT_TIME) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -441,15 +445,14 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_FLIGHT_TIME.getDefaultUnit().toStringUnit(
|
||||
data.getFlightTime());
|
||||
return data.getFlightTime();
|
||||
}
|
||||
},
|
||||
|
||||
//// Ground hit velocity
|
||||
new Column(trans.get("simpanel.col.Groundhitvelocity")) {
|
||||
new ValueColumn(trans.get("simpanel.col.Groundhitvelocity"), UnitGroup.UNITS_VELOCITY) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
public Double valueAt(int row) {
|
||||
if (row < 0 || row >= document.getSimulationCount())
|
||||
return null;
|
||||
|
||||
@ -457,8 +460,7 @@ public class SimulationPanel extends JPanel {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return UnitGroup.UNITS_VELOCITY.getDefaultUnit().toStringUnit(
|
||||
data.getGroundHitVelocity());
|
||||
return data.getGroundHitVelocity();
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,7 +482,8 @@ public class SimulationPanel extends JPanel {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
simulationTable.setAutoCreateRowSorter(true);
|
||||
ColumnTableRowSorter simulationTableSorter = new ColumnTableRowSorter(simulationTableModel);
|
||||
simulationTable.setRowSorter(simulationTableSorter);
|
||||
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
|
||||
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
|
||||
@ -591,6 +594,9 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private enum SimulationTableColumns {
|
||||
|
||||
}
|
||||
|
||||
private class JLabelRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user