kill duplicates

This commit is contained in:
Konstantin Bulenkov
2014-02-10 16:12:18 +01:00
parent 7128707d9e
commit 094e633d0a
3 changed files with 21 additions and 27 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -198,22 +198,6 @@ public class IdeMenuBar extends JMenuBar implements IdeEventQueue.EventDispatche
super.menuSelectionChanged(isIncluded);
}
private static boolean isDescendingFrom(@Nullable Component a, @NotNull Component b) {
while (a != null) {
if (a == b) {
return true;
}
if (a instanceof JPopupMenu) {
a = ((JPopupMenu)a).getInvoker();
}
else {
a = a.getParent();
}
}
return false;
}
private boolean isActivated() {
int index = getSelectionModel().getSelectedIndex();
if (index == -1) {
@@ -311,7 +295,7 @@ public class IdeMenuBar extends JMenuBar implements IdeEventQueue.EventDispatche
Component component = findActualComponent(mouseEvent);
if (myState != State.EXPANDED /*&& !myState.isInProgress()*/) {
boolean mouseInside = myActivated || isDescendingFrom(component, this);
boolean mouseInside = myActivated || UIUtil.isDescendingFrom(component, this);
if (e.getID() == MouseEvent.MOUSE_EXITED && e.getSource() == SwingUtilities.windowForComponent(this) && !myActivated) mouseInside = false;
if (mouseInside && myState == State.COLLAPSED) {
setState(State.EXPANDING);
@@ -197,20 +197,12 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
if (!cmp.isShowing()) return true;
if (cmp == myCloseRec) return true;
if (isDescendingFrom(cmp, myComp) || cmp == myComp) return true;
if (UIUtil.isDescendingFrom(cmp, myComp)) return true;
if (myComp == null || !myComp.isShowing()) return false;
Rectangle rectangleOnScreen = new Rectangle(myComp.getLocationOnScreen(), myComp.getSize());
return rectangleOnScreen.contains(target.getScreenPoint());
}
private static boolean isDescendingFrom(@Nullable Component child, @NotNull Component parent) {
while (child != null && child != parent) {
child = child instanceof JPopupMenu ? ((JPopupMenu)child).getInvoker()
: child.getParent();
}
return child == parent;
}
public boolean isMovingForward(RelativePoint target) {
try {
if (myComp == null || !myComp.isShowing()) return false;
@@ -2243,6 +2243,24 @@ public class UIUtil {
return SystemInfo.isMac && isUnderAquaLookAndFeel() ? 28 : height;
}
/**
* The main difference from javax.swing.SwingUtilities#isDescendingFrom(Component, Component) is that this method
* uses getInvoker() instead of getParent() when it meets JPopupMenu
* @param child child component
* @param parent parent component
* @return true if parent if a top parent of child, false otherwise
*
* @see javax.swing.SwingUtilities#isDescendingFrom(java.awt.Component, java.awt.Component)
*/
public static boolean isDescendingFrom(@Nullable Component child, @NotNull Component parent) {
while (child != null && child != parent) {
child = child instanceof JPopupMenu ? ((JPopupMenu)child).getInvoker()
: child.getParent();
}
return child == parent;
}
@Nullable
public static <T> T getParentOfType(Class<? extends T> cls, Component c) {
Component eachParent = c;