Separate warnings tooltip to sim table columns

This commit is contained in:
SiboVG 2024-02-16 01:03:10 +01:00
parent 3d343528a5
commit 13f47a755d
6 changed files with 141 additions and 19 deletions

View File

@ -634,8 +634,10 @@ simpanel.ttip.outdated = <i><font color=\"red\">Out of date</font></i><br>Click
simpanel.ttip.external = <i>Imported data</i> simpanel.ttip.external = <i>Imported data</i>
simpanel.ttip.notSimulated = <i>Not simulated yet</i><br>Click <i><b>Run simulations</b></i> to simulate. simpanel.ttip.notSimulated = <i>Not simulated yet</i><br>Click <i><b>Run simulations</b></i> to simulate.
simpanel.ttip.noData = No simulation data available. simpanel.ttip.noData = No simulation data available.
simpanel.ttip.noWarnings = <font color=\"gray\">No warnings.</font> simpanel.ttip.noWarnings = No warnings.
simpanel.ttip.warnings = <font color=\"red\">Warnings:</font> simpanel.ttip.criticalWarnings = Critical Warnings:
simpanel.ttip.normalWarnings = Warnings:
simpanel.ttip.informativeWarnings = Informative:
simpanel.ttip.simAbort = Simulation Abort simpanel.ttip.simAbort = Simulation Abort
simpanel.msg.invalidCopySelection = Invalid copy selection simpanel.msg.invalidCopySelection = Invalid copy selection

View File

@ -4,7 +4,26 @@ package net.sf.openrocket.logging;
* The priority of a message. * The priority of a message.
*/ */
public enum MessagePriority { public enum MessagePriority {
LOW, LOW("LOW"),
NORMAL, NORMAL("NORMAL"),
HIGH HIGH("HIGH");
private String exportLabel;
MessagePriority(String exportLabel) {
this.exportLabel = exportLabel;
}
public String getExportLabel() {
return exportLabel;
}
public static MessagePriority fromExportLabel(String exportLabel) {
for (MessagePriority priority : MessagePriority.values()) {
if (priority.exportLabel.equals(exportLabel)) {
return priority;
}
}
return NORMAL;
}
} }

View File

