import com.intellij.util.ui.UIUtil; //导入方法依赖的package包/类
AsyncResult getHintContainerShowPoint() {
final AsyncResult result = new AsyncResult();
if (myLocationCache == null) {
if (myHintContainer != null) {
final Point p = AbstractPopup.getCenterOf(myHintContainer, this);
p.y -= myHintContainer.getVisibleRect().height / 4;
myLocationCache = RelativePoint.fromScreen(p);
} else {
if (myContextComponent != null) {
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
} else {
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer() {
@Override
public void consume(DataContext dataContext) {
myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
}
});
}
}
}
final Component c = myLocationCache.getComponent();
if (!(c instanceof JComponent && c.isShowing())) {
//Yes. It happens sometimes.
// 1. Empty frame. call nav bar, select some package and open it in Project View
// 2. Call nav bar, then Esc
// 3. Hide all tool windows (Ctrl+Shift+F12), so we've got empty frame again
// 4. Call nav bar. NPE. ta da
final JComponent ideFrame = WindowManager.getInstance().getIdeFrame(getProject()).getComponent();
final JRootPane rootPane = UIUtil.getRootPane(ideFrame);
myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(rootPane);
}
result.setDone(myLocationCache);
return result;
}