From 3f86a868ee326a27fdf8d6db8b2058cb1c4bf5f4 Mon Sep 17 00:00:00 2001 From: May Date: Mon, 24 Apr 2023 01:03:30 -0400 Subject: [PATCH 1/7] [#2161] Add setForeground and setBackground functions to DescriptionArea --- .../sf/openrocket/gui/components/DescriptionArea.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java index b60d4f6ad..39ca75da0 100644 --- a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java +++ b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java @@ -202,5 +202,15 @@ public class DescriptionArea extends JScrollPane { editorPane.setFont(font); } } + + public void setBackground(Color color) { + if (editorPane == null) return; + editorPane.setBackground(color); + } + + public void setForeground(Color color) { + if (editorPane == null) return; + editorPane.setForeground(color); + } } From 657f8b761ae4e583eaed8e1d0ba90137902be7a5 Mon Sep 17 00:00:00 2001 From: May Date: Mon, 24 Apr 2023 01:05:52 -0400 Subject: [PATCH 2/7] [#2161] Improve "data will be plotted in time order" warning --- .../gui/simulation/SimulationPlotPanel.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java index c28cc606c..bec59b70c 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java @@ -1,5 +1,6 @@ package net.sf.openrocket.gui.simulation; +import java.awt.Color; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -105,7 +106,8 @@ public class SimulationPlotPanel extends JPanel { private int modifying = 0; - + + private DescriptionArea simPlotPanelDesc; public SimulationPlotPanel(final Simulation simulation) { super(new MigLayout("fill")); @@ -170,6 +172,14 @@ public class SimulationPlotPanel extends JPanel { if (modifying > 0) return; FlightDataType type = (FlightDataType) domainTypeSelector.getSelectedItem(); + if (type == FlightDataType.TYPE_TIME) { + simPlotPanelDesc.setVisible(false); + simPlotPanelDesc.setText(""); + } + else { + simPlotPanelDesc.setVisible(true); + simPlotPanelDesc.setText(trans.get("simplotpanel.Desc")); + } configuration.setDomainAxisType(type); domainUnitSelector.setUnitGroup(type.getUnitGroup()); domainUnitSelector.setSelectedUnit(configuration.getDomainAxisUnit()); @@ -193,9 +203,13 @@ public class SimulationPlotPanel extends JPanel { this.add(domainUnitSelector, "width 40lp, gapright para"); //// The data will be plotted in time order even if the X axis type is not time. - DescriptionArea desc = new DescriptionArea(trans.get("simplotpanel.Desc"), 2, -2f); - desc.setViewportBorder(BorderFactory.createEmptyBorder()); - this.add(desc, "width 1px, growx 1, wrap unrel"); + simPlotPanelDesc = new DescriptionArea("", 2, -2f, false); + simPlotPanelDesc.setVisible(false); + simPlotPanelDesc.setForeground(Color.RED); + + simPlotPanelDesc.setViewportBorder(BorderFactory.createEmptyBorder()); + this.add(simPlotPanelDesc, "width 1px, growx 1, wrap unrel"); + From a40dc83aeb5e7b908a6d9ca6ece8fb7844a07692 Mon Sep 17 00:00:00 2001 From: May Date: Mon, 24 Apr 2023 21:59:07 -0400 Subject: [PATCH 3/7] Use openrocket Color instead of awt Color --- .../sf/openrocket/gui/simulation/SimulationPlotPanel.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java index bec59b70c..d926118a9 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationPlotPanel.java @@ -1,6 +1,5 @@ package net.sf.openrocket.gui.simulation; -import java.awt.Color; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -41,6 +40,7 @@ import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.unit.Unit; +import net.sf.openrocket.util.Color; import net.sf.openrocket.util.Utils; import net.sf.openrocket.gui.widgets.SelectColorButton; @@ -205,8 +205,7 @@ public class SimulationPlotPanel extends JPanel { //// The data will be plotted in time order even if the X axis type is not time. simPlotPanelDesc = new DescriptionArea("", 2, -2f, false); simPlotPanelDesc.setVisible(false); - simPlotPanelDesc.setForeground(Color.RED); - + simPlotPanelDesc.setForeground(Color.DARK_RED.toAWTColor()); simPlotPanelDesc.setViewportBorder(BorderFactory.createEmptyBorder()); this.add(simPlotPanelDesc, "width 1px, growx 1, wrap unrel"); From 508160f88bfab9b6f88bc64da78b67c4a6bd8107 Mon Sep 17 00:00:00 2001 From: May Date: Mon, 24 Apr 2023 22:16:47 -0400 Subject: [PATCH 4/7] Add warning message to plot display --- .../sf/openrocket/gui/plot/SimulationPlotDialog.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java index d9c1724ea..0d23aeacb 100644 --- a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java +++ b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java @@ -28,8 +28,10 @@ import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.gui.widgets.SaveFileChooser; import net.sf.openrocket.l10n.Translator; +import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Preferences; +import net.sf.openrocket.util.Color; import net.sf.openrocket.gui.widgets.SelectColorButton; import org.jfree.chart.ChartPanel; @@ -71,6 +73,16 @@ public class SimulationPlotDialog extends JDialog { //// Description text JLabel label = new StyledLabel(trans.get("PlotDialog.lbl.Chart"), -2); panel.add(label, "wrap"); + + // Add warning if X axis type is not time + if (config.getDomainAxisType() != FlightDataType.TYPE_TIME) { + // TODO: LOW: This translation message doesn't use the proper tense (simple future when it would be present) + // There is currently no translation message representing this dialog. + // Such a message should be added, and this code should be updated to use it. + JLabel msg = new StyledLabel(trans.get("simplotpanel.Desc"), -2); + msg.setForeground(Color.DARK_RED.toAWTColor()); + panel.add(msg, "wrap"); + } //// Show data points final JCheckBox check = new JCheckBox(trans.get("PlotDialog.CheckBox.Showdatapoints")); From 3ab2c13b4c5d71340842fe061fd57f1ebcc07f43 Mon Sep 17 00:00:00 2001 From: May Date: Tue, 25 Apr 2023 14:18:33 -0400 Subject: [PATCH 5/7] Add translation message for plot warning --- core/resources/l10n/messages.properties | 2 ++ .../src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 2e3bbdc1c..7c81230ca 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -767,6 +767,8 @@ simplotpanel.but.NewYaxisplottype = New Y axis plot type simplotpanel.lbl.Axis = Axis: simplotpanel.but.ttip.Deletethisplot = Delete this plot simplotpanel.Desc = The data will be plotted in time order even if the X axis type is not time. +! Fix this name +simplotpanel.Warning = The data is plotted in time order even though the X axis type is not time. simplotpanel.OptionPane.lbl1 = A maximum of 15 plots is allowed. simplotpanel.OptionPane.lbl2 = Cannot add plot simplotpanel.AUTO_NAME = Auto diff --git a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java index 0d23aeacb..b6f204770 100644 --- a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java +++ b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java @@ -76,10 +76,7 @@ public class SimulationPlotDialog extends JDialog { // Add warning if X axis type is not time if (config.getDomainAxisType() != FlightDataType.TYPE_TIME) { - // TODO: LOW: This translation message doesn't use the proper tense (simple future when it would be present) - // There is currently no translation message representing this dialog. - // Such a message should be added, and this code should be updated to use it. - JLabel msg = new StyledLabel(trans.get("simplotpanel.Desc"), -2); + JLabel msg = new StyledLabel(trans.get("simplotpanel.Warning"), -2); msg.setForeground(Color.DARK_RED.toAWTColor()); panel.add(msg, "wrap"); } From 8d1ce46d095de9da197298fa9fc3022bdf0e453c Mon Sep 17 00:00:00 2001 From: May Date: Tue, 25 Apr 2023 14:19:41 -0400 Subject: [PATCH 6/7] Fix problem with setForeground and setBackground --- .../openrocket/gui/components/DescriptionArea.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java index 39ca75da0..2c666eff2 100644 --- a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java +++ b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java @@ -18,6 +18,9 @@ import java.io.FileOutputStream; import javax.swing.JTextPane; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -188,6 +191,7 @@ public class DescriptionArea extends JScrollPane { } }); + setForeground(editorPane.getForeground()); editorPane.scrollRectToVisible(new Rectangle(0, 0, 1, 1)); } @@ -206,11 +210,19 @@ public class DescriptionArea extends JScrollPane { public void setBackground(Color color) { if (editorPane == null) return; editorPane.setBackground(color); + StyledDocument styledDocument = (StyledDocument) editorPane.getDocument(); + SimpleAttributeSet attributeSet = new SimpleAttributeSet(); + StyleConstants.setForeground(attributeSet, color); + styledDocument.setCharacterAttributes(0, styledDocument.getLength(), attributeSet, false); } public void setForeground(Color color) { if (editorPane == null) return; editorPane.setForeground(color); + StyledDocument styledDocument = (StyledDocument) editorPane.getDocument(); + SimpleAttributeSet attributeSet = new SimpleAttributeSet(); + StyleConstants.setForeground(attributeSet, color); + styledDocument.setCharacterAttributes(0, styledDocument.getLength(), attributeSet, false); } } From ff47b8117a04cb7ca46c7419a89cad3bd9940e1a Mon Sep 17 00:00:00 2001 From: May Date: Wed, 26 Apr 2023 14:57:05 -0400 Subject: [PATCH 7/7] Change plot warning message name --- core/resources/l10n/messages.properties | 3 +-- swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 7c81230ca..615319afe 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -767,8 +767,6 @@ simplotpanel.but.NewYaxisplottype = New Y axis plot type simplotpanel.lbl.Axis = Axis: simplotpanel.but.ttip.Deletethisplot = Delete this plot simplotpanel.Desc = The data will be plotted in time order even if the X axis type is not time. -! Fix this name -simplotpanel.Warning = The data is plotted in time order even though the X axis type is not time. simplotpanel.OptionPane.lbl1 = A maximum of 15 plots is allowed. simplotpanel.OptionPane.lbl2 = Cannot add plot simplotpanel.AUTO_NAME = Auto @@ -1506,6 +1504,7 @@ TCMotorSelPan.btn.close = Close ! PlotDialog PlotDialog.CheckBox.Showdatapoints = Show data points PlotDialog.lbl.Chart = left click drag to zoom area. mouse wheel to zoom. ctrl-mouse wheel to zoom x axis only. ctrl-left click drag to pan. right click drag to zoom dynamically. +PlotDialog.lbl.timeSeriesWarning = The data is plotted in time order even though the X axis type is not time. PlotDialog.btn.exportImage = Export Image ComponentTree.ttip.massoverride = mass overriden diff --git a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java index b6f204770..db19ab496 100644 --- a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java +++ b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java @@ -76,7 +76,7 @@ public class SimulationPlotDialog extends JDialog { // Add warning if X axis type is not time if (config.getDomainAxisType() != FlightDataType.TYPE_TIME) { - JLabel msg = new StyledLabel(trans.get("simplotpanel.Warning"), -2); + JLabel msg = new StyledLabel(trans.get("PlotDialog.lbl.timeSeriesWarning"), -2); msg.setForeground(Color.DARK_RED.toAWTColor()); panel.add(msg, "wrap"); }