From 2be4d68b6f2eb2913cb8aa13c75b109889675fe0 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Tue, 24 May 2016 20:33:25 +0300 Subject: [PATCH] cleanup --- .../util/src/com/intellij/util/ui/UIUtil.java | 73 ++++++++----------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 344059d8d8f0..bf36b37b3fec 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -2308,45 +2308,28 @@ public class UIUtil { } public static void removeScrollBorder(final Component c) { - new AwtVisitor(c) { - @Override - public boolean visit(final Component component) { - if (component instanceof JScrollPane) { - if (!hasNonPrimitiveParents(c, component)) { - final JScrollPane scrollPane = (JScrollPane)component; - Integer keepBorderSides = getClientProperty(scrollPane, KEEP_BORDER_SIDES); - if (keepBorderSides != null) { - if (scrollPane.getBorder() instanceof LineBorder) { - Color color = ((LineBorder)scrollPane.getBorder()).getLineColor(); - scrollPane.setBorder(new SideBorder(color, keepBorderSides.intValue())); - } - else { - scrollPane.setBorder(new SideBorder(getBoundsColor(), keepBorderSides.intValue())); - } - } - else { - scrollPane.setBorder(new SideBorder(getBoundsColor(), SideBorder.NONE)); - } - } + for (JScrollPane scrollPane : uiTraverser(c).filter(JScrollPane.class)) { + if (!getParents(scrollPane) + .takeWhile(Conditions.notEqualTo(c)) + .filter(Conditions.not(Conditions.instanceOf(JPanel.class, JLayeredPane.class))) + .isEmpty()) continue; + + Integer keepBorderSides = getClientProperty(scrollPane, KEEP_BORDER_SIDES); + if (keepBorderSides != null) { + if (scrollPane.getBorder() instanceof LineBorder) { + Color color = ((LineBorder)scrollPane.getBorder()).getLineColor(); + scrollPane.setBorder(new SideBorder(color, keepBorderSides.intValue())); + } + else { + scrollPane.setBorder(new SideBorder(getBoundsColor(), keepBorderSides.intValue())); } - return false; } - }; - } - - public static boolean hasNonPrimitiveParents(Component stopParent, Component c) { - Component eachParent = c.getParent(); - while (true) { - if (eachParent == null || eachParent == stopParent) return false; - if (!isPrimitive(eachParent)) return true; - eachParent = eachParent.getParent(); + else { + scrollPane.setBorder(new SideBorder(getBoundsColor(), SideBorder.NONE)); + } } } - public static boolean isPrimitive(Component c) { - return c instanceof JPanel || c instanceof JLayeredPane; - } - public static Point getCenterPoint(Dimension container, Dimension child) { return getCenterPoint(new Rectangle(container), child); } @@ -2793,12 +2776,12 @@ public class UIUtil { @NotNull public static JBIterable getParents(@Nullable Component c) { - return JBIterable.generate(c, new Function.Mono() { - @Override - public Component fun(Component c) { - return c.getParent(); - } - }); + return uiParents(c, true); + } + + @NotNull + public static JBIterable uiParents(@Nullable Component c, boolean strict) { + return strict ? JBIterable.generate(c, COMPONENT_PARENT).skip(1) : JBIterable.generate(c, COMPONENT_PARENT); } @NotNull @@ -2808,7 +2791,7 @@ public class UIUtil { @NotNull public static JBTreeTraverser uiTraverser(@Nullable Component component) { - return new JBTreeTraverser(COMPONENT_CHILDREN).withRoot(component); + return uiTraverser().withRoot(component); } public static final Key> NOT_IN_HIERARCHY_COMPONENTS = Key.create("NOT_IN_HIERARCHY_COMPONENTS"); @@ -2847,6 +2830,14 @@ public class UIUtil { } }; + private static final Function.Mono COMPONENT_PARENT = new Function.Mono() { + @Override + public Component fun(Component c) { + return c.getParent(); + } + }; + + public static void scrollListToVisibleIfNeeded(@NotNull final JList list) { SwingUtilities.invokeLater(new Runnable() { @Override