Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3103 - Look and Feel - review fix

dragonmacher54781dc7f5cb
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 c4d1a0bee6..60f6fb7318 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
@@ -19,6 +19,7 @@ import java.awt.*;
import javax.swing.Icon;
import javax.swing.JTree;
+import javax.swing.plaf.ColorUIResource;
import javax.swing.tree.DefaultTreeCellRenderer;
import docking.widgets.GComponent;
@@ -26,7 +27,7 @@ import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent {
- private static final long serialVersionUID = 1L;
+
private static final Color VALID_DROP_TARGET_COLOR = new Color(200, 200, 255);
private static final int DEFAULT_MIN_ICON_WIDTH = 22;
@@ -80,6 +81,32 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
return this;
}
+ @Override
+ public void setBackgroundSelectionColor(Color newColor) {
+ super.setBackgroundSelectionColor(fromUiResource(newColor));
+ }
+
+ @Override
+ public void setBackgroundNonSelectionColor(Color newColor) {
+ super.setBackgroundNonSelectionColor(fromUiResource(newColor));
+ }
+
+ /**
+ * 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
+ * method.
+ *
+ * @param c the source color
+ * @return the new color
+ */
+ protected Color fromUiResource(Color c) {
+ if (c instanceof ColorUIResource) {
+ return new Color(c.getRGB());
+ }
+ return c;
+ }
+
protected void updateIconTextGap(Icon icon, int minWidth) {
int iconWidth = 0;
if (icon != null) {