deprecate duplicated method in the UIUtil class

This commit is contained in:
Sergey Malenkov
2016-04-20 16:28:44 +03:00
parent 0b1054a252
commit e396e8f9af
4 changed files with 20 additions and 19 deletions
@@ -152,7 +152,7 @@ final class MacScrollBarUI extends DefaultScrollBarUI {
if (event != null && MouseEvent.MOUSE_MOVED == event.getID()) {
Object source = event.getSource();
if (source instanceof Component) {
JScrollPane pane = UIUtil.findParentByClass((Component)source, JScrollPane.class);
JScrollPane pane = UIUtil.getParentOfType(JScrollPane.class, (Component)source);
if (pane != null) {
pauseThumbAnimation(pane.getHorizontalScrollBar());
pauseThumbAnimation(pane.getVerticalScrollBar());
@@ -399,7 +399,7 @@ public final class ActionMenu extends JMenu {
if (event instanceof ComponentEvent) {
ComponentEvent componentEvent = (ComponentEvent)event;
Component component = componentEvent.getComponent();
JPopupMenu popup = UIUtil.findParentByClass(component, JPopupMenu.class);
JPopupMenu popup = UIUtil.getParentOfType(JPopupMenu.class, component);
if (popup != null && popup.getInvoker() == myComponent) {
Rectangle bounds = popup.getBounds();
if (bounds.isEmpty()) return;
@@ -2053,14 +2053,9 @@ public class UIUtil {
return null;
}
@Deprecated
public static <T extends Component> T findParentByClass(@NotNull Component c, Class<T> cls) {
for (Component component = c; component != null; component = component.getParent()) {
if (cls.isAssignableFrom(component.getClass())) {
@SuppressWarnings({"unchecked"}) final T t = (T)component;
return t;
}
}
return null;
return getParentOfType(cls, c);
}
@Language("HTML")
@@ -2762,18 +2757,24 @@ public class UIUtil {
return child == parent;
}
/**
* Searches above in the component hierarchy starting from the specified component.
* Note that the initial component is also checked.
*
* @param type expected class
* @param component initial component
* @return a component of the specified type, or {@code null} if the search is failed
* @see SwingUtilities#getAncestorOfClass
*/
@Nullable
public static <T> T getParentOfType(Class<? extends T> cls, Component c) {
Component eachParent = c;
while (eachParent != null) {
if (cls.isAssignableFrom(eachParent.getClass())) {
@SuppressWarnings({"unchecked"}) final T t = (T)eachParent;
return t;
public static <T> T getParentOfType(@NotNull Class<? extends T> type, Component component) {
while (component != null) {
if (type.isInstance(component)) {
//noinspection unchecked
return (T)component;
}
eachParent = eachParent.getParent();
component = component.getParent();
}
return null;
}
@@ -352,7 +352,7 @@ public class BreakpointsDialog extends DialogWrapper {
JPanel decoratedTree = decorator.createPanel();
decoratedTree.setBorder(IdeBorderFactory.createEmptyBorder());
JScrollPane pane = UIUtil.findParentByClass(tree, JScrollPane.class);
JScrollPane pane = UIUtil.getParentOfType(JScrollPane.class, tree);
if (pane != null) pane.setBorder(IdeBorderFactory.createBorder());
myTreeController.setTreeView(tree);