@ -8,6 +8,7 @@ import net.sf.openrocket.util.Mutable;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
/** /**
* A set that contains multiple <code>Message</code>s. When adding a * A set that contains multiple <code>Message</code>s. When adding a
@ -131,6 +132,22 @@ public abstract class MessageSet<E extends Message> extends AbstractSet<E> imple
return count; return count;
} }
/**
* Returns a list of messages with the specified priority.
*
* @param priority the priority of the messages to retrieve
* @return a list of messages with the specified priority
*/
public List<Message> getMessagesWithPriority(MessagePriority priority) {
List<Message> list = new ArrayList<>();
for (E m : messages) {
if (m.getPriority() == priority) {
list.add(m);
}
}
return list;
}
public void immute() { public void immute() {
mutable.immute(); mutable.immute();
} }

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.gui.main;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
@ -19,6 +20,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Serial; import java.io.Serial;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Box; import javax.swing.Box;
@ -43,16 +45,18 @@ import javax.swing.table.DefaultTableCellRenderer;
import net.sf.openrocket.arch.SystemInfo; import net.sf.openrocket.arch.SystemInfo;
import net.sf.openrocket.gui.components.CsvOptionPanel; import net.sf.openrocket.gui.components.CsvOptionPanel;
import net.sf.openrocket.gui.util.ColorConversion;
import net.sf.openrocket.gui.util.FileHelper; import net.sf.openrocket.gui.util.FileHelper;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.util.UITheme; import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.widgets.SaveFileChooser; import net.sf.openrocket.gui.widgets.SaveFileChooser;
import net.sf.openrocket.logging.Message;
import net.sf.openrocket.logging.MessagePriority;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.logging.SimulationAbort;
import net.sf.openrocket.logging.Warning; import net.sf.openrocket.logging.Warning;
import net.sf.openrocket.logging.WarningSet; import net.sf.openrocket.logging.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
@ -123,6 +127,16 @@ public class SimulationPanel extends JPanel {
private int[] previousSelection = null; private int[] previousSelection = null;
private static Color dimTextColor;
private static Color warningColor;
private static Color errorColor;
private static Color informationColor;
static {
initColors();
}
public SimulationPanel(OpenRocketDocument doc) { public SimulationPanel(OpenRocketDocument doc) {
super(new MigLayout("fill", "[grow][][][][][][grow]")); super(new MigLayout("fill", "[grow][][][][][][grow]"));
@ -244,15 +258,14 @@ public class SimulationPanel extends JPanel {
runSimulation(); runSimulation();
} }
} }
// Show the warnings for the simulation
else if (column == 1) {
int selected = simulationTable.convertRowIndexToModel(selectedRow);
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
}
} else if (e.getClickCount() == 2) { } else if (e.getClickCount() == 2) {
int selected = simulationTable.convertRowIndexToModel(selectedRow); int selected = simulationTable.convertRowIndexToModel(selectedRow);
// Show the warnings for the simulation
if (column == 1) {
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
}
// Edit the simulation or plot/export // Edit the simulation or plot/export
if (column > 1) { else if (column > 1) {
simulationTable.clearSelection(); simulationTable.clearSelection();
simulationTable.addRowSelectionInterval(selectedRow, selectedRow); simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
@ -316,6 +329,18 @@ public class SimulationPanel extends JPanel {
updateActions(); updateActions();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationPanel::updateColors);
}
private static void updateColors() {
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
warningColor = GUIUtil.getUITheme().getWarningColor();
errorColor = GUIUtil.getUITheme().getErrorColor();
informationColor = GUIUtil.getUITheme().getInformationColor();
}
/** /**
* Returns the action used for editing selected simulations. * Returns the action used for editing selected simulations.
* @return the action used for editing selected simulations. * @return the action used for editing selected simulations.
@ -806,24 +831,54 @@ public class SimulationPanel extends JPanel {
tip = new StringBuilder("<html>"); tip = new StringBuilder("<html>");
if (includeSimName) { if (includeSimName) {
tip.append("<b>").append(sim.getName()).append("</b><br>"); tip.append("<b>").append(sim.getName()).append("</b>");
} }
if (data == null) { if (data == null) {
tip.append(trans.get("simpanel.ttip.noData")); tip.append("<br>").append(trans.get("simpanel.ttip.noData"));
return tip.toString(); return tip.toString();
} }
WarningSet warnings = data.getWarningSet(); WarningSet warnings = data.getWarningSet();
if (warnings.isEmpty()) { if (warnings.isEmpty()) {
tip.append(trans.get("simpanel.ttip.noWarnings")); tip.append("<br>").append(ColorConversion.formatHTMLColor(dimTextColor, trans.get("simpanel.ttip.noWarnings")));
return tip.toString(); return tip.toString();
} }
tip.append(trans.get("simpanel.ttip.warnings")); List<Message> criticalWarnings = warnings.getMessagesWithPriority(MessagePriority.HIGH);
for (Warning w : warnings) { List<Message> normalWarnings = warnings.getMessagesWithPriority(MessagePriority.NORMAL);
tip.append("<br>").append(w.toString()); List<Message> informativeWarnings = warnings.getMessagesWithPriority(MessagePriority.LOW);
// Critical warnings
if (!criticalWarnings.isEmpty()) {
tip.append("<br><b>")
.append(ColorConversion.formatHTMLColor(errorColor, trans.get("simpanel.ttip.criticalWarnings")))
.append("</b>");
for (Message m : criticalWarnings) {
tip.append("<br>").append(m.toString());
} }
}
// Warnings
if (!normalWarnings.isEmpty()) {
tip.append("<br><b>")
.append(ColorConversion.formatHTMLColor(warningColor, trans.get("simpanel.ttip.normalWarnings")))
.append("</b>");
for (Message m : normalWarnings) {
tip.append("<br>").append(m.toString());
}
}
// Informative warnings
if (!informativeWarnings.isEmpty()) {
tip.append("<br><b>")
.append(ColorConversion.formatHTMLColor(informationColor, trans.get("simpanel.ttip.informativeWarnings")))
.append("</b>");
for (Message m : informativeWarnings) {
tip.append("<br>").append(m.toString());
}
}
return tip.toString(); return tip.toString();
} }
@ -1190,6 +1245,7 @@ public class SimulationPanel extends JPanel {
public WarningsBox(Simulation simulation) { public WarningsBox(Simulation simulation) {
super(BoxLayout.X_AXIS); // Horizontal box super(BoxLayout.X_AXIS); // Horizontal box
setOpaque(false);
this.simulation = simulation; this.simulation = simulation;
updateContent(); updateContent();
} }
@ -1258,11 +1314,29 @@ public class SimulationPanel extends JPanel {
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
panel.setToolTipText(box.getToolTipText()); panel.setToolTipText(box.getToolTipText());
panel.add(box, BorderLayout.EAST); // Align to the right within the panel panel.add(box, BorderLayout.EAST); // Align to the right within the panel
panel.setOpaque(true);
if (isSelected) {
panel.setBackground(table.getSelectionBackground());
updateBoxColors(box, table.getSelectionForeground());
} else {
panel.setBackground(table.getBackground());
updateBoxColors(box, table.getForeground());
}
return panel; return panel;
} }
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
} }
private void updateBoxColors(WarningsBox box, Color foreground) {
// Set the foreground for the box and its child components
box.setForeground(foreground); // Assuming this sets the box's own foreground
for (Component comp : box.getComponents()) {
if (comp instanceof JLabel) {
comp.setForeground(foreground);
}
}
}
} }
private class SimulationTableModel extends ColumnTableModel { private class SimulationTableModel extends ColumnTableModel {

View File

@ -2,6 +2,8 @@ package net.sf.openrocket.gui.util;
import net.sf.openrocket.util.ORColor; import net.sf.openrocket.util.ORColor;
import java.awt.Color;
public class ColorConversion { public class ColorConversion {
public static java.awt.Color toAwtColor( ORColor c ) { public static java.awt.Color toAwtColor( ORColor c ) {
@ -17,4 +19,12 @@ public class ColorConversion {
} }
return new ORColor( c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); return new ORColor( c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
} }
public static String formatHTMLColor(Color c, String content) {
if (c == null) {
return null;
}
String hexColor = String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue());
return String.format("<font color=\"%s\">%s</font>", hexColor, content);
}
} }

View File

@ -230,7 +230,7 @@ public class UITheme {
@Override @Override
public Color getWarningColor() { public Color getWarningColor() {
return new Color(180, 90, 17); return new Color(192, 135, 0);
} }
@Override @Override