Merge pull request #2347 from SiboVG/issue-2344

[#2344] Optimize UI color fetching
This commit is contained in:
Sibo Van Gool 2023-09-24 22:33:48 +02:00 committed by GitHub
commit fa5bd94772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 939 additions and 132 deletions

View File

@ -5,6 +5,7 @@ import net.sf.openrocket.file.wavefrontobj.export.OBJExportOptions;
import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentAssembly; import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -27,6 +28,7 @@ import javax.swing.JToggleButton;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.Color;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -64,6 +66,12 @@ public class OBJOptionChooser extends JPanel {
private int totallyNormalCounter = 0; private int totallyNormalCounter = 0;
private static Color darkWarningColor;
static {
initColors();
}
public OBJOptionChooser(JComponent parent, OBJExportOptions opts, List<RocketComponent> selectedComponents, Rocket rocket) { public OBJOptionChooser(JComponent parent, OBJExportOptions opts, List<RocketComponent> selectedComponents, Rocket rocket) {
super(new MigLayout("hidemode 3")); super(new MigLayout("hidemode 3"));
@ -305,13 +313,22 @@ public class OBJOptionChooser extends JPanel {
loadOptions(opts); loadOptions(opts);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(OBJOptionChooser::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
/** /**
* Highlight the given button and un-highlight the other button. * Highlight the given button and un-highlight the other button.
* @param highlightButton The button to highlight * @param highlightButton The button to highlight
* @param loserButton The button to un-highlight * @param loserButton The button to un-highlight
*/ */
private void highlightButton(JButton highlightButton, JButton loserButton) { private void highlightButton(JButton highlightButton, JButton loserButton) {
highlightButton.setBorder(BorderFactory.createLineBorder(GUIUtil.getUITheme().getDarkWarningColor())); highlightButton.setBorder(BorderFactory.createLineBorder(darkWarningColor));
loserButton.setBorder(UIManager.getBorder("Button.border")); loserButton.setBorder(UIManager.getBorder("Button.border"));
} }

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.components; package net.sf.openrocket.gui.components;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
@ -16,6 +17,12 @@ import javax.swing.tree.TreePath;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class BasicTree extends JTree { public class BasicTree extends JTree {
private static Color backgroundColor;
static {
initColors();
}
public BasicTree() { public BasicTree() {
super(); super();
setDefaultOptions(); setDefaultOptions();
@ -37,10 +44,18 @@ public class BasicTree extends JTree {
plainUI.setLeftChildIndent(15); plainUI.setLeftChildIndent(15);
this.setBackground(GUIUtil.getUITheme().getBackgroundColor()); this.setBackground(backgroundColor);
this.setShowsRootHandles(false); this.setShowsRootHandles(false);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(BasicTree::updateColors);
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
}
/** /**
* Expand the entire tree structure. All nodes will be visible after the call. * Expand the entire tree structure. All nodes will be visible after the call.

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.components; package net.sf.openrocket.gui.components;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.util.URLUtil; import net.sf.openrocket.gui.util.URLUtil;
import java.awt.Color; import java.awt.Color;
@ -16,6 +17,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import javax.swing.border.Border;
import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener; import javax.swing.event.HyperlinkListener;
import javax.swing.text.SimpleAttributeSet; import javax.swing.text.SimpleAttributeSet;
@ -34,6 +36,12 @@ public class DescriptionArea extends JScrollPane {
private final float size; private final float size;
private static Border border;
static {
initColors();
}
/** /**
* Construct a description area with the specified number of rows, default description font size, * Construct a description area with the specified number of rows, default description font size,
@ -177,12 +185,21 @@ public class DescriptionArea extends JScrollPane {
dim.height = lineheight * rows + extraheight + 2; dim.height = lineheight * rows + extraheight + 2;
this.setPreferredSize(dim); this.setPreferredSize(dim);
editorPane.setBorder(GUIUtil.getUITheme().getBorder()); editorPane.setBorder(border);
this.setViewportView(editorPane); this.setViewportView(editorPane);
this.setText(text); this.setText(text);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(DescriptionArea::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
public void setText(String txt) { public void setText(String txt) {
// Set the font size (we can't simply set the font to change the font size, because we're using text/html) // Set the font size (we can't simply set the font to change the font size, because we're using text/html)
Font defaultFont = editorPane.getFont(); Font defaultFont = editorPane.getFont();

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.components; package net.sf.openrocket.gui.components;
import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -9,6 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.util.URLUtil; import net.sf.openrocket.gui.util.URLUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,6 +24,12 @@ import org.slf4j.LoggerFactory;
public class URLLabel extends SelectableLabel { public class URLLabel extends SelectableLabel {
private static final Logger log = LoggerFactory.getLogger(URLLabel.class); private static final Logger log = LoggerFactory.getLogger(URLLabel.class);
private static Color URLColor;
static {
initColors();
}
/** /**
* Create a label showing the url it will direct to. * Create a label showing the url it will direct to.
* *
@ -48,7 +56,7 @@ public class URLLabel extends SelectableLabel {
Map<TextAttribute, Object> map = new HashMap<TextAttribute, Object>(); Map<TextAttribute, Object> map = new HashMap<TextAttribute, Object>();
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
this.setFont(this.getFont().deriveFont(map)); this.setFont(this.getFont().deriveFont(map));
this.setForeground(GUIUtil.getUITheme().getURLColor()); this.setForeground(URLColor);
this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
@ -66,4 +74,13 @@ public class URLLabel extends SelectableLabel {
} }
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(URLLabel::updateColors);
}
private static void updateColors() {
URLColor = GUIUtil.getUITheme().getURLColor();
}
} }

View File

@ -41,6 +41,7 @@ import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.DescriptionArea; import net.sf.openrocket.gui.components.DescriptionArea;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
@ -467,15 +468,15 @@ class ClusterSelectionPanel extends JPanel {
private static final int MOTOR_DIAMETER = 10; private static final int MOTOR_DIAMETER = 10;
private static final Color SELECTED_COLOR; private static final Color SELECTED_COLOR;
private static final Color UNSELECTED_COLOR; private static Color UNSELECTED_COLOR;
private static final Color MOTOR_FILL_COLOR; private static final Color MOTOR_FILL_COLOR;
private static final Color MOTOR_BORDER_COLOR; private static final Color MOTOR_BORDER_COLOR;
static { static {
SELECTED_COLOR = Color.RED; SELECTED_COLOR = Color.RED;
UNSELECTED_COLOR = GUIUtil.getUITheme().getBackgroundColor();
MOTOR_FILL_COLOR = Color.GREEN; MOTOR_FILL_COLOR = Color.GREEN;
MOTOR_BORDER_COLOR = Color.BLACK; MOTOR_BORDER_COLOR = Color.BLACK;
initColors();
} }
public ClusterSelectionPanel(Clusterable component) { public ClusterSelectionPanel(Clusterable component) {
@ -495,6 +496,15 @@ class ClusterSelectionPanel extends JPanel {
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ClusterSelectionPanel::updateColors);
}
private static void updateColors() {
UNSELECTED_COLOR = GUIUtil.getUITheme().getBackgroundColor();
}
private class ClusterButton extends JPanel implements StateChangeListener, MouseListener, private class ClusterButton extends JPanel implements StateChangeListener, MouseListener,
Resettable { Resettable {

View File

@ -30,6 +30,7 @@ import javax.swing.JTabbedPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@ -49,6 +50,7 @@ import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.dialogs.preset.ComponentPresetChooserDialog; import net.sf.openrocket.gui.dialogs.preset.ComponentPresetChooserDialog;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.widgets.IconToggleButton; import net.sf.openrocket.gui.widgets.IconToggleButton;
import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
@ -97,6 +99,14 @@ public class RocketComponentConfig extends JPanel {
private boolean allSameType; // Checks whether all listener components are of the same type as <component> private boolean allSameType; // Checks whether all listener components are of the same type as <component>
private boolean allMassive; // Checks whether all listener components, and this component, are massive private boolean allMassive; // Checks whether all listener components, and this component, are massive
private static Color darkWarningColor;
private static Color multiCompEditColor;
private static Border border;
static {
initColors();
}
public RocketComponentConfig(OpenRocketDocument document, RocketComponent component, JDialog parent) { public RocketComponentConfig(OpenRocketDocument document, RocketComponent component, JDialog parent) {
setLayout(new MigLayout("fill, gap 4!, ins panel, hidemode 3", "[]:5[]", "[growprio 5]5![fill, grow, growprio 500]5![growprio 5]")); setLayout(new MigLayout("fill, gap 4!, ins panel, hidemode 3", "[]:5[]", "[growprio 5]5![fill, grow, growprio 500]5![growprio 5]"));
@ -187,6 +197,17 @@ public class RocketComponentConfig extends JPanel {
updateFields(); updateFields();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RocketComponentConfig::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
multiCompEditColor = GUIUtil.getUITheme().getMultiCompEditColor();
border = GUIUtil.getUITheme().getBorder();
}
/** /**
* Add a section to the component configuration dialog that displays information about the component. * Add a section to the component configuration dialog that displays information about the component.
*/ */
@ -251,7 +272,7 @@ public class RocketComponentConfig extends JPanel {
//// Multi-comp edit label //// Multi-comp edit label
multiCompEditLabel = new StyledLabel(" ", -1, Style.BOLD); multiCompEditLabel = new StyledLabel(" ", -1, Style.BOLD);
multiCompEditLabel.setFontColor(new Color(170, 0, 100)); multiCompEditLabel.setFontColor(multiCompEditColor);
buttonPanel.add(multiCompEditLabel, "split 2"); buttonPanel.add(multiCompEditLabel, "split 2");
//// Mass: //// Mass:
@ -506,7 +527,7 @@ public class RocketComponentConfig extends JPanel {
StyledLabel labelMassOverriddenBy = new StyledLabel( StyledLabel labelMassOverriddenBy = new StyledLabel(
String.format(trans.get("RocketCompCfg.lbl.MassOverriddenBy"), component.getMassOverriddenBy().getName()), String.format(trans.get("RocketCompCfg.lbl.MassOverriddenBy"), component.getMassOverriddenBy().getName()),
0, StyledLabel.Style.BOLD); 0, StyledLabel.Style.BOLD);
labelMassOverriddenBy.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); labelMassOverriddenBy.setFontColor(darkWarningColor);
labelMassOverriddenBy.setToolTipText( labelMassOverriddenBy.setToolTipText(
String.format(trans.get("RocketCompCfg.lbl.MassOverriddenBy.ttip"), component.getMassOverriddenBy().getName())); String.format(trans.get("RocketCompCfg.lbl.MassOverriddenBy.ttip"), component.getMassOverriddenBy().getName()));
checkboxes.add(labelMassOverriddenBy, "gapleft 25lp, wrap"); checkboxes.add(labelMassOverriddenBy, "gapleft 25lp, wrap");
@ -569,7 +590,7 @@ public class RocketComponentConfig extends JPanel {
StyledLabel labelCGOverriddenBy = new StyledLabel( StyledLabel labelCGOverriddenBy = new StyledLabel(
String.format(trans.get("RocketCompCfg.lbl.CGOverriddenBy"), component.getCGOverriddenBy().getName()), String.format(trans.get("RocketCompCfg.lbl.CGOverriddenBy"), component.getCGOverriddenBy().getName()),
0, StyledLabel.Style.BOLD); 0, StyledLabel.Style.BOLD);
labelCGOverriddenBy.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); labelCGOverriddenBy.setFontColor(darkWarningColor);
labelCGOverriddenBy.setToolTipText( labelCGOverriddenBy.setToolTipText(
String.format(trans.get("RocketCompCfg.lbl.CGOverriddenBy.ttip"), component.getCGOverriddenBy().getName())); String.format(trans.get("RocketCompCfg.lbl.CGOverriddenBy.ttip"), component.getCGOverriddenBy().getName()));
checkboxes.add(labelCGOverriddenBy, "gapleft 25lp, wrap"); checkboxes.add(labelCGOverriddenBy, "gapleft 25lp, wrap");
@ -663,7 +684,7 @@ public class RocketComponentConfig extends JPanel {
StyledLabel labelCDOverriddenBy = new StyledLabel( StyledLabel labelCDOverriddenBy = new StyledLabel(
String.format(trans.get("RocketCompCfg.lbl.CDOverriddenBy"), component.getCDOverriddenBy().getName()), String.format(trans.get("RocketCompCfg.lbl.CDOverriddenBy"), component.getCDOverriddenBy().getName()),
0, StyledLabel.Style.BOLD); 0, StyledLabel.Style.BOLD);
labelCDOverriddenBy.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); labelCDOverriddenBy.setFontColor(darkWarningColor);
labelCDOverriddenBy.setToolTipText( labelCDOverriddenBy.setToolTipText(
String.format(trans.get("RocketCompCfg.lbl.CDOverriddenBy"), component.getCDOverriddenBy().getName())); String.format(trans.get("RocketCompCfg.lbl.CDOverriddenBy"), component.getCDOverriddenBy().getName()));
checkboxes.add(labelCDOverriddenBy, "gapleft 25lp, wrap"); checkboxes.add(labelCDOverriddenBy, "gapleft 25lp, wrap");
@ -719,7 +740,7 @@ public class RocketComponentConfig extends JPanel {
commentTextArea.setLineWrap(true); commentTextArea.setLineWrap(true);
commentTextArea.setWrapStyleWord(true); commentTextArea.setWrapStyleWord(true);
commentTextArea.setEditable(true); commentTextArea.setEditable(true);
commentTextArea.setBorder(GUIUtil.getUITheme().getBorder()); commentTextArea.setBorder(border);
GUIUtil.setTabToFocusing(commentTextArea); GUIUtil.setTabToFocusing(commentTextArea);
commentTextArea.addFocusListener(textFieldListener); commentTextArea.addFocusListener(textFieldListener);
commentTextArea.addKeyListener(new TextComponentSelectionKeyListener(commentTextArea)); commentTextArea.addKeyListener(new TextComponentSelectionKeyListener(commentTextArea));

View File

@ -16,10 +16,12 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.border.Border;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -35,6 +37,12 @@ public class RocketConfig extends RocketComponentConfig {
private final Rocket rocket; private final Rocket rocket;
private static Border border;
static {
initColors();
}
public RocketConfig(OpenRocketDocument d, RocketComponent c, JDialog parent) { public RocketConfig(OpenRocketDocument d, RocketComponent c, JDialog parent) {
super(d, c, parent); super(d, c, parent);
@ -55,7 +63,7 @@ public class RocketConfig extends RocketComponentConfig {
designerTextArea.setLineWrap(true); designerTextArea.setLineWrap(true);
designerTextArea.setWrapStyleWord(true); designerTextArea.setWrapStyleWord(true);
designerTextArea.setEditable(true); designerTextArea.setEditable(true);
designerTextArea.setBorder(GUIUtil.getUITheme().getBorder()); designerTextArea.setBorder(border);
GUIUtil.setTabToFocusing(designerTextArea); GUIUtil.setTabToFocusing(designerTextArea);
designerTextArea.addFocusListener(textFieldListener); designerTextArea.addFocusListener(textFieldListener);
this.add(new JScrollPane(designerTextArea), "wmin 400lp, height 60lp:60lp:, grow 30, wrap para"); this.add(new JScrollPane(designerTextArea), "wmin 400lp, height 60lp:60lp:, grow 30, wrap para");
@ -70,7 +78,7 @@ public class RocketConfig extends RocketComponentConfig {
revisionTextArea.setLineWrap(true); revisionTextArea.setLineWrap(true);
revisionTextArea.setWrapStyleWord(true); revisionTextArea.setWrapStyleWord(true);
revisionTextArea.setEditable(true); revisionTextArea.setEditable(true);
revisionTextArea.setBorder(GUIUtil.getUITheme().getBorder()); revisionTextArea.setBorder(border);
GUIUtil.setTabToFocusing(revisionTextArea); GUIUtil.setTabToFocusing(revisionTextArea);
revisionTextArea.addFocusListener(textFieldListener); revisionTextArea.addFocusListener(textFieldListener);
@ -81,6 +89,15 @@ public class RocketConfig extends RocketComponentConfig {
addEasterEgg(); addEasterEgg();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RocketConfig::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
/** /**
* Little method that adds a fun easter-egg to the rocket config dialog. * Little method that adds a fun easter-egg to the rocket config dialog.
*/ */

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.customexpression; package net.sf.openrocket.gui.customexpression;
import java.awt.Color;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -15,10 +16,12 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
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 org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -43,6 +46,12 @@ public class CustomExpressionPanel extends JPanel {
private JPanel expressionSelectorPanel; private JPanel expressionSelectorPanel;
private OpenRocketDocument doc; private OpenRocketDocument doc;
private static Border border;
static {
initColors();
}
public CustomExpressionPanel(final OpenRocketDocument doc, final JDialog parentDialog) { public CustomExpressionPanel(final OpenRocketDocument doc, final JDialog parentDialog) {
super(new MigLayout("fill")); super(new MigLayout("fill"));
this.doc = doc; this.doc = doc;
@ -51,7 +60,7 @@ public class CustomExpressionPanel extends JPanel {
expressionSelectorPanel.setToolTipText(trans.get("customExpressionPanel.lbl.CalcNote")); expressionSelectorPanel.setToolTipText(trans.get("customExpressionPanel.lbl.CalcNote"));
JScrollPane scroll = new JScrollPane(expressionSelectorPanel); JScrollPane scroll = new JScrollPane(expressionSelectorPanel);
expressionSelectorPanel.setBorder(GUIUtil.getUITheme().getBorder()); expressionSelectorPanel.setBorder(border);
//Border bdr = BorderFactory.createTitledBorder(trans.get("customExpressionPanel.lbl.CustomExpressions")); //Border bdr = BorderFactory.createTitledBorder(trans.get("customExpressionPanel.lbl.CustomExpressions"));
//scroll.setBorder(bdr); //scroll.setBorder(bdr);
@ -132,6 +141,15 @@ public class CustomExpressionPanel extends JPanel {
updateExpressions(); updateExpressions();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(CustomExpressionPanel::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
/* /*
* Update the expressionSelectorPanel * Update the expressionSelectorPanel
*/ */
@ -171,10 +189,24 @@ public class CustomExpressionPanel extends JPanel {
* A JPanel which configures a single expression * A JPanel which configures a single expression
*/ */
private class SingleExpression extends JPanel { private class SingleExpression extends JPanel {
private static Color backgroundColor;
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SingleExpression::updateColors);
}
static {
initColors();
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
}
// Convenience method to make the labels consistent // Convenience method to make the labels consistent
private JLabel setLabelStyle(JLabel l) { private JLabel setLabelStyle(JLabel l) {
l.setBackground(GUIUtil.getUITheme().getBackgroundColor()); l.setBackground(backgroundColor);
l.setOpaque(true); l.setOpaque(true);
l.setBorder(BorderFactory.createRaisedBevelBorder()); l.setBorder(BorderFactory.createRaisedBevelBorder());
l.setText(" " + l.getText() + " "); l.setText(" " + l.getText() + " ");
@ -192,7 +224,7 @@ public class CustomExpressionPanel extends JPanel {
JLabel symbolLabel = new JLabel(trans.get("customExpression.Symbol") + " :"); JLabel symbolLabel = new JLabel(trans.get("customExpression.Symbol") + " :");
JLabel symbol = new JLabel(expression.getSymbol()); JLabel symbol = new JLabel(expression.getSymbol());
symbol = setLabelStyle(symbol); symbol = setLabelStyle(symbol);
symbol.setBackground(GUIUtil.getUITheme().getBackgroundColor()); symbol.setBackground(backgroundColor);
JLabel unitLabel = new JLabel(trans.get("customExpression.Units") + " :"); JLabel unitLabel = new JLabel(trans.get("customExpression.Units") + " :");
UnitSelector unitSelector = new UnitSelector(expression.getType().getUnitGroup()); UnitSelector unitSelector = new UnitSelector(expression.getType().getUnitGroup());

View File

@ -29,6 +29,7 @@ import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.URLLabel; import net.sf.openrocket.gui.components.URLLabel;
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.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogLevelBufferLogger; import net.sf.openrocket.logging.LogLevelBufferLogger;
import net.sf.openrocket.logging.LogLine; import net.sf.openrocket.logging.LogLine;
@ -48,6 +49,12 @@ public class BugReportDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences(); private static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
private static Color darkWarningColor;
static {
initColors();
}
public BugReportDialog(Window parent, String labelText, final String message, final boolean sendIfUnchanged) { public BugReportDialog(Window parent, String labelText, final String message, final boolean sendIfUnchanged) {
//// Bug report //// Bug report
@ -104,6 +111,15 @@ public class BugReportDialog extends JDialog {
GUIUtil.setDisposableDialogOptions(this, close); GUIUtil.setDisposableDialogOptions(this, close);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(BugReportDialog::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
/** /**
* Show a general bug report dialog allowing the user to input information about * Show a general bug report dialog allowing the user to input information about
* the bug they encountered. * the bug they encountered.
@ -178,7 +194,7 @@ public class BugReportDialog extends JDialog {
private static void addBugReportInformation(StringBuilder sb) { private static void addBugReportInformation(StringBuilder sb) {
sb.append("<html>---------- Bug report ----------\n"); sb.append("<html>---------- Bug report ----------\n");
sb.append('\n'); sb.append('\n');
Color color = GUIUtil.getUITheme().getDarkWarningColor(); Color color = darkWarningColor;
sb.append(String.format("<b style='color:rgb(%d, %d, %d)'>Please include a description about what actions you were " + sb.append(String.format("<b style='color:rgb(%d, %d, %d)'>Please include a description about what actions you were " +
"performing when the exception occurred:</b>\n", color.getRed(), color.getGreen(), color.getBlue())); "performing when the exception occurred:</b>\n", color.getRed(), color.getGreen(), color.getBlue()));
sb.append("<i>(You can edit text directly in this window)</i>\n"); sb.append("<i>(You can edit text directly in this window)</i>\n");

View File

@ -33,6 +33,7 @@ import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
@ -41,6 +42,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.aerodynamics.AerodynamicCalculator; import net.sf.openrocket.aerodynamics.AerodynamicCalculator;
import net.sf.openrocket.aerodynamics.AerodynamicForces; import net.sf.openrocket.aerodynamics.AerodynamicForces;
import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.FlightConditions;
import net.sf.openrocket.gui.util.UITheme;
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.gui.adaptors.Column; import net.sf.openrocket.gui.adaptors.Column;
@ -97,6 +99,12 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
private final List<AerodynamicForces> dragData = new ArrayList<AerodynamicForces>(); private final List<AerodynamicForces> dragData = new ArrayList<AerodynamicForces>();
private final List<AerodynamicForces> rollData = new ArrayList<AerodynamicForces>(); private final List<AerodynamicForces> rollData = new ArrayList<AerodynamicForces>();
private static Border border;
static {
initColors();
}
public ComponentAnalysisDialog(final RocketPanel rocketPanel) { public ComponentAnalysisDialog(final RocketPanel rocketPanel) {
////Component analysis ////Component analysis
@ -150,7 +158,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
warningList = new JList<>(); warningList = new JList<>();
JScrollPane scrollPane = new JScrollPane(warningList); JScrollPane scrollPane = new JScrollPane(warningList);
warningList.setBorder(GUIUtil.getUITheme().getBorder()); warningList.setBorder(border);
////Warnings: ////Warnings:
scrollPane.setBorder(BorderFactory.createTitledBorder(trans.get("componentanalysisdlg.TitledBorder.warnings"))); scrollPane.setBorder(BorderFactory.createTitledBorder(trans.get("componentanalysisdlg.TitledBorder.warnings")));
panel.add(scrollPane, "gap paragraph, spany 4, w 300lp, grow, height :100lp:, wrap"); panel.add(scrollPane, "gap paragraph, spany 4, w 300lp, grow, height :100lp:, wrap");
@ -499,6 +507,14 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ComponentAnalysisDialog::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
/** /**
* Updates the data in the table and fires a table data change event. * Updates the data in the table and fires a table data change event.
@ -626,6 +642,12 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
private final List<?> data; private final List<?> data;
protected final int decimalPlaces; protected final int decimalPlaces;
private static Color backgroundColor;
static {
initColors();
}
public CustomCellRenderer(List<?> data, int decimalPlaces) { public CustomCellRenderer(List<?> data, int decimalPlaces) {
super(); super();
this.decimalPlaces = decimalPlaces; this.decimalPlaces = decimalPlaces;
@ -634,6 +656,15 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
this.boldFont = normalFont.deriveFont(Font.BOLD); this.boldFont = normalFont.deriveFont(Font.BOLD);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(CustomCellRenderer::updateColors);
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
}
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object value, public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) { boolean isSelected, boolean hasFocus, int row, int column) {
@ -647,7 +678,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe
} }
label.setOpaque(true); label.setOpaque(true);
label.setBackground(GUIUtil.getUITheme().getBackgroundColor()); label.setBackground(backgroundColor);
label.setHorizontalAlignment(SwingConstants.LEFT); label.setHorizontalAlignment(SwingConstants.LEFT);
if ((row < 0) || (row >= data.size())) if ((row < 0) || (row >= data.size()))

View File

@ -32,12 +32,14 @@ import javax.swing.ListSelectionModel;
import javax.swing.RowFilter; import javax.swing.RowFilter;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.Timer; import javax.swing.Timer;
import javax.swing.border.Border;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel; import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter; import javax.swing.table.TableRowSorter;
import net.sf.openrocket.gui.util.UITheme;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -110,6 +112,12 @@ public class DebugLogDialog extends JDialog {
private final SelectableLabel messageLabel; private final SelectableLabel messageLabel;
private final JTextArea stackTraceLabel; private final JTextArea stackTraceLabel;
private static Border border;
static {
initColors();
}
public DebugLogDialog(Window parent) { public DebugLogDialog(Window parent) {
//// OpenRocket debug log //// OpenRocket debug log
super(parent, trans.get("debuglogdlg.OpenRocketdebuglog")); super(parent, trans.get("debuglogdlg.OpenRocketdebuglog"));
@ -343,7 +351,7 @@ public class DebugLogDialog extends JDialog {
bottomPanel.add(new JLabel(trans.get("debuglogdlg.lbl.Stacktrace")), "wrap rel"); bottomPanel.add(new JLabel(trans.get("debuglogdlg.lbl.Stacktrace")), "wrap rel");
stackTraceLabel = new JTextArea(8, 80); stackTraceLabel = new JTextArea(8, 80);
stackTraceLabel.setEditable(false); stackTraceLabel.setEditable(false);
stackTraceLabel.setBorder(GUIUtil.getUITheme().getBorder()); stackTraceLabel.setBorder(border);
GUIUtil.changeFontSize(stackTraceLabel, -2); GUIUtil.changeFontSize(stackTraceLabel, -2);
bottomPanel.add(new JScrollPane(stackTraceLabel), "grow, pushy 200, growprioy 200"); bottomPanel.add(new JScrollPane(stackTraceLabel), "grow, pushy 200, growprioy 200");
@ -386,6 +394,15 @@ public class DebugLogDialog extends JDialog {
followBox.requestFocus(); followBox.requestFocus();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(DebugLogDialog::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
private void updateSelected(int row) { private void updateSelected(int row) {
if (row < 0) { if (row < 0) {

View File

@ -4,6 +4,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.util.BetterListCellRenderer; import net.sf.openrocket.gui.util.BetterListCellRenderer;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.logging.Error; import net.sf.openrocket.logging.Error;
import net.sf.openrocket.logging.ErrorSet; import net.sf.openrocket.logging.ErrorSet;
import net.sf.openrocket.logging.Warning; import net.sf.openrocket.logging.Warning;
@ -16,6 +17,8 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@ -25,12 +28,30 @@ import java.awt.event.MouseEvent;
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class ErrorWarningDialog { public abstract class ErrorWarningDialog {
private static Border border;
private static Color darkWarningColor;
private static Color textSelectionForegroundColor;
static {
initColors();
}
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ErrorWarningDialog::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
textSelectionForegroundColor = GUIUtil.getUITheme().getTextSelectionForegroundColor();
}
public static void showErrorsAndWarnings(Component parent, Object message, String title, ErrorSet errors, WarningSet warnings) { public static void showErrorsAndWarnings(Component parent, Object message, String title, ErrorSet errors, WarningSet warnings) {
JPanel content = new JPanel(new MigLayout("ins 0, fillx")); JPanel content = new JPanel(new MigLayout("ins 0, fillx"));
StyledLabel label = new StyledLabel("Errors"); StyledLabel label = new StyledLabel("Errors");
label.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); label.setFontColor(darkWarningColor);
content.add(label, "wrap, gaptop 15lp"); content.add(label, "wrap, gaptop 15lp");
Error[] e = errors.toArray(new Error[0]); Error[] e = errors.toArray(new Error[0]);
@ -38,7 +59,7 @@ public abstract class ErrorWarningDialog {
errorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); errorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
errorList.setCellRenderer(new ErrorListCellRenderer()); errorList.setCellRenderer(new ErrorListCellRenderer());
JScrollPane errorPane = new JScrollPane(errorList); JScrollPane errorPane = new JScrollPane(errorList);
errorList.setBorder(GUIUtil.getUITheme().getBorder()); errorList.setBorder(border);
content.add(errorPane, "wrap, growx"); content.add(errorPane, "wrap, growx");
// Deselect items if clicked on blank region // Deselect items if clicked on blank region
@ -60,7 +81,7 @@ public abstract class ErrorWarningDialog {
final JList<Warning> warningList = new JList<>(w); final JList<Warning> warningList = new JList<>(w);
warningList.setCellRenderer(new BetterListCellRenderer()); warningList.setCellRenderer(new BetterListCellRenderer());
JScrollPane warningPane = new JScrollPane(warningList); JScrollPane warningPane = new JScrollPane(warningList);
warningList.setBorder(GUIUtil.getUITheme().getBorder()); warningList.setBorder(border);
content.add(warningPane, "wrap, growx"); content.add(warningPane, "wrap, growx");
// Deselect items if clicked on blank region // Deselect items if clicked on blank region
@ -87,9 +108,9 @@ public abstract class ErrorWarningDialog {
// Text color // Text color
if (isSelected) { if (isSelected) {
label.setForeground(GUIUtil.getUITheme().getTextSelectionForegroundColor()); label.setForeground(textSelectionForegroundColor);
} else { } else {
label.setForeground(GUIUtil.getUITheme().getDarkWarningColor()); label.setForeground(darkWarningColor);
} }
return label; return label;

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.dialogs; package net.sf.openrocket.gui.dialogs;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Insets; import java.awt.Insets;
@ -32,6 +33,7 @@ import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
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.URLUtil; import net.sf.openrocket.gui.util.URLUtil;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
@ -51,6 +53,12 @@ public class UpdateInfoDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private final SwingPreferences preferences = (SwingPreferences) Application.getPreferences(); private final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
private static Color textColor;
static {
initColors();
}
public UpdateInfoDialog(UpdateInfo info) { public UpdateInfoDialog(UpdateInfo info) {
//// OpenRocket update available //// OpenRocket update available
super(null, trans.get("update.dlg.updateAvailable.title"), ModalityType.APPLICATION_MODAL); super(null, trans.get("update.dlg.updateAvailable.title"), ModalityType.APPLICATION_MODAL);
@ -74,7 +82,7 @@ public class UpdateInfoDialog extends JDialog {
// Release information box // Release information box
final JTextPane textPane = new JTextPane(); final JTextPane textPane = new JTextPane();
textPane.setBorder(BorderFactory.createLineBorder(GUIUtil.getUITheme().getTextColor())); textPane.setBorder(BorderFactory.createLineBorder(textColor));
textPane.setEditable(false); textPane.setEditable(false);
textPane.setContentType("text/html"); textPane.setContentType("text/html");
textPane.setMargin(new Insets(10, 10, 40, 10)); textPane.setMargin(new Insets(10, 10, 40, 10));
@ -201,6 +209,15 @@ public class UpdateInfoDialog extends JDialog {
GUIUtil.setDisposableDialogOptions(this, btnLater); GUIUtil.setDisposableDialogOptions(this, btnLater);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(UpdateInfoDialog::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
}
/** /**
* ComboBox renderer to display an UpdatePlatform by the platform name * ComboBox renderer to display an UpdatePlatform by the platform name
*/ */

View File

@ -6,21 +6,37 @@ import javax.swing.BorderFactory;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.border.Border;
import net.sf.openrocket.gui.util.BetterListCellRenderer; import net.sf.openrocket.gui.util.BetterListCellRenderer;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.logging.Warning; import net.sf.openrocket.logging.Warning;
import net.sf.openrocket.logging.WarningSet; import net.sf.openrocket.logging.WarningSet;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class WarningDialog { public abstract class WarningDialog {
public static void showWarnings(Component parent, Object message, String title, WarningSet warnings) { private static Border border;
static {
initColors();
}
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(WarningDialog::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
public static void showWarnings(Component parent, Object message, String title, WarningSet warnings) {
Warning[] w = warnings.toArray(new Warning[0]); Warning[] w = warnings.toArray(new Warning[0]);
final JList<Warning> list = new JList<Warning>(w); final JList<Warning> list = new JList<Warning>(w);
list.setCellRenderer(new BetterListCellRenderer()); list.setCellRenderer(new BetterListCellRenderer());
JScrollPane pane = new JScrollPane(list); JScrollPane pane = new JScrollPane(list);
pane.setBorder(GUIUtil.getUITheme().getBorder()); pane.setBorder(border);
JOptionPane.showMessageDialog(parent, new Object[] { message, pane }, JOptionPane.showMessageDialog(parent, new Object[] { message, pane },
title, JOptionPane.WARNING_MESSAGE); title, JOptionPane.WARNING_MESSAGE);

View File

@ -4,6 +4,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.util.URLUtil; import net.sf.openrocket.gui.util.URLUtil;
import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
@ -20,9 +21,9 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import javax.swing.border.Border;
import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener; import javax.swing.event.HyperlinkListener;
import java.awt.Desktop;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -35,6 +36,12 @@ public class WelcomeDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static final Logger log = LoggerFactory.getLogger(WelcomeDialog.class); private static final Logger log = LoggerFactory.getLogger(WelcomeDialog.class);
private static Border border;
static {
initColors();
}
/** /**
* @param releaseNotes the release notes to display for the current version * @param releaseNotes the release notes to display for the current version
*/ */
@ -82,7 +89,7 @@ public class WelcomeDialog extends JDialog {
textPane.setCaretPosition(0); // Scroll to the top textPane.setCaretPosition(0); // Scroll to the top
JScrollPane scrollPane = new JScrollPane(textPane); JScrollPane scrollPane = new JScrollPane(textPane);
scrollPane.setBorder(GUIUtil.getUITheme().getBorder()); scrollPane.setBorder(border);
panel.add(scrollPane, "skip 1, left, spanx, grow, push, gapbottom 6px, wrap"); panel.add(scrollPane, "skip 1, left, spanx, grow, push, gapbottom 6px, wrap");
// Don't show this dialog again // Don't show this dialog again
@ -114,4 +121,13 @@ public class WelcomeDialog extends JDialog {
this.setLocationRelativeTo(null); this.setLocationRelativeTo(null);
GUIUtil.setDisposableDialogOptions(this, closeBtn); GUIUtil.setDisposableDialogOptions(this, closeBtn);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(WelcomeDialog::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
} }

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.dialogs.flightconfiguration; package net.sf.openrocket.gui.dialogs.flightconfiguration;
import java.awt.Color;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -15,6 +16,7 @@ import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.configdialog.CommonStrings; import net.sf.openrocket.gui.configdialog.CommonStrings;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -25,6 +27,12 @@ public class RenameConfigDialog extends JDialog {
private static final long serialVersionUID = -5423008694485357248L; private static final long serialVersionUID = -5423008694485357248L;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static Color dimTextColor;
static {
initColors();
}
public RenameConfigDialog(final Window parent, final Rocket rocket, final FlightConfigurationId fcid) { public RenameConfigDialog(final Window parent, final Rocket rocket, final FlightConfigurationId fcid) {
super(parent, trans.get("RenameConfigDialog.title"), Dialog.ModalityType.APPLICATION_MODAL); super(parent, trans.get("RenameConfigDialog.title"), Dialog.ModalityType.APPLICATION_MODAL);
@ -73,11 +81,20 @@ public class RenameConfigDialog extends JDialog {
+ trans.get("RenameConfigDialog.lbl.infoCases") + trans.get("RenameConfigDialog.lbl.infoCases")
+ trans.get("RenameConfigDialog.lbl.infoCombination"); + trans.get("RenameConfigDialog.lbl.infoCombination");
StyledLabel info = new StyledLabel(text, -2); StyledLabel info = new StyledLabel(text, -2);
info.setFontColor(GUIUtil.getUITheme().getDimTextColor()); info.setFontColor(dimTextColor);
panel.add(info, "spanx, growx, wrap"); panel.add(info, "spanx, growx, wrap");
this.add(panel); this.add(panel);
GUIUtil.setDisposableDialogOptions(this, okButton); GUIUtil.setDisposableDialogOptions(this, okButton);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RenameConfigDialog::updateColors);
}
private static void updateColors() {
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
}
} }

View File

@ -34,6 +34,7 @@ import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.CheckList; import net.sf.openrocket.gui.util.CheckList;
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.widgets.MultiSlider; import net.sf.openrocket.gui.widgets.MultiSlider;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -118,6 +119,12 @@ public abstract class MotorFilterPanel extends JPanel {
private final MultiSlider lengthSlider; private final MultiSlider lengthSlider;
private final MultiSlider diameterSlider; private final MultiSlider diameterSlider;
private static Border border;
static {
initColors();
}
public MotorFilterPanel(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) { public MotorFilterPanel(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) {
super(new MigLayout("fill", "[grow]")); super(new MigLayout("fill", "[grow]"));
this.filter = filter; this.filter = filter;
@ -146,7 +153,7 @@ public abstract class MotorFilterPanel extends JPanel {
// Manufacturer selection // Manufacturer selection
JPanel sub = new JPanel(new MigLayout("fill")); JPanel sub = new JPanel(new MigLayout("fill"));
Border templateBorder = GUIUtil.getUITheme().getBorder(); Border templateBorder = border;
TitledBorder border = BorderFactory.createTitledBorder(templateBorder); TitledBorder border = BorderFactory.createTitledBorder(templateBorder);
border.setTitle(trans.get("TCurveMotorCol.MANUFACTURER")); border.setTitle(trans.get("TCurveMotorCol.MANUFACTURER"));
GUIUtil.changeFontStyle(border, Font.BOLD); GUIUtil.changeFontStyle(border, Font.BOLD);
@ -186,9 +193,8 @@ public abstract class MotorFilterPanel extends JPanel {
}); });
JScrollPane scrollPane = new JScrollPane(manufacturerCheckList.getList()); JScrollPane scrollPane = new JScrollPane(manufacturerCheckList.getList());
Border border1 = GUIUtil.getUITheme().getBorder(); if (border != null) {
if (border1 != null) { scrollPane.setBorder(border);
scrollPane.setBorder(border1);
} }
sub.add(scrollPane, "grow, pushy, wrap"); sub.add(scrollPane, "grow, pushy, wrap");
@ -368,6 +374,15 @@ public abstract class MotorFilterPanel extends JPanel {
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(MotorFilterPanel::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
public void setMotorMount( MotorMount mount ) { public void setMotorMount( MotorMount mount ) {
filter.setMotorMount(mount); filter.setMotorMount(mount);
onSelectionChanged(); onSelectionChanged();

View File

@ -15,7 +15,9 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.util.StringUtils; import net.sf.openrocket.util.StringUtils;
import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel; import org.jfree.chart.ChartPanel;
@ -42,8 +44,10 @@ class MotorInformationPanel extends JPanel {
private static final int ZOOM_ICON_POSITION_NEGATIVE_X = 50; private static final int ZOOM_ICON_POSITION_NEGATIVE_X = 50;
private static final int ZOOM_ICON_POSITION_POSITIVE_Y = 12; private static final int ZOOM_ICON_POSITION_POSITIVE_Y = 12;
private static final Color NO_COMMENT_COLOR = GUIUtil.getUITheme().getDimTextColor(); private static Color NO_COMMENT_COLOR;
private static final Color WITH_COMMENT_COLOR = GUIUtil.getUITheme().getTextColor(); private static Color WITH_COMMENT_COLOR;
private static Color textColor;
private static Border border;
// Motors in set // Motors in set
private List<ThrustCurveMotor> selectedMotorSet; private List<ThrustCurveMotor> selectedMotorSet;
@ -74,6 +78,10 @@ class MotorInformationPanel extends JPanel {
private final ChartPanel chartPanel; private final ChartPanel chartPanel;
private final JLabel zoomIcon; private final JLabel zoomIcon;
static {
initColors();
}
public MotorInformationPanel() { public MotorInformationPanel() {
super(new MigLayout("fill")); super(new MigLayout("fill"));
@ -159,7 +167,7 @@ class MotorInformationPanel extends JPanel {
comment = new JTextArea(5, 5); comment = new JTextArea(5, 5);
comment.setBorder(GUIUtil.getUITheme().getBorder()); comment.setBorder(border);
GUIUtil.changeFontSize(comment, -2); GUIUtil.changeFontSize(comment, -2);
withCommentFont = comment.getFont(); withCommentFont = comment.getFont();
noCommentFont = withCommentFont.deriveFont(Font.ITALIC); noCommentFont = withCommentFont.deriveFont(Font.ITALIC);
@ -191,7 +199,7 @@ class MotorInformationPanel extends JPanel {
//// Thrust curve: //// Thrust curve:
TextTitle title = new TextTitle(trans.get("TCMotorSelPan.title.Thrustcurve"), this.getFont()); TextTitle title = new TextTitle(trans.get("TCMotorSelPan.title.Thrustcurve"), this.getFont());
title.setPaint(GUIUtil.getUITheme().getTextColor()); title.setPaint(textColor);
chart.setTitle(title); chart.setTitle(title);
chart.setBackgroundPaint(this.getBackground()); chart.setBackgroundPaint(this.getBackground());
plot.setBackgroundPaint(Color.WHITE); plot.setBackgroundPaint(Color.WHITE);
@ -240,6 +248,18 @@ class MotorInformationPanel extends JPanel {
} }
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(MotorInformationPanel::updateColors);
}
private static void updateColors() {
NO_COMMENT_COLOR = GUIUtil.getUITheme().getDimTextColor();
WITH_COMMENT_COLOR = GUIUtil.getUITheme().getTextColor();
textColor = GUIUtil.getUITheme().getTextColor();
border = GUIUtil.getUITheme().getBorder();
}
public void clearData() { public void clearData() {
selectedMotor = null; selectedMotor = null;
selectedMotorSet = null; selectedMotorSet = null;

View File

@ -111,6 +111,12 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
private ThrustCurveMotorSet selectedMotorSet; private ThrustCurveMotorSet selectedMotorSet;
private double selectedDelay; private double selectedDelay;
private static Color dimTextColor;
static {
initColors();
}
public ThrustCurveMotorSelectionPanel( final FlightConfigurationId fcid, MotorMount mount ) { public ThrustCurveMotorSelectionPanel( final FlightConfigurationId fcid, MotorMount mount ) {
this(); this();
setMotorMountAndConfig( fcid, mount ); setMotorMountAndConfig( fcid, mount );
@ -336,7 +342,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
nrOfMotorsLabel = new StyledLabel(-2f, StyledLabel.Style.ITALIC); nrOfMotorsLabel = new StyledLabel(-2f, StyledLabel.Style.ITALIC);
nrOfMotorsLabel.setToolTipText(trans.get("TCMotorSelPan.lbl.ttip.nrOfMotors")); nrOfMotorsLabel.setToolTipText(trans.get("TCMotorSelPan.lbl.ttip.nrOfMotors"));
updateNrOfMotors(); updateNrOfMotors();
nrOfMotorsLabel.setForeground(GUIUtil.getUITheme().getDimTextColor()); nrOfMotorsLabel.setForeground(dimTextColor);
panel.add(nrOfMotorsLabel, "gapleft para, spanx, wrap"); panel.add(nrOfMotorsLabel, "gapleft para, spanx, wrap");
sorter.addRowSorterListener(new RowSorterListener() { sorter.addRowSorterListener(new RowSorterListener() {
@Override @Override
@ -400,6 +406,15 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ThrustCurveMotorSelectionPanel::updateColors);
}
private static void updateColors() {
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
}
public void setMotorMountAndConfig( final FlightConfigurationId _fcid, MotorMount mountToEdit ) { public void setMotorMountAndConfig( final FlightConfigurationId _fcid, MotorMount mountToEdit ) {
if ( null == _fcid ){ if ( null == _fcid ){
throw new NullPointerException(" attempted to set mount with a null FCID. bug. "); throw new NullPointerException(" attempted to set mount with a null FCID. bug. ");

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.dialogs.optimization; package net.sf.openrocket.gui.dialogs.optimization;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Font; import java.awt.Font;
import java.util.Enumeration; import java.util.Enumeration;
@ -17,6 +18,7 @@ import javax.swing.tree.TreePath;
import net.sf.openrocket.gui.components.BasicTree; import net.sf.openrocket.gui.components.BasicTree;
import net.sf.openrocket.gui.main.ComponentIcons; import net.sf.openrocket.gui.main.ComponentIcons;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.optimization.rocketoptimization.SimulationModifier; import net.sf.openrocket.optimization.rocketoptimization.SimulationModifier;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -38,6 +40,15 @@ public class SimulationModifierTree extends BasicTree {
private final List<SimulationModifier> selectedModifiers; private final List<SimulationModifier> selectedModifiers;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static Color textColor;
private static Color dimTextColor;
private static Color textSelectionForegroundColor;
private static Color textSelectionBackgroundColor;
static {
initColors();
}
/** /**
* Sole constructor. * Sole constructor.
* *
@ -58,6 +69,18 @@ public class SimulationModifierTree extends BasicTree {
expandComponents(); expandComponents();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationModifierTree::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
textSelectionForegroundColor = GUIUtil.getUITheme().getTextSelectionForegroundColor();
textSelectionBackgroundColor = GUIUtil.getUITheme().getTextSelectionBackgroundColor();
}
/** /**
* Populate the simulation modifier tree from the provided information. This can be used to update * Populate the simulation modifier tree from the provided information. This can be used to update
@ -157,7 +180,7 @@ public class SimulationModifierTree extends BasicTree {
// Set text color/style // Set text color/style
if (object instanceof RocketComponent) { if (object instanceof RocketComponent) {
setForeground(GUIUtil.getUITheme().getDimTextColor()); setForeground(dimTextColor);
setFont(componentFont); setFont(componentFont);
// Set tooltip // Set tooltip
@ -171,21 +194,21 @@ public class SimulationModifierTree extends BasicTree {
this.setToolTipText(null); this.setToolTipText(null);
} }
} else if (object instanceof String) { } else if (object instanceof String) {
setForeground(GUIUtil.getUITheme().getDimTextColor()); setForeground(dimTextColor);
setFont(stringFont); setFont(stringFont);
} else if (object instanceof SimulationModifier) { } else if (object instanceof SimulationModifier) {
if (selectedModifiers.contains(object)) { if (selectedModifiers.contains(object)) {
setForeground(GUIUtil.getUITheme().getDimTextColor()); setForeground(dimTextColor);
setFont(stringFont); setFont(stringFont);
} else { } else {
if (tree.getSelectionRows() != null && if (tree.getSelectionRows() != null &&
IntStream.of(tree.getSelectionRows()).anyMatch(r -> r == row)) { IntStream.of(tree.getSelectionRows()).anyMatch(r -> r == row)) {
setForeground(GUIUtil.getUITheme().getTextSelectionForegroundColor()); setForeground(textSelectionForegroundColor);
setBackground(GUIUtil.getUITheme().getTextSelectionBackgroundColor()); setBackground(textSelectionBackgroundColor);
setOpaque(true); setOpaque(true);
} else { } else {
setForeground(GUIUtil.getUITheme().getTextColor()); setForeground(textColor);
} }
setFont(modifierFont); setFont(modifierFont);
} }

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.dialogs.preferences; package net.sf.openrocket.gui.dialogs.preferences;
import java.awt.Color;
import java.awt.LayoutManager; import java.awt.LayoutManager;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -24,6 +25,7 @@ import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.models.atmosphere.ExtendedISAModel; import net.sf.openrocket.models.atmosphere.ExtendedISAModel;
import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.SimulationOptions;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
@ -31,6 +33,11 @@ import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.StateChangeListener;
public class LaunchPreferencesPanel extends PreferencesPanel { public class LaunchPreferencesPanel extends PreferencesPanel {
private static Color darkWarningColor;
static {
initColors();
}
public LaunchPreferencesPanel(JDialog parent, LayoutManager layout) { public LaunchPreferencesPanel(JDialog parent, LayoutManager layout) {
super(parent, layout); super(parent, layout);
@ -44,7 +51,7 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
StyledLabel warning = new StyledLabel(String.format( StyledLabel warning = new StyledLabel(String.format(
"<html>%s</html>", trans.get("pref.dlg.lbl.launchWarning")), "<html>%s</html>", trans.get("pref.dlg.lbl.launchWarning")),
0.5f, StyledLabel.Style.BOLD); 0.5f, StyledLabel.Style.BOLD);
warning.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); warning.setFontColor(darkWarningColor);
warning.setToolTipText(trans.get("pref.dlg.lbl.launchWarning.ttip")); warning.setToolTipText(trans.get("pref.dlg.lbl.launchWarning.ttip"));
add(warning, "spanx, growx 0, gapbottom para, wrap"); add(warning, "spanx, growx 0, gapbottom para, wrap");
@ -451,6 +458,15 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(LaunchPreferencesPanel::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
private String getIntensityDescription(double i) { private String getIntensityDescription(double i) {
if (i < 0.001) if (i < 0.001)
// // None // // None

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.dialogs.preferences; package net.sf.openrocket.gui.dialogs.preferences;
import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -18,6 +19,7 @@ import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.simulation.RK4SimulationStepper; import net.sf.openrocket.simulation.RK4SimulationStepper;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.GeodeticComputationStrategy; import net.sf.openrocket.util.GeodeticComputationStrategy;
@ -26,6 +28,12 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
public class SimulationPreferencesPanel extends PreferencesPanel { public class SimulationPreferencesPanel extends PreferencesPanel {
private static final long serialVersionUID = 7983195730016979888L; private static final long serialVersionUID = 7983195730016979888L;
private static Color darkWarningColor;
static {
initColors();
}
/* /*
* private GeodeticComputationStrategy geodeticComputation = * private GeodeticComputationStrategy geodeticComputation =
* GeodeticComputationStrategy.SPHERICAL; * GeodeticComputationStrategy.SPHERICAL;
@ -85,7 +93,7 @@ public class SimulationPreferencesPanel extends PreferencesPanel {
StyledLabel warning = new StyledLabel(String.format( StyledLabel warning = new StyledLabel(String.format(
"<html>%s</html>", trans.get("pref.dlg.lbl.launchWarning")), "<html>%s</html>", trans.get("pref.dlg.lbl.launchWarning")),
0, StyledLabel.Style.BOLD); 0, StyledLabel.Style.BOLD);
warning.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); warning.setFontColor(darkWarningColor);
warning.setToolTipText(trans.get("pref.dlg.lbl.launchWarning.ttip")); warning.setToolTipText(trans.get("pref.dlg.lbl.launchWarning.ttip"));
subsub.add(warning, "spanx, wrap para"); subsub.add(warning, "spanx, wrap para");
@ -294,4 +302,13 @@ public class SimulationPreferencesPanel extends PreferencesPanel {
* public void fireContentsChanged() { super.fireContentsChanged(this, 0, * public void fireContentsChanged() { super.fireContentsChanged(this, 0,
* getSize()); } } * getSize()); } }
*/ */
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationPreferencesPanel::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
} }

View File

@ -35,6 +35,7 @@ import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputAdapter; import javax.swing.event.MouseInputAdapter;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -99,12 +100,18 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
RocketRenderer rr = new FigureRenderer(); RocketRenderer rr = new FigureRenderer();
private static Color backgroundColor;
static {
initColors();
}
public RocketFigure3d(final OpenRocketDocument document) { public RocketFigure3d(final OpenRocketDocument document) {
this.document = document; this.document = document;
this.rkt = document.getRocket(); this.rkt = document.getRocket();
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
//Only initialize GL if 3d is enabled. // Only initialize GL if 3d is enabled.
if (is3dEnabled()) { if (is3dEnabled()) {
//Fixes a linux / X bug: Splash must be closed before GL Init //Fixes a linux / X bug: Splash must be closed before GL Init
SplashScreen splash = Splash.getSplashScreen(); SplashScreen splash = Splash.getSplashScreen();
@ -115,6 +122,15 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
} }
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RocketFigure3d::updateColors);
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
}
public void flushTextureCaches() { public void flushTextureCaches() {
((GLAutoDrawable) canvas).invoke(true, new GLRunnable() { ((GLAutoDrawable) canvas).invoke(true, new GLRunnable() {
@Override @Override
@ -289,7 +305,6 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
GL2 gl = drawable.getGL().getGL2(); GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU(); GLU glu = new GLU();
Color backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
gl.glClearColor(backgroundColor.getRed()/255f, backgroundColor.getGreen()/255f, gl.glClearColor(backgroundColor.getRed()/255f, backgroundColor.getGreen()/255f,
backgroundColor.getBlue()/255f, backgroundColor.getAlpha()/255f); backgroundColor.getBlue()/255f, backgroundColor.getAlpha()/255f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.figureelements; package net.sf.openrocket.gui.figureelements;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Area; import java.awt.geom.Area;
@ -19,6 +20,12 @@ public class CGCaret extends Caret {
private static Area caret = null; private static Area caret = null;
private static Color CGColor;
static {
initColors();
}
/** /**
* Create a new CGCaret at the specified coordinates. * Create a new CGCaret at the specified coordinates.
*/ */
@ -26,6 +33,15 @@ public class CGCaret extends Caret {
super(x,y); super(x,y);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(CGCaret::updateColors);
}
private static void updateColors() {
CGColor = GUIUtil.getUITheme().getCGColor();
}
/** /**
* Returns the Area corresponding to the caret. The Area object is created only once, * Returns the Area corresponding to the caret. The Area object is created only once,
* after which the object is cloned for new copies. * after which the object is cloned for new copies.
@ -58,7 +74,7 @@ public class CGCaret extends Caret {
*/ */
@Override @Override
protected Color getColor() { protected Color getColor() {
return GUIUtil.getUITheme().getCGColor(); return CGColor;
} }
} }

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.figureelements; package net.sf.openrocket.gui.figureelements;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Area; import java.awt.geom.Area;
@ -18,6 +19,12 @@ public class CPCaret extends Caret {
private static Area caret = null; private static Area caret = null;
private static Color CPColor;
static {
initColors();
}
/** /**
* Create a new CPCaret at the specified coordinates. * Create a new CPCaret at the specified coordinates.
*/ */
@ -25,6 +32,15 @@ public class CPCaret extends Caret {
super(x,y); super(x,y);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(CPCaret::updateColors);
}
private static void updateColors() {
CPColor = GUIUtil.getUITheme().getCPColor();
}
/** /**
* Returns the Area object of the caret. The Area object is created only once, * Returns the Area object of the caret. The Area object is created only once,
* after which new copies are cloned from it. * after which new copies are cloned from it.
@ -53,6 +69,6 @@ public class CPCaret extends Caret {
*/ */
@Override @Override
protected Color getColor() { protected Color getColor() {
return GUIUtil.getUITheme().getCPColor(); return CPColor;
} }
} }

View File

@ -3,6 +3,7 @@ package net.sf.openrocket.gui.figureelements;
import static net.sf.openrocket.util.Chars.ALPHA; import static net.sf.openrocket.util.Chars.ALPHA;
import static net.sf.openrocket.util.Chars.THETA; import static net.sf.openrocket.util.Chars.THETA;
import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -12,6 +13,7 @@ import java.awt.geom.Rectangle2D;
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.logging.Warning; import net.sf.openrocket.logging.Warning;
import net.sf.openrocket.logging.WarningSet; import net.sf.openrocket.logging.WarningSet;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
@ -65,6 +67,15 @@ public class RocketInfo implements FigureElement {
private float line = 0; private float line = 0;
private float x1, x2, y1, y2; private float x1, x2, y1, y2;
private static Color textColor;
private static Color dimTextColor;
private static Color warningColor;
private static Color flightDataTextActiveColor;
private static Color flightDataTextInactiveColor;
static {
initColors();
}
public RocketInfo(FlightConfiguration configuration) { public RocketInfo(FlightConfiguration configuration) {
this.configuration = configuration; this.configuration = configuration;
@ -72,6 +83,19 @@ public class RocketInfo implements FigureElement {
this.secondaryStabilityUnits = UnitGroup.secondaryStabilityUnits(configuration); this.secondaryStabilityUnits = UnitGroup.secondaryStabilityUnits(configuration);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RocketInfo::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
warningColor = GUIUtil.getUITheme().getWarningColor();
flightDataTextActiveColor = GUIUtil.getUITheme().getFlightDataTextActiveColor();
flightDataTextInactiveColor = GUIUtil.getUITheme().getFlightDataTextInactiveColor();
}
@Override @Override
public void paint(Graphics2D myG2, double scale) { public void paint(Graphics2D myG2, double scale) {
@ -176,7 +200,7 @@ public class RocketInfo implements FigureElement {
GlyphVector massLineWithoutMotors = createText(massTextWithoutMotors); GlyphVector massLineWithoutMotors = createText(massTextWithoutMotors);
g2.setColor(GUIUtil.getUITheme().getTextColor()); g2.setColor(textColor);
g2.drawGlyphVector(name, x1, y1); g2.drawGlyphVector(name, x1, y1);
g2.drawGlyphVector(lengthLine, x1, y1+line); g2.drawGlyphVector(lengthLine, x1, y1+line);
@ -234,7 +258,7 @@ public class RocketInfo implements FigureElement {
unitWidth = unitWidth + spaceWidth; unitWidth = unitWidth + spaceWidth;
stabUnitWidth = stabUnitWidth + spaceWidth; stabUnitWidth = stabUnitWidth + spaceWidth;
g2.setColor(GUIUtil.getUITheme().getTextColor()); g2.setColor(textColor);
// Draw the stability, CG & CP values (and units) // Draw the stability, CG & CP values (and units)
g2.drawGlyphVector(stabValue, (float)(x2-stabRect.getWidth()), y1); g2.drawGlyphVector(stabValue, (float)(x2-stabRect.getWidth()), y1);
@ -261,7 +285,7 @@ public class RocketInfo implements FigureElement {
atPos = (float)(x2 - atTextRect.getWidth()); atPos = (float)(x2 - atTextRect.getWidth());
} }
g2.setColor(GUIUtil.getUITheme().getDimTextColor()); g2.setColor(dimTextColor);
g2.drawGlyphVector(atText, atPos, y1 + 3*line); g2.drawGlyphVector(atText, atPos, y1 + 3*line);
} }
@ -411,7 +435,7 @@ public class RocketInfo implements FigureElement {
float y = y2 - line * (texts.length-1); float y = y2 - line * (texts.length-1);
g2.setColor(GUIUtil.getUITheme().getWarningColor()); g2.setColor(warningColor);
for (GlyphVector v: texts) { for (GlyphVector v: texts) {
Rectangle2D rect = v.getVisualBounds(); Rectangle2D rect = v.getVisualBounds();
@ -427,7 +451,7 @@ public class RocketInfo implements FigureElement {
if (calculatingData) { if (calculatingData) {
//// Calculating... //// Calculating...
GlyphVector calculating = createText(trans.get("RocketInfo.Calculating")); GlyphVector calculating = createText(trans.get("RocketInfo.Calculating"));
g2.setColor(GUIUtil.getUITheme().getTextColor()); g2.setColor(textColor);
g2.drawGlyphVector(calculating, x1, (float)(y2-height)); g2.drawGlyphVector(calculating, x1, (float)(y2-height));
} }
} }
@ -485,17 +509,17 @@ public class RocketInfo implements FigureElement {
width += 5; width += 5;
if (!calculatingData) if (!calculatingData)
g2.setColor(GUIUtil.getUITheme().getFlightDataTextActiveColor()); g2.setColor(flightDataTextActiveColor);
else else
g2.setColor(GUIUtil.getUITheme().getFlightDataTextInactiveColor()); g2.setColor(flightDataTextInactiveColor);
g2.drawGlyphVector(apogee, (float)x1, (float)(y2-2*line)); g2.drawGlyphVector(apogee, x1, y2-2*line);
g2.drawGlyphVector(maxVelocity, (float)x1, (float)(y2-line)); g2.drawGlyphVector(maxVelocity, x1, y2-line);
g2.drawGlyphVector(maxAcceleration, (float)x1, (float)(y2)); g2.drawGlyphVector(maxAcceleration, x1, y2);
g2.drawGlyphVector(apogeeValue, (float)(x1+width), (float)(y2-2*line)); g2.drawGlyphVector(apogeeValue, (float)(x1+width), y2-2*line);
g2.drawGlyphVector(velocityValue, (float)(x1+width), (float)(y2-line)); g2.drawGlyphVector(velocityValue, (float)(x1+width), y2-line);
g2.drawGlyphVector(accelerationValue, (float)(x1+width), (float)(y2)); g2.drawGlyphVector(accelerationValue, (float)(x1+width), y2);
return 3*line; return 3*line;
} }

View File

@ -13,6 +13,7 @@ import java.util.Map;
import javax.swing.text.html.StyleSheet; import javax.swing.text.html.StyleSheet;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.BugException;
/** /**
@ -33,6 +34,11 @@ public class SlideSetManager {
private final String baseDir; private final String baseDir;
private final Map<String, SlideSet> slideSets = new LinkedHashMap<String, SlideSet>(); private final Map<String, SlideSet> slideSets = new LinkedHashMap<String, SlideSet>();
private static Color textColor;
static {
initColors();
}
/** /**
* Sole constructor. * Sole constructor.
@ -46,6 +52,15 @@ public class SlideSetManager {
this.baseDir = baseDir; this.baseDir = baseDir;
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SlideSetManager::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
}
/** /**
* Load all the tours. * Load all the tours.
@ -132,7 +147,6 @@ public class SlideSetManager {
try { try {
StyleSheet ss = new StyleSheet(); StyleSheet ss = new StyleSheet();
Color textColor = GUIUtil.getUITheme().getTextColor();
ss.addRule(String.format("p { color: rgb(%d, %d, %d, %d)", ss.addRule(String.format("p { color: rgb(%d, %d, %d, %d)",
textColor.getRed(), textColor.getGreen(), textColor.getBlue(), textColor.getAlpha())); textColor.getRed(), textColor.getGreen(), textColor.getBlue(), textColor.getAlpha()));
InputStreamReader reader = new InputStreamReader(in, "UTF-8"); InputStreamReader reader = new InputStreamReader(in, "UTF-8");

View File

@ -7,12 +7,14 @@ import javax.swing.JEditorPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import javax.swing.border.Border;
import javax.swing.event.HyperlinkListener; import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet; import javax.swing.text.html.StyleSheet;
import net.sf.openrocket.gui.components.ImageDisplayComponent; import net.sf.openrocket.gui.components.ImageDisplayComponent;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
/** /**
* Component that displays a single slide, with the image on top and * Component that displays a single slide, with the image on top and
@ -30,6 +32,12 @@ public class SlideShowComponent extends JSplitPane {
private final ImageDisplayComponent imageDisplay; private final ImageDisplayComponent imageDisplay;
private final JEditorPane textPane; private final JEditorPane textPane;
private static Border border;
static {
initColors();
}
public SlideShowComponent() { public SlideShowComponent() {
super(VERTICAL_SPLIT); super(VERTICAL_SPLIT);
@ -45,12 +53,21 @@ public class SlideShowComponent extends JSplitPane {
textPane.setPreferredSize(new Dimension(WIDTH, HEIGHT_TEXT)); textPane.setPreferredSize(new Dimension(WIDTH, HEIGHT_TEXT));
JScrollPane scrollPanel = new JScrollPane(textPane); JScrollPane scrollPanel = new JScrollPane(textPane);
textPane.setBorder(GUIUtil.getUITheme().getBorder()); textPane.setBorder(border);
this.setRightComponent(scrollPanel); this.setRightComponent(scrollPanel);
this.setResizeWeight(((double) HEIGHT_IMAGE) / (HEIGHT_IMAGE + HEIGHT_TEXT)); this.setResizeWeight(((double) HEIGHT_IMAGE) / (HEIGHT_IMAGE + HEIGHT_TEXT));
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SlideShowComponent::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
public void setSlide(Slide slide) { public void setSlide(Slide slide) {

View File

@ -5,6 +5,7 @@ import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.configdialog.ComponentConfigDialog; import net.sf.openrocket.gui.configdialog.ComponentConfigDialog;
import net.sf.openrocket.gui.main.componenttree.ComponentTree; import net.sf.openrocket.gui.main.componenttree.ComponentTree;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.widgets.IconButton; import net.sf.openrocket.gui.widgets.IconButton;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
@ -24,6 +25,7 @@ import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
@ -51,6 +53,12 @@ public class DesignPanel extends JSplitPane {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private final Component tree; private final Component tree;
private static Border border;
static {
initColors();
}
public DesignPanel(final BasicFrame parent, final OpenRocketDocument document, final ComponentTree tree) { public DesignPanel(final BasicFrame parent, final OpenRocketDocument document, final ComponentTree tree) {
super(JSplitPane.HORIZONTAL_SPLIT, true); super(JSplitPane.HORIZONTAL_SPLIT, true);
setResizeWeight(0.5); setResizeWeight(0.5);
@ -174,7 +182,7 @@ public class DesignPanel extends JSplitPane {
// Place tree inside scroll pane // Place tree inside scroll pane
JScrollPane scroll = new JScrollPane(tree); JScrollPane scroll = new JScrollPane(tree);
tree.setBorder(GUIUtil.getUITheme().getBorder()); tree.setBorder(border);
panel.add(scroll, "spany, wmin 140px, grow, wrap"); panel.add(scroll, "spany, wmin 140px, grow, wrap");
@ -230,6 +238,15 @@ public class DesignPanel extends JSplitPane {
this.setRightComponent(panel); this.setRightComponent(panel);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(DesignPanel::updateColors);
}
private static void updateColors() {
border = GUIUtil.getUITheme().getBorder();
}
/** /**
* Highlight all child components of a stage/rocket/podset when it is selected * Highlight all child components of a stage/rocket/podset when it is selected
* @param tree the tree in which the component selection took place * @param tree the tree in which the component selection took place

View File

@ -1,12 +1,14 @@
package net.sf.openrocket.gui.main.componenttree; package net.sf.openrocket.gui.main.componenttree;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.Font; import java.awt.Font;
import java.util.List; import java.util.List;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -18,6 +20,7 @@ import javax.swing.tree.TreePath;
import net.sf.openrocket.gui.main.ComponentIcons; import net.sf.openrocket.gui.main.ComponentIcons;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.MassComponent; import net.sf.openrocket.rocketcomponent.MassComponent;
import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType; import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType;
@ -32,6 +35,21 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static Color textSelectionBackgroundColor;
private static Color textSelectionForegroundColor;
private static Color componentTreeBackgroundColor;
private static Color componentTreeForegroundColor;
private static Icon massOverrideSubcomponentIcon;
private static Icon massOverrideIcon;
private static Icon CGOverrideSubcomponentIcon;
private static Icon CGOverrideIcon;
private static Icon CDOverrideSubcomponentIcon;
private static Icon CDOverrideIcon;
static {
initColors();
}
@Override @Override
public Component getTreeCellRendererComponent(JTree tree, Object value, public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean sel, boolean expanded, boolean leaf, int row,
@ -81,12 +99,12 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
// Set the background and foreground colors of the text JLabel // Set the background and foreground colors of the text JLabel
if (sel) { if (sel) {
textLabel.setOpaque(true); textLabel.setOpaque(true);
textLabel.setBackground(GUIUtil.getUITheme().getTextSelectionBackgroundColor()); textLabel.setBackground(textSelectionBackgroundColor);
textLabel.setForeground(GUIUtil.getUITheme().getTextSelectionForegroundColor()); textLabel.setForeground(textSelectionForegroundColor);
} else { } else {
textLabel.setOpaque(true); // Set this to true to allow the background color to be visible textLabel.setOpaque(true); // Set this to true to allow the background color to be visible
textLabel.setBackground(GUIUtil.getUITheme().getComponentTreeBackgroundColor()); textLabel.setBackground(componentTreeBackgroundColor);
textLabel.setForeground(GUIUtil.getUITheme().getComponentTreeForegroundColor()); textLabel.setForeground(componentTreeForegroundColor);
} }
applyToolTipText(components, c, panel); applyToolTipText(components, c, panel);
@ -99,23 +117,23 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
c.isCDOverridden() || c.getCDOverriddenBy() != null) { c.isCDOverridden() || c.getCDOverriddenBy() != null) {
JPanel p = new JPanel(); JPanel p = new JPanel();
p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1)); p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
p.setBackground(GUIUtil.getUITheme().getComponentTreeBackgroundColor()); p.setBackground(componentTreeBackgroundColor);
p.setForeground(GUIUtil.getUITheme().getComponentTreeForegroundColor()); p.setForeground(componentTreeForegroundColor);
p.add(comp/* , BorderLayout.WEST */); p.add(comp/* , BorderLayout.WEST */);
if (c.getMassOverriddenBy() != null) { if (c.getMassOverriddenBy() != null) {
p.add(new JLabel(GUIUtil.getUITheme().getMassOverrideSubcomponentIcon())); p.add(new JLabel(massOverrideSubcomponentIcon));
} else if (c.isMassOverridden()) { } else if (c.isMassOverridden()) {
p.add(new JLabel(GUIUtil.getUITheme().getMassOverrideIcon())); p.add(new JLabel(massOverrideIcon));
} }
if (c.getCGOverriddenBy() != null) { if (c.getCGOverriddenBy() != null) {
p.add(new JLabel(GUIUtil.getUITheme().getCGOverrideSubcomponentIcon())); p.add(new JLabel(CGOverrideSubcomponentIcon));
} else if (c.isCGOverridden()) { } else if (c.isCGOverridden()) {
p.add(new JLabel(GUIUtil.getUITheme().getCGOverrideIcon())); p.add(new JLabel(CGOverrideIcon));
} }
if (c.getCDOverriddenBy() != null) { if (c.getCDOverriddenBy() != null) {
p.add(new JLabel(GUIUtil.getUITheme().getCDOverrideSubcomponentIcon())); p.add(new JLabel(CDOverrideSubcomponentIcon));
} else if (c.isCDOverridden()) { } else if (c.isCDOverridden()) {
p.add(new JLabel(GUIUtil.getUITheme().getCDOverrideIcon())); p.add(new JLabel(CDOverrideIcon));
} }
// Make sure the tooltip also works on the override icons // Make sure the tooltip also works on the override icons
@ -131,6 +149,25 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
return comp; return comp;
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ComponentTreeRenderer::updateColors);
}
private static void updateColors() {
textSelectionBackgroundColor = GUIUtil.getUITheme().getTextSelectionBackgroundColor();
textSelectionForegroundColor = GUIUtil.getUITheme().getTextSelectionForegroundColor();
componentTreeBackgroundColor = GUIUtil.getUITheme().getComponentTreeBackgroundColor();
componentTreeForegroundColor = GUIUtil.getUITheme().getComponentTreeForegroundColor();
massOverrideSubcomponentIcon = GUIUtil.getUITheme().getMassOverrideSubcomponentIcon();
massOverrideIcon = GUIUtil.getUITheme().getMassOverrideIcon();
CGOverrideSubcomponentIcon = GUIUtil.getUITheme().getCGOverrideSubcomponentIcon();
CGOverrideIcon = GUIUtil.getUITheme().getCGOverrideIcon();
CDOverrideSubcomponentIcon = GUIUtil.getUITheme().getCDOverrideSubcomponentIcon();
CDOverrideIcon = GUIUtil.getUITheme().getCDOverrideIcon();
}
private void applyToolTipText(List<RocketComponent> components, RocketComponent c, JComponent comp) { private void applyToolTipText(List<RocketComponent> components, RocketComponent c, JComponent comp) {
String tooltipText; String tooltipText;
if (components != null && components.size() > 1 && components.contains(c)) { if (components != null && components.size() > 1 && components.contains(c)) {

View File

@ -25,6 +25,7 @@ import javax.swing.table.DefaultTableCellRenderer;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.main.FlightConfigurationPanel; import net.sf.openrocket.gui.main.FlightConfigurationPanel;
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.util.ArrayList; import net.sf.openrocket.util.ArrayList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -56,6 +57,13 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
protected final Rocket rocket; protected final Rocket rocket;
protected final JTable table; protected final JTable table;
private static Color textColor;
private static Color dimTextColor;
static {
initColors();
}
public FlightConfigurablePanel(final FlightConfigurationPanel flightConfigurationPanel, OpenRocketDocument document, Rocket rocket) { public FlightConfigurablePanel(final FlightConfigurationPanel flightConfigurationPanel, OpenRocketDocument document, Rocket rocket) {
super(new MigLayout("fill")); super(new MigLayout("fill"));
this.flightConfigurationPanel = flightConfigurationPanel; this.flightConfigurationPanel = flightConfigurationPanel;
@ -67,6 +75,16 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
synchronizeConfigurationSelection(); synchronizeConfigurationSelection();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(FlightConfigurablePanel::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
dimTextColor = GUIUtil.getUITheme().getDimTextColor();
}
/** /**
* Update the data in the table, with component change event type {cce} * Update the data in the table, with component change event type {cce}
* @param cce index of the ComponentChangeEvent to use (e.g. ComponentChangeEvent.NONFUNCTIONAL_CHANGE) * @param cce index of the ComponentChangeEvent to use (e.g. ComponentChangeEvent.NONFUNCTIONAL_CHANGE)
@ -400,14 +418,14 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
c.setBorder(b); c.setBorder(b);
} }
protected final void shaded(JLabel label) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(GUIUtil.getUITheme().getDimTextColor());
}
protected final void regular(JLabel label) { protected final void regular(JLabel label) {
GUIUtil.changeFontStyle(label, Font.PLAIN); GUIUtil.changeFontStyle(label, Font.PLAIN);
label.setForeground(GUIUtil.getUITheme().getTextColor()); label.setForeground(textColor);
}
protected final void shaded(JLabel label) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(dimTextColor);
} }
protected abstract JLabel format( T component, FlightConfigurationId configId, JLabel label ); protected abstract JLabel format( T component, FlightConfigurationId configId, JLabel label );

View File

@ -1,5 +1,6 @@
package net.sf.openrocket.gui.plot; package net.sf.openrocket.gui.plot;
import java.awt.Color;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -24,6 +25,7 @@ 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.Icons; import net.sf.openrocket.gui.util.Icons;
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.widgets.SaveFileChooser; import net.sf.openrocket.gui.widgets.SaveFileChooser;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.simulation.FlightDataType;
@ -43,6 +45,12 @@ import org.jfree.chart.JFreeChart;
public class SimulationPlotDialog extends JDialog { public class SimulationPlotDialog extends JDialog {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static Color darkWarningColor;
static {
initColors();
}
private SimulationPlotDialog(Window parent, Simulation simulation, PlotConfiguration config) { private SimulationPlotDialog(Window parent, Simulation simulation, PlotConfiguration config) {
//// Flight data plot //// Flight data plot
super(parent, simulation.getName()); super(parent, simulation.getName());
@ -73,7 +81,7 @@ public class SimulationPlotDialog extends JDialog {
// Add warning if X axis type is not time // Add warning if X axis type is not time
if (config.getDomainAxisType() != FlightDataType.TYPE_TIME) { if (config.getDomainAxisType() != FlightDataType.TYPE_TIME) {
JLabel msg = new StyledLabel(trans.get("PlotDialog.lbl.timeSeriesWarning"), -2); JLabel msg = new StyledLabel(trans.get("PlotDialog.lbl.timeSeriesWarning"), -2);
msg.setForeground(GUIUtil.getUITheme().getDarkWarningColor()); msg.setForeground(darkWarningColor);
panel.add(msg, "wrap"); panel.add(msg, "wrap");
} }
@ -155,7 +163,7 @@ public class SimulationPlotDialog extends JDialog {
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
doPngExport(chartPanel,jChart); doPNGExport(chartPanel,jChart);
} }
}); });
panel.add(button, "gapleft rel"); panel.add(button, "gapleft rel");
@ -178,7 +186,16 @@ public class SimulationPlotDialog extends JDialog {
GUIUtil.rememberWindowPosition(this); GUIUtil.rememberWindowPosition(this);
} }
private boolean doPngExport(ChartPanel chartPanel, JFreeChart chart){ private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationPlotDialog::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
private boolean doPNGExport(ChartPanel chartPanel, JFreeChart chart){
JFileChooser chooser = new SaveFileChooser(); JFileChooser chooser = new SaveFileChooser();
chooser.setAcceptAllFileFilterUsed(false); chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(FileHelper.PNG_FILTER); chooser.setFileFilter(FileHelper.PNG_FILTER);

View File

@ -12,6 +12,7 @@ import java.util.List;
import javax.swing.JPanel; import javax.swing.JPanel;
import net.sf.openrocket.gui.util.UITheme;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -55,6 +56,12 @@ public abstract class AbstractScaleFigure extends JPanel {
protected final List<EventListener> listeners = new LinkedList<EventListener>(); protected final List<EventListener> listeners = new LinkedList<EventListener>();
private static Color backgroundColor;
static {
initColors();
}
public AbstractScaleFigure() { public AbstractScaleFigure() {
// produces a pixels-per-meter scale factor // produces a pixels-per-meter scale factor
@ -70,10 +77,19 @@ public abstract class AbstractScaleFigure extends JPanel {
this.setPreferredSize(new Dimension(100,100)); this.setPreferredSize(new Dimension(100,100));
setSize(100,100); setSize(100,100);
setBackground(GUIUtil.getUITheme().getBackgroundColor()); setBackground(backgroundColor);
setOpaque(true); setOpaque(true);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(AbstractScaleFigure::updateColors);
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
}
public int getBorderHeight(){ return borderThickness_px.height; } public int getBorderHeight(){ return borderThickness_px.height; }
public int getBorderWidth(){ return borderThickness_px.width; } public int getBorderWidth(){ return borderThickness_px.width; }

View File

@ -1,6 +1,7 @@
package net.sf.openrocket.gui.scalefigure; package net.sf.openrocket.gui.scalefigure;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
@ -15,6 +16,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.rocketcomponent.FreeformFinSet; import net.sf.openrocket.rocketcomponent.FreeformFinSet;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.SymmetricComponent; import net.sf.openrocket.rocketcomponent.SymmetricComponent;
@ -57,15 +59,40 @@ public class FinPointFigure extends AbstractScaleFigure {
private Rectangle2D.Double[] finPointHandles = null; private Rectangle2D.Double[] finPointHandles = null;
private int selectedIndex = -1; private int selectedIndex = -1;
private static Color backgroundColor;
private static Color finPointBodyLineColor;
private static Color finPointGridMajorLineColor;
private static Color finPointGridMinorLineColor;
private static Color finPointPointColor;
private static Color finPointSelectedPointColor;
static {
initColors();
}
public FinPointFigure(FreeformFinSet finset) { public FinPointFigure(FreeformFinSet finset) {
this.finset = finset; this.finset = finset;
setBackground(GUIUtil.getUITheme().getBackgroundColor()); setBackground(backgroundColor);
setOpaque(true); setOpaque(true);
updateFigure(); updateFigure();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(FinPointFigure::updateColors);
}
private static void updateColors() {
backgroundColor = GUIUtil.getUITheme().getBackgroundColor();
finPointBodyLineColor = GUIUtil.getUITheme().getFinPointBodyLineColor();
finPointGridMajorLineColor = GUIUtil.getUITheme().getFinPointGridMajorLineColor();
finPointGridMinorLineColor = GUIUtil.getUITheme().getFinPointGridMinorLineColor();
finPointPointColor = GUIUtil.getUITheme().getFinPointPointColor();
finPointSelectedPointColor = GUIUtil.getUITheme().getFinPointSelectedPointColor();
}
@Override @Override
public Point getAutoZoomPoint(){ public Point getAutoZoomPoint(){
return new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0); return new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0);
@ -122,11 +149,11 @@ public class FinPointFigure extends AbstractScaleFigure {
Line2D.Double line = new Line2D.Double(); Line2D.Double line = new Line2D.Double();
for (Tick t : verticalTicks) { for (Tick t : verticalTicks) {
if (t.major) { if (t.major) {
g2.setColor(GUIUtil.getUITheme().getFinPointGridMajorLineColor()); g2.setColor(finPointGridMajorLineColor);
line.setLine( t.value, y0, t.value, y1); line.setLine( t.value, y0, t.value, y1);
g2.draw(line); g2.draw(line);
}else{ }else{
g2.setColor(GUIUtil.getUITheme().getFinPointGridMinorLineColor()); g2.setColor(finPointGridMinorLineColor);
line.setLine( t.value, y0, t.value, y1); line.setLine( t.value, y0, t.value, y1);
g2.draw(line); g2.draw(line);
} }
@ -136,11 +163,11 @@ public class FinPointFigure extends AbstractScaleFigure {
Tick[] horizontalTicks = unit.getTicks(y0, y1, MINOR_TICKS / this.scale, MAJOR_TICKS / this.scale); Tick[] horizontalTicks = unit.getTicks(y0, y1, MINOR_TICKS / this.scale, MAJOR_TICKS / this.scale);
for (Tick t : horizontalTicks) { for (Tick t : horizontalTicks) {
if (t.major) { if (t.major) {
g2.setColor(GUIUtil.getUITheme().getFinPointGridMajorLineColor()); g2.setColor(finPointGridMajorLineColor);
line.setLine( x0, t.value, x1, t.value); line.setLine( x0, t.value, x1, t.value);
g2.draw(line); g2.draw(line);
}else{ }else{
g2.setColor(GUIUtil.getUITheme().getFinPointGridMinorLineColor()); g2.setColor(finPointGridMinorLineColor);
line.setLine( x0, t.value, x1, t.value); line.setLine( x0, t.value, x1, t.value);
g2.draw(line); g2.draw(line);
} }
@ -163,7 +190,7 @@ public class FinPointFigure extends AbstractScaleFigure {
// setup lines // setup lines
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale ); final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g2.setColor(GUIUtil.getUITheme().getFinPointBodyLineColor()); g2.setColor(finPointBodyLineColor);
Transition body = (Transition) finset.getParent(); Transition body = (Transition) finset.getParent();
final float xResolution_m = 0.01f; // distance between draw points, in meters final float xResolution_m = 0.01f; // distance between draw points, in meters
@ -213,7 +240,7 @@ public class FinPointFigure extends AbstractScaleFigure {
final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale ); final float bodyLineWidth = (float) ( LINE_WIDTH_BODY_PIXELS / scale );
g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setStroke(new BasicStroke( bodyLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g2.setColor(GUIUtil.getUITheme().getFinPointBodyLineColor()); g2.setColor(finPointBodyLineColor);
g2.draw(shape); g2.draw(shape);
} }
@ -230,12 +257,12 @@ public class FinPointFigure extends AbstractScaleFigure {
final float finEdgeWidth_m = (float) (LINE_WIDTH_FIN_PIXELS / scale ); final float finEdgeWidth_m = (float) (LINE_WIDTH_FIN_PIXELS / scale );
g2.setStroke(new BasicStroke( finEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setStroke(new BasicStroke( finEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g2.setColor(GUIUtil.getUITheme().getFinPointBodyLineColor()); g2.setColor(finPointBodyLineColor);
g2.draw(shape); g2.draw(shape);
} }
private void paintFinHandles(final Graphics2D g2) { private void paintFinHandles(final Graphics2D g2) {
// excludes fin tab points // Excludes fin tab points
final Coordinate[] drawPoints = finset.getFinPoints(); final Coordinate[] drawPoints = finset.getFinPoints();
// Fin point boxes // Fin point boxes
@ -244,7 +271,7 @@ public class FinPointFigure extends AbstractScaleFigure {
final float boxEdgeWidth_m = (float) ( LINE_WIDTH_BOX_PIXELS / scale ); final float boxEdgeWidth_m = (float) ( LINE_WIDTH_BOX_PIXELS / scale );
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
g2.setColor(GUIUtil.getUITheme().getFinPointPointColor()); g2.setColor(finPointPointColor);
finPointHandles = new Rectangle2D.Double[ drawPoints.length]; finPointHandles = new Rectangle2D.Double[ drawPoints.length];
for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) { for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) {
@ -256,15 +283,15 @@ public class FinPointFigure extends AbstractScaleFigure {
final Rectangle2D.Double selectedPointHighlight = new Rectangle2D.Double(c.x - selBoxHalfWidth, c.y - selBoxHalfWidth, selBoxWidth, selBoxWidth); final Rectangle2D.Double selectedPointHighlight = new Rectangle2D.Double(c.x - selBoxHalfWidth, c.y - selBoxHalfWidth, selBoxWidth, selBoxWidth);
// switch to the highlight color // Switch to the highlight color
g2.setColor(GUIUtil.getUITheme().getFinPointSelectedPointColor()); g2.setColor(finPointSelectedPointColor);
g2.draw(selectedPointHighlight); g2.draw(selectedPointHighlight);
// reset to the normal color // Reset to the normal color
g2.setColor(GUIUtil.getUITheme().getFinPointPointColor()); g2.setColor(finPointPointColor);
} }
// normal boxes // Normal boxes
finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth); finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
g2.draw(finPointHandles[currentIndex]); g2.draw(finPointHandles[currentIndex]);

View File

@ -18,6 +18,7 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.ParallelStage;
import net.sf.openrocket.rocketcomponent.PodSet; import net.sf.openrocket.rocketcomponent.PodSet;
@ -94,6 +95,13 @@ public class RocketFigure extends AbstractScaleFigure {
private final ArrayList<FigureElement> relativeExtra = new ArrayList<FigureElement>(); private final ArrayList<FigureElement> relativeExtra = new ArrayList<FigureElement>();
private final ArrayList<FigureElement> absoluteExtra = new ArrayList<FigureElement>(); private final ArrayList<FigureElement> absoluteExtra = new ArrayList<FigureElement>();
private static Color motorFillColor;
private static Color motorBorderColor;
static {
initColors();
}
/** /**
* Creates a new rocket figure. * Creates a new rocket figure.
@ -108,6 +116,16 @@ public class RocketFigure extends AbstractScaleFigure {
updateFigure(); updateFigure();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(RocketFigure::updateColors);
}
private static void updateColors() {
motorFillColor = GUIUtil.getUITheme().getMotorFillColor();
motorBorderColor = GUIUtil.getUITheme().getMotorBorderColor();
}
public Point getAutoZoomPoint(){ public Point getAutoZoomPoint(){
return new Point( Math.max(0, originLocation_px.x - borderThickness_px.width), return new Point( Math.max(0, originLocation_px.x - borderThickness_px.width),
Math.max(0, - borderThickness_px.height)); Math.max(0, - borderThickness_px.height));
@ -291,8 +309,8 @@ public class RocketFigure extends AbstractScaleFigure {
RenderingHints.VALUE_STROKE_NORMALIZE); RenderingHints.VALUE_STROKE_NORMALIZE);
// Draw motors // Draw motors
Color fillColor = GUIUtil.getUITheme().getMotorFillColor(); Color fillColor = motorFillColor;
Color borderColor = GUIUtil.getUITheme().getMotorBorderColor(); Color borderColor = motorBorderColor;
FlightConfiguration config = rocket.getSelectedConfiguration(); FlightConfiguration config = rocket.getSelectedConfiguration();
for (MotorConfiguration curInstance : config.getActiveMotors()) { for (MotorConfiguration curInstance : config.getActiveMotors()) {

View File

@ -26,6 +26,7 @@ import javax.swing.event.ChangeListener;
import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.unit.Tick; import net.sf.openrocket.unit.Tick;
import net.sf.openrocket.unit.Unit; import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
@ -72,6 +73,12 @@ public class ScaleScrollPane extends JScrollPane
private Point2D.Double viewCenter_frac = new Point2D.Double(0.5f, 0.5f); private Point2D.Double viewCenter_frac = new Point2D.Double(0.5f, 0.5f);
private static Color textColor;
static {
initColors();
}
/** /**
* Create a scale scroll pane. * Create a scale scroll pane.
* *
@ -128,6 +135,15 @@ public class ScaleScrollPane extends JScrollPane
viewport.addComponentListener(this); viewport.addComponentListener(this);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(ScaleScrollPane::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
}
public AbstractScaleFigure getFigure() { public AbstractScaleFigure getFigure() {
return figure; return figure;
} }
@ -399,7 +415,7 @@ public class ScaleScrollPane extends JScrollPane
} }
// Set color & hints // Set color & hints
g2.setColor(GUIUtil.getUITheme().getTextColor()); g2.setColor(textColor);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE); RenderingHints.VALUE_STROKE_NORMALIZE);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, g2.setRenderingHint(RenderingHints.KEY_RENDERING,

View File

@ -33,6 +33,7 @@ import net.sf.openrocket.document.events.DocumentChangeEvent;
import net.sf.openrocket.gui.components.ConfigurationComboBox; import net.sf.openrocket.gui.components.ConfigurationComboBox;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
@ -62,6 +63,12 @@ public class SimulationEditDialog extends JDialog {
private boolean isModified = false; // Whether the simulation has been modified private boolean isModified = false; // Whether the simulation has been modified
private final boolean isNewSimulation; // Whether you are editing a new simulation, or an existing one private final boolean isNewSimulation; // Whether you are editing a new simulation, or an existing one
private static Color multiCompEditColor;
static {
initColors();
}
public SimulationEditDialog(Window parent, final OpenRocketDocument document, boolean isNewSimulation, Simulation... sims) { public SimulationEditDialog(Window parent, final OpenRocketDocument document, boolean isNewSimulation, Simulation... sims) {
//// Edit simulation //// Edit simulation
super(parent, sims.length == 1 ? trans.get("simedtdlg.title.Editsim") : trans.get("simedtdlg.title.MultiSimEdit"), super(parent, sims.length == 1 ? trans.get("simedtdlg.title.Editsim") : trans.get("simedtdlg.title.MultiSimEdit"),
@ -103,6 +110,15 @@ public class SimulationEditDialog extends JDialog {
GUIUtil.setDisposableDialogOptions(this, null); GUIUtil.setDisposableDialogOptions(this, null);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationEditDialog::updateColors);
}
private static void updateColors() {
multiCompEditColor = GUIUtil.getUITheme().getMultiCompEditColor();
}
private boolean isSingleEdit() { private boolean isSingleEdit() {
return simulationList.length == 1; return simulationList.length == 1;
} }
@ -247,7 +263,7 @@ public class SimulationEditDialog extends JDialog {
//// Multi-simulation edit //// Multi-simulation edit
if (simulationList.length > 1) { if (simulationList.length > 1) {
StyledLabel multiSimEditLabel = new StyledLabel("", -1, StyledLabel.Style.BOLD); StyledLabel multiSimEditLabel = new StyledLabel("", -1, StyledLabel.Style.BOLD);
multiSimEditLabel.setFontColor(new Color(170, 0, 100)); multiSimEditLabel.setFontColor(multiCompEditColor);
multiSimEditLabel.setText(trans.get("simedtdlg.title.MultiSimEdit")); multiSimEditLabel.setText(trans.get("simedtdlg.title.MultiSimEdit"));
StringBuilder components = new StringBuilder(trans.get("simedtdlg.title.MultiSimEdit.ttip")); StringBuilder components = new StringBuilder(trans.get("simedtdlg.title.MultiSimEdit.ttip"));
for (int i = 0; i < simulationList.length; i++) { for (int i = 0; i < simulationList.length; i++) {

View File

@ -22,6 +22,7 @@ import javax.swing.JScrollPane;
import javax.swing.JSpinner; import javax.swing.JSpinner;
import javax.swing.MenuElement; import javax.swing.MenuElement;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
@ -36,6 +37,7 @@ import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.RK4SimulationStepper; import net.sf.openrocket.simulation.RK4SimulationStepper;
import net.sf.openrocket.simulation.SimulationOptions; import net.sf.openrocket.simulation.SimulationOptions;
@ -63,6 +65,13 @@ class SimulationOptionsPanel extends JPanel {
final JPopupMenu extensionMenu; final JPopupMenu extensionMenu;
JMenu extensionMenuCopyExtension; JMenu extensionMenuCopyExtension;
private static Color textColor;
private static Border border;
static {
initColors();
}
SimulationOptionsPanel(OpenRocketDocument document, final Simulation simulation) { SimulationOptionsPanel(OpenRocketDocument document, final Simulation simulation) {
super(new MigLayout("fill")); super(new MigLayout("fill"));
this.document = document; this.document = document;
@ -207,8 +216,8 @@ class SimulationOptionsPanel extends JPanel {
currentExtensions = new JPanel(new MigLayout("fillx, gap 0 0, ins 0")); currentExtensions = new JPanel(new MigLayout("fillx, gap 0 0, ins 0"));
JScrollPane scroll = new JScrollPane(currentExtensions); JScrollPane scroll = new JScrollPane(currentExtensions);
currentExtensions.setBorder(GUIUtil.getUITheme().getBorder()); currentExtensions.setBorder(border);
scroll.setForeground(GUIUtil.getUITheme().getTextColor()); scroll.setForeground(textColor);
// &#$%! scroll pane will not honor "growy"... // &#$%! scroll pane will not honor "growy"...
sub.add(scroll, "growx, growy, h 100%"); sub.add(scroll, "growx, growy, h 100%");
@ -216,6 +225,16 @@ class SimulationOptionsPanel extends JPanel {
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationOptionsPanel::updateColors);
}
private static void updateColors() {
textColor = GUIUtil.getUITheme().getTextColor();
border = GUIUtil.getUITheme().getBorder();
}
private JPopupMenu getExtensionMenu() { private JPopupMenu getExtensionMenu() {
Set<SimulationExtensionProvider> extensions = Application.getInjector().getInstance(new Key<Set<SimulationExtensionProvider>>() { Set<SimulationExtensionProvider> extensions = Application.getInjector().getInstance(new Key<Set<SimulationExtensionProvider>>() {
}); });

View File

@ -12,7 +12,6 @@ import javax.swing.BorderFactory;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -20,6 +19,7 @@ import javax.swing.JPanel;
import javax.swing.JRadioButton; import javax.swing.JRadioButton;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
@ -33,6 +33,7 @@ import net.sf.openrocket.gui.plot.SimulationPlotDialog;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
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.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightDataBranch; import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.simulation.FlightDataType;
@ -40,7 +41,6 @@ import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences; import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.Unit; import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.util.Color;
import net.sf.openrocket.util.Utils; import net.sf.openrocket.util.Utils;
import net.sf.openrocket.gui.widgets.SelectColorButton; import net.sf.openrocket.gui.widgets.SelectColorButton;
@ -109,6 +109,13 @@ public class SimulationPlotPanel extends JPanel {
private DescriptionArea simPlotPanelDesc; private DescriptionArea simPlotPanelDesc;
private static java.awt.Color darkWarningColor;
private static Border border;
static {
initColors();
}
public SimulationPlotPanel(final Simulation simulation) { public SimulationPlotPanel(final Simulation simulation) {
super(new MigLayout("fill")); super(new MigLayout("fill"));
@ -205,7 +212,7 @@ public class SimulationPlotPanel extends JPanel {
//// The data will be plotted in time order even if the X axis type is not time. //// The data will be plotted in time order even if the X axis type is not time.
simPlotPanelDesc = new DescriptionArea("", 2, -2f, false); simPlotPanelDesc = new DescriptionArea("", 2, -2f, false);
simPlotPanelDesc.setVisible(false); simPlotPanelDesc.setVisible(false);
simPlotPanelDesc.setForeground(GUIUtil.getUITheme().getDarkWarningColor()); simPlotPanelDesc.setForeground(darkWarningColor);
simPlotPanelDesc.setViewportBorder(BorderFactory.createEmptyBorder()); simPlotPanelDesc.setViewportBorder(BorderFactory.createEmptyBorder());
this.add(simPlotPanelDesc, "width 1px, growx 1, wrap unrel"); this.add(simPlotPanelDesc, "width 1px, growx 1, wrap unrel");
@ -220,7 +227,7 @@ public class SimulationPlotPanel extends JPanel {
typeSelectorPanel = new JPanel(new MigLayout("gapy rel")); typeSelectorPanel = new JPanel(new MigLayout("gapy rel"));
JScrollPane scroll = new JScrollPane(typeSelectorPanel); JScrollPane scroll = new JScrollPane(typeSelectorPanel);
scroll.setBorder(GUIUtil.getUITheme().getBorder()); scroll.setBorder(border);
this.add(scroll, "spany 3, height 10px, wmin 400lp, grow 100, gapright para"); this.add(scroll, "spany 3, height 10px, wmin 400lp, grow 100, gapright para");
@ -379,6 +386,16 @@ public class SimulationPlotPanel extends JPanel {
updatePlots(); updatePlots();
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(SimulationPlotPanel::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
border = GUIUtil.getUITheme().getBorder();
}
private void updateStyleEventWidgets(JLabel styleEventMarker, JRadioButton radioVerticalMarker, JRadioButton radioIcon) { private void updateStyleEventWidgets(JLabel styleEventMarker, JRadioButton radioVerticalMarker, JRadioButton radioIcon) {
if (modifying > 0) if (modifying > 0)
return; return;

View File

@ -4,6 +4,7 @@ package net.sf.openrocket.gui.util;
import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
/** /**
@ -12,6 +13,14 @@ import java.awt.Component;
* @author Sibo Van Gool <sibo.vangool@hotmail.com> * @author Sibo Van Gool <sibo.vangool@hotmail.com>
*/ */
public class BetterListCellRenderer extends DefaultListCellRenderer { public class BetterListCellRenderer extends DefaultListCellRenderer {
private static Color rowBackgroundDarkerColor;
private static Color rowBackgroundLighterColor;
private static Color textSelectionForegroundColor;
private static Color textColor;
static {
initColors();
}
@Override @Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, public Component getListCellRendererComponent(JList<?> list, Object value, int index,
@ -21,17 +30,29 @@ public class BetterListCellRenderer extends DefaultListCellRenderer {
// Alternating row colors // Alternating row colors
if (!isSelected) { if (!isSelected) {
if (index % 2 == 0) { if (index % 2 == 0) {
label.setBackground(GUIUtil.getUITheme().getRowBackgroundDarkerColor()); label.setBackground(rowBackgroundDarkerColor);
} else { } else {
label.setBackground(GUIUtil.getUITheme().getRowBackgroundLighterColor()); label.setBackground(rowBackgroundLighterColor);
} }
} }
// Text color // Text color
if (isSelected) { if (isSelected) {
label.setForeground(GUIUtil.getUITheme().getTextSelectionForegroundColor()); label.setForeground(textSelectionForegroundColor);
} else { } else {
label.setForeground(GUIUtil.getUITheme().getTextColor()); label.setForeground(textColor);
} }
return label; return label;
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(BetterListCellRenderer::updateColors);
}
private static void updateColors() {
rowBackgroundDarkerColor = GUIUtil.getUITheme().getRowBackgroundDarkerColor();
rowBackgroundLighterColor = GUIUtil.getUITheme().getRowBackgroundLighterColor();
textSelectionForegroundColor = GUIUtil.getUITheme().getTextSelectionForegroundColor();
textColor = GUIUtil.getUITheme().getTextColor();
}
} }

View File

@ -18,8 +18,10 @@ import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -43,6 +45,7 @@ public class UITheme {
Color getRowBackgroundDarkerColor(); Color getRowBackgroundDarkerColor();
Color getFlightDataTextActiveColor(); Color getFlightDataTextActiveColor();
Color getFlightDataTextInactiveColor(); Color getFlightDataTextInactiveColor();
Color getMultiCompEditColor();
// Component colors // Component colors
String getDefaultBodyComponentColor(); String getDefaultBodyComponentColor();
@ -83,6 +86,27 @@ public class UITheme {
Border getBorder(); Border getBorder();
void formatScriptTextArea(RSyntaxTextArea textArea); void formatScriptTextArea(RSyntaxTextArea textArea);
// Static list of listeners
static List<Runnable> themeChangeListeners = new ArrayList<>();
// Static method to add a listener
static void addUIThemeChangeListener(Runnable listener) {
// TODO: implement this once you have implemented invalidation for each listener so that we don't get memory leaks
//themeChangeListeners.add(listener);
}
// Static method to remove a listener
static void removeUIThemeChangeListener(Runnable listener) {
themeChangeListeners.remove(listener);
}
// Static method to notify all listeners
static void notifyUIThemeChangeListeners() {
for (Runnable listener : themeChangeListeners) {
listener.run();
}
}
} }
public static boolean isLightTheme(Theme theme) { public static boolean isLightTheme(Theme theme) {
@ -115,6 +139,9 @@ public class UITheme {
GUIUtil.setBestLAF(); GUIUtil.setBestLAF();
setGlobalFontSize(prefs.getUIFontSize()); setGlobalFontSize(prefs.getUIFontSize());
// After applying the theme settings, notify listeners
Theme.notifyUIThemeChangeListeners();
} }
@Override @Override
@ -182,6 +209,11 @@ public class UITheme {
return new Color(0,0,127,127); return new Color(0,0,127,127);
} }
@Override
public Color getMultiCompEditColor() {
return new Color(170, 0, 100);
}
@Override @Override
public String getDefaultBodyComponentColor() { public String getDefaultBodyComponentColor() {
return "0,0,240"; return "0,0,240";
@ -338,6 +370,9 @@ public class UITheme {
LafManager.install(new DarculaTheme()); LafManager.install(new DarculaTheme());
setGlobalFontSize(prefs.getUIFontSize()); setGlobalFontSize(prefs.getUIFontSize());
// After applying the theme settings, notify listeners
Theme.notifyUIThemeChangeListeners();
} }
@Override @Override
@ -405,6 +440,11 @@ public class UITheme {
return new Color(128, 166, 230, 127); return new Color(128, 166, 230, 127);
} }
@Override
public Color getMultiCompEditColor() {
return new Color(222, 146, 176);
}
@Override @Override
public String getDefaultBodyComponentColor() { public String getDefaultBodyComponentColor() {
return "150,162,255"; return "150,162,255";
@ -639,6 +679,11 @@ public class UITheme {
return getCurrentTheme().getFlightDataTextInactiveColor(); return getCurrentTheme().getFlightDataTextInactiveColor();
} }
@Override
public Color getMultiCompEditColor() {
return getCurrentTheme().getMultiCompEditColor();
}
@Override @Override
public String getDefaultBodyComponentColor() { public String getDefaultBodyComponentColor() {
return getCurrentTheme().getDefaultBodyComponentColor(); return getCurrentTheme().getDefaultBodyComponentColor();

View File

@ -10,11 +10,14 @@ import javax.swing.event.DocumentListener;
import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.UITheme;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.plugin.Plugin; import net.sf.openrocket.plugin.Plugin;
import net.sf.openrocket.simulation.extension.AbstractSwingSimulationExtensionConfigurator; import net.sf.openrocket.simulation.extension.AbstractSwingSimulationExtensionConfigurator;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import java.awt.Color;
@Plugin @Plugin
public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> { public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> {
private JavaCode extension; private JavaCode extension;
@ -23,10 +26,25 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private static Color darkWarningColor;
static {
initColors();
}
public JavaCodeConfigurator() { public JavaCodeConfigurator() {
super(JavaCode.class); super(JavaCode.class);
} }
private static void initColors() {
updateColors();
UITheme.Theme.addUIThemeChangeListener(JavaCodeConfigurator::updateColors);
}
private static void updateColors() {
darkWarningColor = GUIUtil.getUITheme().getDarkWarningColor();
}
@Override @Override
protected JComponent getConfigurationComponent(final JavaCode extension, Simulation simulation, JPanel panel) { protected JComponent getConfigurationComponent(final JavaCode extension, Simulation simulation, JPanel panel) {
this.extension = extension; this.extension = extension;
@ -35,7 +53,7 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig
classNameField = new JTextField(extension.getClassName()); classNameField = new JTextField(extension.getClassName());
panel.add(classNameField, "growx, wrap"); panel.add(classNameField, "growx, wrap");
this.errorMsg = new StyledLabel(); this.errorMsg = new StyledLabel();
errorMsg.setFontColor(GUIUtil.getUITheme().getDarkWarningColor()); errorMsg.setFontColor(darkWarningColor);
errorMsg.setVisible(false); errorMsg.setVisible(false);
panel.add(errorMsg, "growx, wrap"); panel.add(errorMsg, "growx, wrap");