Skip to content

Cleanup board/library manager color setting and somewhat support dark themes #9272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Component getTableCellEditorComponent(JTable table, Object value,
editorCell.versionToInstallChooser
.setVisible(!mayInstalled.isPresent() && notInstalled.size() > 1);

editorCell.setForeground(Color.BLACK);
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
return editorCell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel;
final JLabel statusLabel;
final JTextPane description;
private final String moreInfoLbl = tr("More info");

public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
Expand Down Expand Up @@ -77,7 +78,8 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
versionToInstallChooser
.setMinimumSize(new Dimension((int)versionToInstallChooser.getPreferredSize().getWidth() + 50, (int)versionToInstallChooser.getPreferredSize().getHeight()));

makeNewDescription();
description = makeNewDescription();
add(description);

buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
Expand Down Expand Up @@ -121,7 +123,6 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
add(Box.createVerticalStrut(15));

ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
JTextPane description = makeNewDescription();

// FIXME: happens on macosx, don't know why
if (releases == null)
Expand Down Expand Up @@ -205,7 +206,6 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
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.
Expand All @@ -215,14 +215,6 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
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?
Expand All @@ -246,9 +238,6 @@ private String setButtonOrLink(JButton button, String desc, String label, String

// TODO Make this a method of Theme
private JTextPane makeNewDescription() {
if (getComponentCount() > 0) {
remove(0);
}
JTextPane description = new JTextPane();
description.setInheritsPopupMenu(true);
Insets margin = description.getMargin();
Expand All @@ -274,7 +263,6 @@ private JTextPane makeNewDescription() {
}
});
// description.addKeyListener(new DelegatingKeyListener(parentTable));
add(description, 0);
return description;
}

Expand All @@ -283,4 +271,11 @@ public void setButtonsVisible(boolean enabled) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
value, isSelected);
cell.setButtonsVisible(false);

cell.setForeground(Color.BLACK);
if (row % 2 == 0) {
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public Component getTableCellEditorComponent(JTable table, Object _value,
cell.versionToInstallChooser
.setVisible(installed == null && uninstalledReleases.size() > 1);

cell.update(table, _value, true, !installedBuiltIn.isEmpty());
cell.update(table, _value, !installedBuiltIn.isEmpty());
cell.setForeground(Color.BLACK);
cell.setBackground(new Color(218, 227, 227)); // #dae3e3
return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel;
final JLabel statusLabel;
final JTextPane description;
private final String moreInfoLbl = tr("More Info");
private final String onlineHelpLbl = tr("Online Help");

Expand Down Expand Up @@ -117,7 +118,8 @@ public ContributedPlatformTableCellJPanel() {
versionToInstallChooser
.setMaximumSize(versionToInstallChooser.getPreferredSize());

makeNewDescription();
description = makeNewDescription();
add(description);

buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
Expand Down Expand Up @@ -184,12 +186,9 @@ private String setButtonOrLink(JButton button, String desc, String label, String
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();

// FIXME: happens on macosx, don't know why
if (releases == null) {
return;
Expand Down Expand Up @@ -268,7 +267,6 @@ void update(JTable parentTable, Object value, boolean isSelected,
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.
Expand All @@ -278,20 +276,9 @@ void update(JTable parentTable, Object value, boolean isSelected,
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() {
if (getComponentCount() > 0) {
remove(0);
}
JTextPane description = new JTextPane();
description.setInheritsPopupMenu(true);
Insets margin = description.getMargin();
Expand All @@ -315,7 +302,6 @@ private JTextPane makeNewDescription() {
Base.openURL(e.getDescription());
}
});
add(description, 0);
return description;
}

Expand All @@ -326,4 +312,10 @@ public void setButtonsVisible(boolean 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public Component getTableCellRendererComponent(JTable table, Object value,
int column) {
ContributedPlatformTableCellJPanel cell = new ContributedPlatformTableCellJPanel();
cell.setButtonsVisible(false);
cell.update(table, value, isSelected, false);
cell.update(table, value, false);

cell.setForeground(Color.BLACK);
if (row % 2 == 0) {
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
} else {
Expand Down
1 change: 0 additions & 1 deletion app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public void windowOpened(WindowEvent e) {
contribTable.setDragEnabled(false);
contribTable.setIntercellSpacing(new Dimension(0, 1));
contribTable.setShowVerticalLines(false);
contribTable.setSelectionBackground(Theme.getColor("status.notice.bgcolor"));
contribTable.addKeyListener(new AbstractKeyListener() {

@Override
Expand Down