GP-2047 - fix for tree rendering bug on some Linux systems

This commit is contained in:
dragonmacher 2022-05-18 12:28:47 -04:00
parent e3a751ca46
commit 0de8cd3aca
4 changed files with 18 additions and 21 deletions

View File

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,31 +24,27 @@ class BackgroundIcon implements Icon {
private static Color VERSION_ICON_COLOR_DARK = new Color(0x82, 0x82, 0xff); private static Color VERSION_ICON_COLOR_DARK = new Color(0x82, 0x82, 0xff);
private static Color VERSION_ICON_COLOR_LIGHT = new Color(0x9f, 0x9f, 0xff); private static Color VERSION_ICON_COLOR_LIGHT = new Color(0x9f, 0x9f, 0xff);
private static final int WIDTH = 18;
private static final int HEIGHT = 17;
private int width; private int width;
private int height; private int height;
private boolean isVersioned; private boolean isVersioned;
BackgroundIcon(boolean isVersioned) {
this(WIDTH, HEIGHT, isVersioned);
}
BackgroundIcon(int width, int height, boolean isVersioned) { BackgroundIcon(int width, int height, boolean isVersioned) {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.isVersioned = isVersioned; this.isVersioned = isVersioned;
} }
@Override
public int getIconHeight() { public int getIconHeight() {
return height; return height;
} }
@Override
public int getIconWidth() { public int getIconWidth() {
return width; return width;
} }
@Override
public void paintIcon(Component c, Graphics g, int x, int y) { public void paintIcon(Component c, Graphics g, int x, int y) {
if (isVersioned) { if (isVersioned) {
g.setColor(VERSION_ICON_COLOR_LIGHT); g.setColor(VERSION_ICON_COLOR_LIGHT);
@ -63,7 +58,6 @@ class BackgroundIcon implements Icon {
else { else {
g.setColor(c.getBackground()); g.setColor(c.getBackground());
g.fillRect(x, y, width, height); g.fillRect(x, y, width, height);
} }
} }
} }

View File

@ -331,11 +331,15 @@ public class DataTypeArchiveGTree extends GTree {
JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, isSelected, JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, isSelected,
expanded, leaf, row, focus); expanded, leaf, row, focus);
// Background icon uses the label's color so set it to match the if (!label.isOpaque()) {
// tree's background. Otherwise the icon's in the tree might have a // work around an issue on some platforms where the label is painting a color that
// different background and look odd. // does not match the tree
MultiIcon multiIcon = new MultiIcon(new BackgroundIcon(ICON_WIDTH, ICON_HEIGHT, false)); label.setBackground(
isSelected ? getBackgroundSelectionColor() : tree.getBackground());
}
MultiIcon multiIcon = new MultiIcon(
new BackgroundIcon(ICON_WIDTH, ICON_HEIGHT, false));
Icon icon = getIcon(); Icon icon = getIcon();
multiIcon.addIcon(new CenterVerticalIcon(icon, ICON_HEIGHT)); multiIcon.addIcon(new CenterVerticalIcon(icon, ICON_HEIGHT));

View File

@ -52,7 +52,6 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
// paint the previously dragged-over node as the drop target. // paint the previously dragged-over node as the drop target.
paintDropTarget = (value == dropTarget); paintDropTarget = (value == dropTarget);
setOpaque(true);
setBackground(selected1 ? getBackgroundSelectionColor() : getBackgroundNonSelectionColor()); setBackground(selected1 ? getBackgroundSelectionColor() : getBackgroundNonSelectionColor());
if (!(value instanceof GTreeNode)) { if (!(value instanceof GTreeNode)) {

View File

@ -138,8 +138,8 @@ public class MultiIcon implements Icon {
@Override @Override
public void paintIcon(Component c, Graphics g, int x, int y) { public void paintIcon(Component c, Graphics g, int x, int y) {
init(); init();
for (int i = 0; i < iconList.size(); i++) {
Icon icon = iconList.get(i); for (Icon icon : iconList) {
icon.paintIcon(c, g, x, y); icon.paintIcon(c, g, x, y);
} }