From 094e633d0a05cafe08d48d111636c8b9dae7dc22 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 10 Feb 2014 16:10:58 +0100 Subject: [PATCH] kill duplicates --- .../intellij/openapi/wm/impl/IdeMenuBar.java | 20 ++----------------- .../src/com/intellij/ui/BalloonImpl.java | 10 +--------- .../util/src/com/intellij/util/ui/UIUtil.java | 18 +++++++++++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeMenuBar.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeMenuBar.java index f928ec1b9997..8d3d0c15b0f8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeMenuBar.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeMenuBar.java @@ -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); diff --git a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java index 5c340a508e28..6ef75b205fcb 100644 --- a/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/BalloonImpl.java @@ -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; diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index b939c924968d..e9eebf39a215 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -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 getParentOfType(Class cls, Component c) { Component eachParent = c;