1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-20 09:52:13 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2019-10-01 15:13:04 +02:00 committed by Cristian Maglie
parent 7d625181f6
commit 93581b03d7
6 changed files with 17 additions and 0 deletions

View File

@ -125,6 +125,7 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
editorCell.versionToInstallChooser editorCell.versionToInstallChooser
.setVisible(!mayInstalled.isPresent() && notInstalled.size() > 1); .setVisible(!mayInstalled.isPresent() && notInstalled.size() > 1);
editorCell.setForeground(Color.BLACK);
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3 editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
return editorCell; return editorCell;
} }

View File

@ -265,4 +265,11 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
buttonsPanel.setVisible(enabled); buttonsPanel.setVisible(enabled);
inactiveButtonsPanel.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);
}
} }

View File

@ -46,6 +46,7 @@ public class ContributedLibraryTableCellRenderer implements TableCellRenderer {
value, isSelected); value, isSelected);
cell.setButtonsVisible(false); cell.setButtonsVisible(false);
cell.setForeground(Color.BLACK);
if (row % 2 == 0) { if (row % 2 == 0) {
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
} else { } else {

View File

@ -130,6 +130,7 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
.setVisible(installed == null && uninstalledReleases.size() > 1); .setVisible(installed == null && uninstalledReleases.size() > 1);
cell.update(table, _value, !installedBuiltIn.isEmpty()); cell.update(table, _value, !installedBuiltIn.isEmpty());
cell.setForeground(Color.BLACK);
cell.setBackground(new Color(218, 227, 227)); // #dae3e3 cell.setBackground(new Color(218, 227, 227)); // #dae3e3
return cell; return cell;
} }

View File

@ -306,4 +306,10 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
inactiveButtonsPanel.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);
}
} }

View File

@ -46,6 +46,7 @@ public class ContributedPlatformTableCellRenderer implements TableCellRenderer {
cell.setButtonsVisible(false); cell.setButtonsVisible(false);
cell.update(table, value, false); cell.update(table, value, false);
cell.setForeground(Color.BLACK);
if (row % 2 == 0) { if (row % 2 == 0) {
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
} else { } else {