mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ui: fix HighlightComponent leakage from UI Inspector
myHighlightComponent might have not been disposed if `setHighlightingEnabled(true)` called twice in a row
This commit is contained in:
committed by
Aleksey Pivovarov
parent
2ba90c25fe
commit
8c37f7c225
@@ -231,28 +231,37 @@ public class UiInspectorAction extends ToggleAction implements DumbAware {
|
||||
}
|
||||
|
||||
private void setHighlightingEnabled(boolean enable) {
|
||||
Component target = enable ? myComponent : myHighlightComponent;
|
||||
JRootPane rootPane = target == null ? null : SwingUtilities.getRootPane(target);
|
||||
JComponent glassPane = rootPane == null ? null : (JComponent)rootPane.getGlassPane();
|
||||
if (glassPane == null) {
|
||||
myHighlightComponent = null;
|
||||
return;
|
||||
}
|
||||
if (enable) {
|
||||
myHighlightComponent = new HighlightComponent(new JBColor(JBColor.GREEN, JBColor.RED));
|
||||
if (myHighlightComponent != null) {
|
||||
JComponent glassPane = getGlassPane(myHighlightComponent);
|
||||
if (glassPane != null) {
|
||||
glassPane.remove(myHighlightComponent);
|
||||
|
||||
Point pt = SwingUtilities.convertPoint(myComponent, new Point(0, 0), rootPane);
|
||||
myHighlightComponent.setBounds(pt.x, pt.y, myComponent.getWidth(), myComponent.getHeight());
|
||||
glassPane.add(myHighlightComponent);
|
||||
}
|
||||
else {
|
||||
glassPane.remove(myHighlightComponent);
|
||||
glassPane.revalidate();
|
||||
glassPane.repaint();
|
||||
}
|
||||
myHighlightComponent = null;
|
||||
}
|
||||
glassPane.revalidate();
|
||||
glassPane.repaint();
|
||||
|
||||
if (enable && myComponent != null) {
|
||||
JComponent glassPane = getGlassPane(myComponent);
|
||||
if (glassPane != null) {
|
||||
myHighlightComponent = new HighlightComponent(new JBColor(JBColor.GREEN, JBColor.RED));
|
||||
|
||||
Point pt = SwingUtilities.convertPoint(myComponent, new Point(0, 0), glassPane);
|
||||
myHighlightComponent.setBounds(pt.x, pt.y, myComponent.getWidth(), myComponent.getHeight());
|
||||
glassPane.add(myHighlightComponent);
|
||||
|
||||
glassPane.revalidate();
|
||||
glassPane.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JComponent getGlassPane(@NotNull Component component) {
|
||||
JRootPane rootPane = SwingUtilities.getRootPane(component);
|
||||
return rootPane == null ? null : (JComponent)rootPane.getGlassPane();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComponentTreeCellRenderer extends ColoredTreeCellRenderer {
|
||||
|
||||
Reference in New Issue
Block a user