diff --git a/diylc/diylc-core/src/main/resources/update.xml b/diylc/diylc-core/src/main/resources/update.xml index 80249130..41eaa9f1 100644 --- a/diylc/diylc-core/src/main/resources/update.xml +++ b/diylc/diylc-core/src/main/resources/update.xml @@ -433,6 +433,10 @@ IMPROVEMENT Improved sensitivity of 'Multimeter Probe' that required pixel-level precision to detect connectivity; improved rendering of the probe in outline mode + + IMPROVEMENT + Improve contrast of tooltips on some Linux machines that show white text against yellow ballon + BUG_FIX Fixed underside rendering and mirroring position issues that affected only SPDT 'Mini Toggle Switch' types diff --git a/diylc/diylc-swing/src/main/java/org/diylc/DIYLCStarter.java b/diylc/diylc-swing/src/main/java/org/diylc/DIYLCStarter.java index 1141aa09..9a504613 100644 --- a/diylc/diylc-swing/src/main/java/org/diylc/DIYLCStarter.java +++ b/diylc/diylc-swing/src/main/java/org/diylc/DIYLCStarter.java @@ -42,6 +42,7 @@ import org.diylc.serialization.ProjectFileManager; import org.diylc.swing.gui.MainFrame; import org.diylc.swing.gui.TemplateDialog; import org.diylc.swing.plugins.file.ProjectDrawingProvider; +import org.diylc.utils.SwingUtils; /** * Main class that runs DIYLC. @@ -138,6 +139,9 @@ public class DIYLCStarter { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + // Fix tooltip colors for Linux systems where they may be unreadable + SwingUtils.fixTooltipColors(); + // Apply configurable font scaling from VM argument: -Dorg.diylc.fontScaleFactor=X org.diylc.utils.FontScalingUtils.applyFontScaling(); } catch (Exception e) { diff --git a/diylc/diylc-swing/src/main/java/org/diylc/utils/SwingUtils.java b/diylc/diylc-swing/src/main/java/org/diylc/utils/SwingUtils.java new file mode 100644 index 00000000..f1458ef0 --- /dev/null +++ b/diylc/diylc-swing/src/main/java/org/diylc/utils/SwingUtils.java @@ -0,0 +1,71 @@ +/* + * + * DIY Layout Creator (DIYLC). + * Copyright (c) 2009-2025 held jointly by the individual authors. + * + * This file is part of DIYLC. + * + * DIYLC is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * DIYLC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DIYLC. If not, see . + * + */ +package org.diylc.utils; + +import java.awt.Color; +import java.util.function.Function; +import javax.swing.UIManager; + +/** + * Utility class for Swing UI-related operations. + * + * @author Branislav Stojkovic + */ +public class SwingUtils { + + /** + * Fixes tooltip colors for Linux systems where they may be unreadable. + * Some Linux L&F themes set white text on light backgrounds, making tooltips invisible. + * This method ensures tooltips always have dark text on light background for readability. + * + * Should be called after UIManager.setLookAndFeel() to override system defaults. + */ + public static void fixTooltipColors() { + Color tooltipBg = UIManager.getColor("ToolTip.background"); + Color tooltipFg = UIManager.getColor("ToolTip.foreground"); + + // Helper function to calculate brightness (0.0 = black, 1.0 = white) + Function getBrightness = (c) -> { + return (0.299 * c.getRed() + 0.587 * c.getGreen() + 0.114 * c.getBlue()) / 255.0; + }; + + // Check if we have a problematic color combination (light text on light background) + boolean needsFix = false; + if (tooltipFg != null && tooltipBg != null) { + double fgBrightness = getBrightness.apply(tooltipFg); + double bgBrightness = getBrightness.apply(tooltipBg); + // If both foreground and background are light, it's unreadable + if (fgBrightness > 0.7 && bgBrightness > 0.5) { + needsFix = true; + } + } else if (tooltipFg == null || tooltipBg == null) { + // Missing color definitions - set safe defaults + needsFix = true; + } + + if (needsFix) { + UIManager.put("ToolTip.background", new Color(255, 255, 220)); // Light yellow + UIManager.put("ToolTip.foreground", Color.BLACK); + } + } +} +