From 651ba88a475daa8ec504eb0bd5e23e10a96cc038 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 23 Jul 2022 14:36:33 +0200 Subject: [PATCH] Clean up code... --- .../openrocket/gui/main/SimulationPanel.java | 498 +++++++++--------- 1 file changed, 249 insertions(+), 249 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index be9359509..efd353b90 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -151,255 +151,7 @@ public class SimulationPanel extends JPanel { //////// The simulation table - - simulationTableModel = new ColumnTableModel( - - //// Status and warning column - new Column("") { - private JLabel label = null; - - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - // Initialize the label - if (label == null) { - label = new StyledLabel(2f); - label.setIconTextGap(1); - // label.setFont(label.getFont().deriveFont(Font.BOLD)); - } - - // Set simulation status icon - Simulation.Status status = document.getSimulation(row).getStatus(); - label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status)); - - - // Set warning marker - if (status == Simulation.Status.NOT_SIMULATED || - status == Simulation.Status.EXTERNAL) { - - label.setText(""); - - } else { - - WarningSet w = document.getSimulation(row).getSimulatedWarnings(); - if (w == null) { - label.setText(""); - } else if (w.isEmpty()) { - label.setForeground(OK_COLOR); - label.setText(OK_TEXT); - } else { - label.setForeground(WARNING_COLOR); - label.setText(WARNING_TEXT); - } - } - - return label; - } - - @Override - public int getExactWidth() { - return 36; - } - - @Override - public Class getColumnClass() { - return JLabel.class; - } - }, - - //// Simulation name - //// Name - new Column(trans.get("simpanel.col.Name")) { - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - return document.getSimulation(row).getName(); - } - - @Override - public int getDefaultWidth() { - return 125; - } - - @Override - public Comparator getComparator() { - return new AlphanumComparator(); - } - }, - - //// Simulation configuration - new Column(trans.get("simpanel.col.Configuration")) { - @Override - public Object getValueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()){ - return null; - } - - Rocket rkt = document.getRocket(); - FlightConfigurationId fcid = document.getSimulation(row).getId(); - return descriptor.format( rkt, fcid); - } - - @Override - public int getDefaultWidth() { - return 125; - } - }, - - //// Launch rod velocity - new ValueColumn(trans.get("simpanel.col.Velocityoffrod"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getLaunchRodVelocity(); - } - - }, - - //// Apogee - new ValueColumn(trans.get("simpanel.col.Apogee"), UnitGroup.UNITS_DISTANCE) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxAltitude(); - } - }, - - //// Velocity at deployment - new ValueColumn(trans.get("simpanel.col.Velocityatdeploy"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getDeploymentVelocity(); - } - }, - - //// Deployment Time from Apogee - new ValueColumn(trans.get("simpanel.col.OptimumCoastTime"), - trans.get("simpanel.col.OptimumCoastTime.ttip"), - UnitGroup.UNITS_SHORT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null || data.getBranchCount() == 0) - return null; - - double val = data.getBranch(0).getOptimumDelay(); - if ( Double.isNaN(val) ) { - return null; - } - return val; - } - }, - - //// Maximum velocity - new ValueColumn(trans.get("simpanel.col.Maxvelocity"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxVelocity(); - } - }, - - //// Maximum acceleration - new ValueColumn(trans.get("simpanel.col.Maxacceleration"), UnitGroup.UNITS_ACCELERATION) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getMaxAcceleration(); - } - }, - - //// Time to apogee - new ValueColumn(trans.get("simpanel.col.Timetoapogee"), UnitGroup.UNITS_FLIGHT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getTimeToApogee(); - } - }, - - //// Flight time - new ValueColumn(trans.get("simpanel.col.Flighttime"), UnitGroup.UNITS_FLIGHT_TIME) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getFlightTime(); - } - }, - - //// Ground hit velocity - new ValueColumn(trans.get("simpanel.col.Groundhitvelocity"), UnitGroup.UNITS_VELOCITY) { - @Override - public Double valueAt(int row) { - if (row < 0 || row >= document.getSimulationCount()) - return null; - - FlightData data = document.getSimulation(row).getSimulatedData(); - if (data == null) - return null; - - return data.getGroundHitVelocity(); - } - } - - ) { - - private static final long serialVersionUID = 8686456963492628476L; - - @Override - public int getRowCount() { - return document.getSimulationCount(); - } - }; + simulationTableModel = new SimulationTableModel(); // Override processKeyBinding so that the JTable does not catch // key bindings used in menu accelerators @@ -971,6 +723,254 @@ public class SimulationPanel extends JPanel { return tip; } + } + private class SimulationTableModel extends ColumnTableModel { + private static final long serialVersionUID = 8686456963492628476L; + + public SimulationTableModel() { + super( + //// Status and warning column + new Column("") { + private JLabel label = null; + + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + // Initialize the label + if (label == null) { + label = new StyledLabel(2f); + label.setIconTextGap(1); + // label.setFont(label.getFont().deriveFont(Font.BOLD)); + } + + // Set simulation status icon + Simulation.Status status = document.getSimulation(row).getStatus(); + label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status)); + + + // Set warning marker + if (status == Simulation.Status.NOT_SIMULATED || + status == Simulation.Status.EXTERNAL) { + + label.setText(""); + + } else { + + WarningSet w = document.getSimulation(row).getSimulatedWarnings(); + if (w == null) { + label.setText(""); + } else if (w.isEmpty()) { + label.setForeground(OK_COLOR); + label.setText(OK_TEXT); + } else { + label.setForeground(WARNING_COLOR); + label.setText(WARNING_TEXT); + } + } + + return label; + } + + @Override + public int getExactWidth() { + return 36; + } + + @Override + public Class getColumnClass() { + return JLabel.class; + } + }, + + //// Simulation name + //// Name + new Column(trans.get("simpanel.col.Name")) { + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + return document.getSimulation(row).getName(); + } + + @Override + public int getDefaultWidth() { + return 125; + } + + @Override + public Comparator getComparator() { + return new AlphanumComparator(); + } + }, + + //// Simulation configuration + new Column(trans.get("simpanel.col.Configuration")) { + @Override + public Object getValueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) { + return null; + } + + Rocket rkt = document.getRocket(); + FlightConfigurationId fcid = document.getSimulation(row).getId(); + return descriptor.format(rkt, fcid); + } + + @Override + public int getDefaultWidth() { + return 125; + } + }, + + //// Launch rod velocity + new ValueColumn(trans.get("simpanel.col.Velocityoffrod"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getLaunchRodVelocity(); + } + + }, + + //// Apogee + new ValueColumn(trans.get("simpanel.col.Apogee"), UnitGroup.UNITS_DISTANCE) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxAltitude(); + } + }, + + //// Velocity at deployment + new ValueColumn(trans.get("simpanel.col.Velocityatdeploy"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getDeploymentVelocity(); + } + }, + + //// Deployment Time from Apogee + new ValueColumn(trans.get("simpanel.col.OptimumCoastTime"), + trans.get("simpanel.col.OptimumCoastTime.ttip"), UnitGroup.UNITS_SHORT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null || data.getBranchCount() == 0) + return null; + + double val = data.getBranch(0).getOptimumDelay(); + if (Double.isNaN(val)) { + return null; + } + return val; + } + }, + + //// Maximum velocity + new ValueColumn(trans.get("simpanel.col.Maxvelocity"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxVelocity(); + } + }, + + //// Maximum acceleration + new ValueColumn(trans.get("simpanel.col.Maxacceleration"), UnitGroup.UNITS_ACCELERATION) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getMaxAcceleration(); + } + }, + + //// Time to apogee + new ValueColumn(trans.get("simpanel.col.Timetoapogee"), UnitGroup.UNITS_FLIGHT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getTimeToApogee(); + } + }, + + //// Flight time + new ValueColumn(trans.get("simpanel.col.Flighttime"), UnitGroup.UNITS_FLIGHT_TIME) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getFlightTime(); + } + }, + + //// Ground hit velocity + new ValueColumn(trans.get("simpanel.col.Groundhitvelocity"), UnitGroup.UNITS_VELOCITY) { + @Override + public Double valueAt(int row) { + if (row < 0 || row >= document.getSimulationCount()) + return null; + + FlightData data = document.getSimulation(row).getSimulatedData(); + if (data == null) + return null; + + return data.getGroundHitVelocity(); + } + } + ); + } + + @Override + public int getRowCount() { + return document.getSimulationCount(); + } } }