Skip to content

Ghidra is a software reverse engineering (SRE) framework

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

dragonmacher0de8cd3aca0f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/BackgroundIcon.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/BackgroundIcon.java
index 873c34f4f1..623bf08c0f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/BackgroundIcon.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/BackgroundIcon.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (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_LIGHT = new Color(0x9f, 0x9f, 0xff);
- private static final int WIDTH = 18;
- private static final int HEIGHT = 17;
-
private int width;
private int height;
private boolean isVersioned;
- BackgroundIcon(boolean isVersioned) {
- this(WIDTH, HEIGHT, isVersioned);
- }
-
BackgroundIcon(int width, int height, boolean isVersioned) {
this.width = width;
this.height = height;
this.isVersioned = isVersioned;
}
+ @Override
public int getIconHeight() {
return height;
}
+ @Override
public int getIconWidth() {
return width;
}
+ @Override
public void paintIcon(Component c, Graphics g, int x, int y) {
if (isVersioned) {
g.setColor(VERSION_ICON_COLOR_LIGHT);
@@ -63,7 +58,6 @@ class BackgroundIcon implements Icon {
else {
g.setColor(c.getBackground());
g.fillRect(x, y, width, height);
-
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
index 6d0e95f523..7e40136a78 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
@@ -242,7 +242,7 @@ public class DataTypeArchiveGTree extends GTree {
//==================================================================================================
// Inner Classes
-//==================================================================================================
+//==================================================================================================
private class DataTypeTransformer extends DefaultGTreeDataTransformer {
@@ -270,7 +270,7 @@ public class DataTypeArchiveGTree extends GTree {
private void addFunctionDefinitionStrings(FunctionDefinition function,
List<String> results) {
- // the prototype string will include name, return type and parameter
+ // the prototype string will include name, return type and parameter
// data types and names...so use that, unless it turns out to be bad
results.add(function.getPrototypeString());
@@ -331,11 +331,15 @@ public class DataTypeArchiveGTree extends GTree {
JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, isSelected,
expanded, leaf, row, focus);
- // Background icon uses the label's color so set it to match the
- // tree's background. Otherwise the icon's in the tree might have a
- // different background and look odd.
- MultiIcon multiIcon = new MultiIcon(new BackgroundIcon(ICON_WIDTH, ICON_HEIGHT, false));
+ if (!label.isOpaque()) {
+ // work around an issue on some platforms where the label is painting a color that
+ // does not match the tree
+ label.setBackground(
+ isSelected ? getBackgroundSelectionColor() : tree.getBackground());
+ }
+ MultiIcon multiIcon = new MultiIcon(
+ new BackgroundIcon(ICON_WIDTH, ICON_HEIGHT, false));
Icon icon = getIcon();
multiIcon.addIcon(new CenterVerticalIcon(icon, ICON_HEIGHT));
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/support/GTreeRenderer.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/support/GTreeRenderer.java
index 7b89d20ef5..d373b28dbc 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/support/GTreeRenderer.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/support/GTreeRenderer.java
@@ -52,7 +52,6 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
// paint the previously dragged-over node as the drop target.
paintDropTarget = (value == dropTarget);
- setOpaque(true);
setBackground(selected1 ? getBackgroundSelectionColor() : getBackgroundNonSelectionColor());
if (!(value instanceof GTreeNode)) {
@@ -95,8 +94,8 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
/**
* Converts the given color from a {@link ColorUIResource} to a {@link Color}. This is used
- * to deal with the issue that some Look and Feels will not correctly paint with this
- * renderer when using UI resource objects. This behavior can be changed by overriding this
+ * to deal with the issue that some Look and Feels will not correctly paint with this
+ * renderer when using UI resource objects. This behavior can be changed by overriding this
* method.
*
* @param c the source color
@@ -138,7 +137,7 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
if (font != cachedDefaultFont && font != cachedBoldFont) {
cachedDefaultFont = font;
- // Bug Alert!:
+ // Bug Alert!:
// We must create a new font here and not use deriveFont(). Using derive font has
// bugs when calculating the string width for a bold derived font.
cachedBoldFont = new Font(font.getFamily(), Font.BOLD, font.getSize());
diff --git a/Ghidra/Framework/Generic/src/main/java/resources/MultiIcon.java b/Ghidra/Framework/Generic/src/main/java/resources/MultiIcon.java
index 706aaf7e0e..10ff12602d 100644
--- a/Ghidra/Framework/Generic/src/main/java/resources/MultiIcon.java
+++ b/Ghidra/Framework/Generic/src/main/java/resources/MultiIcon.java
@@ -138,8 +138,8 @@ public class MultiIcon implements Icon {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
init();
- for (int i = 0; i < iconList.size(); i++) {
- Icon icon = iconList.get(i);
+
+ for (Icon icon : iconList) {
icon.paintIcon(c, g, x, y);
}