Separate warnings tooltip to sim table columns
This commit is contained in:
parent
3d343528a5
commit
13f47a755d
@ -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.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.noWarnings = <font color=\"gray\">No warnings.</font>
|
||||
simpanel.ttip.warnings = <font color=\"red\">Warnings:</font>
|
||||
simpanel.ttip.noWarnings = No warnings.
|
||||
simpanel.ttip.criticalWarnings = Critical Warnings:
|
||||
simpanel.ttip.normalWarnings = Warnings:
|
||||
simpanel.ttip.informativeWarnings = Informative:
|
||||
simpanel.ttip.simAbort = Simulation Abort
|
||||
simpanel.msg.invalidCopySelection = Invalid copy selection
|
||||
|
||||
|
@ -4,7 +4,26 @@ package net.sf.openrocket.logging;
|
||||
* The priority of a message.
|
||||
*/
|
||||
public enum MessagePriority {
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH
|
||||
LOW("LOW"),
|
||||
NORMAL("NORMAL"),
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import net.sf.openrocket.util.Mutable;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
mutable.immute();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.sf.openrocket.gui.main;
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
@ -19,6 +20,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serial;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Box;
|
||||
@ -43,16 +45,18 @@ import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import net.sf.openrocket.arch.SystemInfo;
|
||||
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.GUIUtil;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.gui.util.UITheme;
|
||||
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.LoggerFactory;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.logging.SimulationAbort;
|
||||
import net.sf.openrocket.logging.Warning;
|
||||
import net.sf.openrocket.logging.WarningSet;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
@ -123,6 +127,16 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
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) {
|
||||
super(new MigLayout("fill", "[grow][][][][][][grow]"));
|
||||
|
||||
@ -244,15 +258,14 @@ public class SimulationPanel extends JPanel {
|
||||
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) {
|
||||
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
|
||||
if (column > 1) {
|
||||
else if (column > 1) {
|
||||
simulationTable.clearSelection();
|
||||
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
|
||||
|
||||
@ -316,6 +329,18 @@ public class SimulationPanel extends JPanel {
|
||||
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.
|
||||
* @return the action used for editing selected simulations.
|
||||
@ -806,25 +831,55 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
tip = new StringBuilder("<html>");
|
||||
if (includeSimName) {
|
||||
tip.append("<b>").append(sim.getName()).append("</b><br>");
|
||||
tip.append("<b>").append(sim.getName()).append("</b>");
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
tip.append(trans.get("simpanel.ttip.noData"));
|
||||
tip.append("<br>").append(trans.get("simpanel.ttip.noData"));
|
||||
return tip.toString();
|
||||
}
|
||||
|
||||
WarningSet warnings = data.getWarningSet();
|
||||
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();
|
||||
}
|
||||
|
||||
tip.append(trans.get("simpanel.ttip.warnings"));
|
||||
for (Warning w : warnings) {
|
||||
tip.append("<br>").append(w.toString());
|
||||
List<Message> criticalWarnings = warnings.getMessagesWithPriority(MessagePriority.HIGH);
|
||||
List<Message> normalWarnings = warnings.getMessagesWithPriority(MessagePriority.NORMAL);
|
||||
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();
|
||||
}
|
||||
|
||||
@ -1190,6 +1245,7 @@ public class SimulationPanel extends JPanel {
|
||||
|
||||
public WarningsBox(Simulation simulation) {
|
||||
super(BoxLayout.X_AXIS); // Horizontal box
|
||||
setOpaque(false);
|
||||
this.simulation = simulation;
|
||||
updateContent();
|
||||
}
|
||||
@ -1258,11 +1314,29 @@ public class SimulationPanel extends JPanel {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setToolTipText(box.getToolTipText());
|
||||
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 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 {
|
||||
|
@ -2,6 +2,8 @@ package net.sf.openrocket.gui.util;
|
||||
|
||||
import net.sf.openrocket.util.ORColor;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class ColorConversion {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ public class UITheme {
|
||||
|
||||
@Override
|
||||
public Color getWarningColor() {
|
||||
return new Color(180, 90, 17);
|
||||
return new Color(192, 135, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user