From 93581b03d723e55c60caedb4729ffc6ea808fe78 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 1 Oct 2019 15:13:04 +0200 Subject: [PATCH] Set foreground color in library/board manager Previously, only the background color was changed to white or light grey. This worked well for the default theme with a black or dark text, but not for a dark theme with white or light text. This commit fixes this by also overriding the text color to be black. Since the colors are set on the JPanel table cell, but the actual text is rendered by the description JTextPane, the `setForeground` method is overridden to forward the foreground color to the description pane. Note that this commit only touches the table cell and description inside, the dropdowns and buttons have neither background nor foreground color set (thus these use both colors from the system theme). It might be more consistent to also override these, but such native UI components are typically tricky to colorize properly, so best let the system handle that normally. An alternative solution would be only use the default colors, which would actually preserve the dark theme colors in these managers as well (rather than forcing black-on-white/grey as now). There are default colors for selected and non-selected table cells that could be used, but these are different from the current colors. Additionally, the current odd/even alternating colors are then also no longer available. --- .../libraries/ui/ContributedLibraryTableCellEditor.java | 1 + .../libraries/ui/ContributedLibraryTableCellJPanel.java | 7 +++++++ .../libraries/ui/ContributedLibraryTableCellRenderer.java | 1 + .../packages/ui/ContributedPlatformTableCellEditor.java | 1 + .../packages/ui/ContributedPlatformTableCellJPanel.java | 6 ++++++ .../packages/ui/ContributedPlatformTableCellRenderer.java | 1 + 6 files changed, 17 insertions(+) diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java index c5c2e4175..7c2ecff38 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java @@ -125,6 +125,7 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell { editorCell.versionToInstallChooser .setVisible(!mayInstalled.isPresent() && notInstalled.size() > 1); + editorCell.setForeground(Color.BLACK); editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3 return editorCell; } diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java index 560c9889b..cbd805ab7 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java @@ -265,4 +265,11 @@ public class ContributedLibraryTableCellJPanel extends JPanel { buttonsPanel.setVisible(enabled); inactiveButtonsPanel.setVisible(!enabled); } + + public void setForeground(Color c) { + super.setForeground(c); + // The description is not opaque, so copy our foreground color to it. + if (description != null) + description.setForeground(c); + } } diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java index bc4b3ffd9..d107f9020 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java @@ -46,6 +46,7 @@ public class ContributedLibraryTableCellRenderer implements TableCellRenderer { value, isSelected); cell.setButtonsVisible(false); + cell.setForeground(Color.BLACK); if (row % 2 == 0) { cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 } else { diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java index acfb58bb3..7fe221fa3 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java @@ -130,6 +130,7 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell { .setVisible(installed == null && uninstalledReleases.size() > 1); cell.update(table, _value, !installedBuiltIn.isEmpty()); + cell.setForeground(Color.BLACK); cell.setBackground(new Color(218, 227, 227)); // #dae3e3 return cell; } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java index 2f42a9026..616bfbea6 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java @@ -306,4 +306,10 @@ public class ContributedPlatformTableCellJPanel extends JPanel { inactiveButtonsPanel.setVisible(!enabled); } + public void setForeground(Color c) { + super.setForeground(c); + // The description is not opaque, so copy our foreground color to it. + if (description != null) + description.setForeground(c); + } } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java index 19d484dc2..b6f6aae01 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java @@ -46,6 +46,7 @@ public class ContributedPlatformTableCellRenderer implements TableCellRenderer { cell.setButtonsVisible(false); cell.update(table, value, false); + cell.setForeground(Color.BLACK); if (row % 2 == 0) { cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 } else {