This commit is contained in:
Gregory.Shrago
2016-05-24 21:47:14 +03:00
parent c0b21f952d
commit 2be4d68b6f
@@ -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<Component> getParents(@Nullable Component c) {
return JBIterable.generate(c, new Function.Mono<Component>() {
@Override
public Component fun(Component c) {
return c.getParent();
}
});
return uiParents(c, true);
}
@NotNull
public static JBIterable<Component> 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<Component> uiTraverser(@Nullable Component component) {
return new JBTreeTraverser<Component>(COMPONENT_CHILDREN).withRoot(component);
return uiTraverser().withRoot(component);
}
public static final Key<Iterable<? extends Component>> NOT_IN_HIERARCHY_COMPONENTS = Key.create("NOT_IN_HIERARCHY_COMPONENTS");
@@ -2847,6 +2830,14 @@ public class UIUtil {
}
};
private static final Function.Mono<Component> COMPONENT_PARENT = new Function.Mono<Component>() {
@Override
public Component fun(Component c) {
return c.getParent();
}
};
public static void scrollListToVisibleIfNeeded(@NotNull final JList list) {
SwingUtilities.invokeLater(new Runnable() {
@Override