From 778f681c2fa28a8be3fb2bab9b22299db65976fb Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 1 Oct 2019 12:48:34 +0200 Subject: [PATCH] Remove unneeded color-setting code in the boards and library manager Previously, for the boards manager: - InstallerJDialog would set the "selection background" color on the table, using the "status.notice.bgcolor" the color (default blueish green). This color is not used directly, but made available for cell renderers to use. https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/ui/InstallerJDialog.java#L183 - For each cell, either a ContributedPlatformTableCellEditor or ContributedPlatformTableCellRenderer is used, depending on whether the cell is being edited (i.e. when selected). - Both of these create a ContributedPlatformTableCellJPanel, and call its `update` method, which creates the components for the cell. - The `update` method als sets the background color of the description to white, which does not actually have any effect because the description is not opaque. https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java#L271 https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java#L309 https://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#setBackground(java.awt.Color) - The `update` method also sets its colors of itself (JPanel) to the FG and BG color, or the selected FG and BG color of the table depending on the selected status of the cell. These seem to default to black on white for non-selected and white on blue-ish for selected cells. However, InstallJDialog has replaced the selected BG with a blueish green, as shown above. Of these, only the BG colors actually seem to take effect. The fg color of the description component is actually used (default black). https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java#L282-L288 - After calling `update`, ContributedPlatformTableCellEditor overrides the JPanel background color with a fixed grey color. Similarly, ContributedPlatformTableCellRenderer sets an alternating white and (slightly lighter) grey background color. Together, this means that the background color set by ContributedPlatformTableCellJPanel is never actually used. https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java#L132-L133 https://github.com/arduino/Arduino/blob/a1448876a1115c9d3ee9e88f29a15bb081a27816/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java#L47-L53 For the library manager, pretty much the same happens. Effectively, the only colors that were actually used were the background colors set by ContributedPlatformTableCellEditor and ContributedPlatformTableCellRenderer. This is problematic because: - There is a lot of other confusing and unused code - The foreground color is never set. This is fine when it is black or another dark color, but when the system is configured with a dark theme, the default foreground color will be white, which is problematic on a white background. This commit remove the unneeded code, setting the foreground color is left for later. It also removes the (now unused) `isSelected` from `ContributedPlatformTableCellJPanel::update`. For the library manager, the corresponding argument is still used to decide the "author" color. --- .../ui/ContributedLibraryTableCellJPanel.java | 9 --------- .../ui/ContributedPlatformTableCellEditor.java | 2 +- .../ui/ContributedPlatformTableCellJPanel.java | 12 +----------- .../ui/ContributedPlatformTableCellRenderer.java | 2 +- .../arduino/contributions/ui/InstallerJDialog.java | 1 - 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java index 665b83a95..a9a8a39f4 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java @@ -199,7 +199,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel { description.setText(desc); // copy description to accessibility context for screen readers to use description.getAccessibleContext().setAccessibleDescription(desc); - description.setBackground(Color.WHITE); // for modelToView to work, the text area has to be sized. It doesn't // matter if it's visible or not. @@ -209,14 +208,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel { InstallerTableCell .setJTextPaneDimensionToFitContainedText(description, parentTable.getBounds().width); - - if (isSelected) { - setBackground(parentTable.getSelectionBackground()); - setForeground(parentTable.getSelectionForeground()); - } else { - setBackground(parentTable.getBackground()); - setForeground(parentTable.getForeground()); - } } // same function as in ContributedPlatformTableCellJPanel - is there a utils file this can move to? diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java index 26bcb1c9d..acfb58bb3 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java @@ -129,7 +129,7 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell { cell.versionToInstallChooser .setVisible(installed == null && uninstalledReleases.size() > 1); - cell.update(table, _value, true, !installedBuiltIn.isEmpty()); + cell.update(table, _value, !installedBuiltIn.isEmpty()); 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 6051ec98c..9575d12e6 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java @@ -175,8 +175,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel { return retString; } - void update(JTable parentTable, Object value, boolean isSelected, - boolean hasBuiltInRelease) { + void update(JTable parentTable, Object value, boolean hasBuiltInRelease) { ContributedPlatformReleases releases = (ContributedPlatformReleases) value; JTextPane description = makeNewDescription(); @@ -262,7 +261,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel { description.setText(desc); // copy description to accessibility context for screen readers to use description.getAccessibleContext().setAccessibleDescription(desc); - description.setBackground(Color.WHITE); // for modelToView to work, the text area has to be sized. It doesn't // matter if it's visible or not. @@ -272,14 +270,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel { int width = parentTable.getBounds().width; InstallerTableCell.setJTextPaneDimensionToFitContainedText(description, width); - - if (isSelected) { - setBackground(parentTable.getSelectionBackground()); - setForeground(parentTable.getSelectionForeground()); - } else { - setBackground(parentTable.getBackground()); - setForeground(parentTable.getForeground()); - } } private JTextPane makeNewDescription() { diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java index cc4b1d0c1..19d484dc2 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java @@ -44,7 +44,7 @@ public class ContributedPlatformTableCellRenderer implements TableCellRenderer { int column) { ContributedPlatformTableCellJPanel cell = new ContributedPlatformTableCellJPanel(); cell.setButtonsVisible(false); - cell.update(table, value, isSelected, false); + cell.update(table, value, false); if (row % 2 == 0) { cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 diff --git a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java index dd2998bc4..2888cd688 100644 --- a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java +++ b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java @@ -180,7 +180,6 @@ public abstract class InstallerJDialog extends JDialog { contribTable.setDragEnabled(false); contribTable.setIntercellSpacing(new Dimension(0, 1)); contribTable.setShowVerticalLines(false); - contribTable.setSelectionBackground(Theme.getColor("status.notice.bgcolor")); contribTable.addKeyListener(new AbstractKeyListener() { @Override