Merge remote-tracking branch

'origin/GP-2047-dragonmacher-tree-renderer-bg-fix' into patch
(Closes #4260)
This commit is contained in:
Ryan Kurtz 2022-05-23 11:15:21 -04:00
commit 9880801814
4 changed files with 18 additions and 21 deletions

View File

@ -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);
}
}
}

View File

@ -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));

View File

@ -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());

View File

@ -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);
}