Minor improvements

This commit is contained in:
SiboVG 2024-01-12 00:18:01 +01:00
parent d75a345f4e
commit 49cdbe5426
3 changed files with 33 additions and 21 deletions

View File

@ -362,6 +362,16 @@ public class Simulation implements ChangeSource, Cloneable {
return false;
}
/**
* Determines whether the specified branch in the simulation has errors
*
* @param branch the branch to check for errors
*/
public boolean hasErrors(int branch) {
FlightData data = getSimulatedData();
return data.getBranch(branch).getFirstEvent(FlightEvent.Type.SIM_ABORT) != null;
}
/**
* Returns true if the status indicates that the simulation data is up-to-date.
* @param status status of the simulation to check for if its data is up-to-date

View File

@ -833,7 +833,7 @@ public class SimulationPlot {
private XYTitleAnnotation createAnnotation(int branchNo) {
String abortString = "";
StringBuilder abortString = new StringBuilder();
for (int b = Math.max(0, branchNo);
b < ((branchNo < 0) ?
@ -842,17 +842,18 @@ public class SimulationPlot {
FlightDataBranch branch = simulation.getSimulatedData().getBranch(b);
FlightEvent abortEvent = branch.getFirstEvent(FlightEvent.Type.SIM_ABORT);
if (abortEvent != null) {
if (abortString == "") {
abortString = trans.get("simulationplot.abort.title");
if (abortString.isEmpty()) {
abortString = new StringBuilder(trans.get("simulationplot.abort.title"));
}
abortString += "\n" + trans.get("simulationplot.abort.stage") + ": " + branch.getBranchName() +
", " + trans.get("simulationplot.abort.time") + ": " + abortEvent.getTime() +
", " + trans.get("simulationplot.abort.cause") + ": " + ((SimulationAbort)abortEvent.getData()).getMessageDescription();
abortString.append("\n")
.append(trans.get("simulationplot.abort.stage")).append(": ").append(branch.getBranchName()).append("; ")
.append(trans.get("simulationplot.abort.time")).append(": ").append(abortEvent.getTime()).append(" s; ")
.append(trans.get("simulationplot.abort.cause")).append(": ").append(((SimulationAbort) abortEvent.getData()).getMessageDescription());
}
}
if (abortString != "") {
TextTitle abortsTitle = new TextTitle(abortString,
if (!abortString.toString().isEmpty()) {
TextTitle abortsTitle = new TextTitle(abortString.toString(),
new Font(Font.SANS_SERIF, Font.BOLD, 14), Color.RED,
RectangleEdge.TOP,
HorizontalAlignment.LEFT, VerticalAlignment.TOP,

View File

@ -46,6 +46,7 @@ public class SimulationPlotDialog extends JDialog {
private static final Translator trans = Application.getTranslator();
private static Color darkWarningColor;
private final JCheckBox checkErrors;
static {
initColors();
@ -61,7 +62,7 @@ public class SimulationPlotDialog extends JDialog {
final SimulationPlot myPlot = new SimulationPlot(simulation, config, initialShowPoints);
// Create the dialog
JPanel panel = new JPanel(new MigLayout("fill","[]","[grow][]"));
JPanel panel = new JPanel(new MigLayout("fill, hidemode 3","[]","[grow][]"));
this.add(panel);
final ChartPanel chartPanel = new SimulationChart(myPlot.getJFreeChart());
@ -99,18 +100,17 @@ public class SimulationPlotDialog extends JDialog {
panel.add(checkData, "split, left");
//// Show errors if any
//// ALWAYS show errors initially; make user turn it off for themselves
if (simulation.hasErrors()) {
final JCheckBox checkErrors = new JCheckBox(trans.get("PlotDialog.CheckBox.ShowErrors"));
checkErrors.setSelected(true);
checkErrors.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myPlot.setShowErrors(checkErrors.isSelected());
}
});
panel.add(checkErrors, "split, left");
}
//// Always enable 'show errors' initially; make user turn it off for themselves
checkErrors = new JCheckBox(trans.get("PlotDialog.CheckBox.ShowErrors"));
checkErrors.setSelected(true);
checkErrors.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myPlot.setShowErrors(checkErrors.isSelected());
}
});
panel.add(checkErrors, "split, left");
checkErrors.setVisible(simulation.hasErrors());
//// Add series selection box
ArrayList<String> stages = new ArrayList<String>();
@ -123,6 +123,7 @@ public class SimulationPlotDialog extends JDialog {
@Override
public void itemStateChanged(ItemEvent e) {
int selectedStage = stageSelection.getSelectedIndex() - 1;
checkErrors.setVisible(selectedStage == -1 ? simulation.hasErrors() : simulation.hasErrors(selectedStage));
myPlot.setShowBranch(selectedStage);
}