List of usage examples for com.intellij.openapi.ui.popup JBPopup getSize
Dimension getSize();
From source file:com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager.java
License:Apache License
private void processMouseMove(@NotNull EditorMouseEvent e) { if (!myApplicationActive || e.getArea() != EditorMouseEventArea.EDITING_AREA) { // Skip if the mouse is not at the editing area. closeQuickDocIfPossible();// w w w . j a v a 2s. co m return; } if (e.getMouseEvent().getModifiers() != 0) { // Don't show the control when any modifier is active (e.g. Ctrl or Alt is hold). There is a common situation that a user // wants to navigate via Ctrl+click or perform quick evaluate by Alt+click. return; } Editor editor = e.getEditor(); if (editor.isOneLineMode()) { // Don't want auto quick doc to mess at, say, editor used for debugger condition. return; } Project project = editor.getProject(); if (project == null) { return; } DocumentationManager documentationManager = DocumentationManager.getInstance(project); JBPopup hint = documentationManager.getDocInfoHint(); if (hint != null) { // Skip the event if the control is shown because of explicit 'show quick doc' action call. DocumentationManager manager = getDocManager(); if (manager == null || !manager.isCloseOnSneeze()) { return; } // Skip the event if the mouse is under the opened quick doc control. Point hintLocation = hint.getLocationOnScreen(); Dimension hintSize = hint.getSize(); int mouseX = e.getMouseEvent().getXOnScreen(); int mouseY = e.getMouseEvent().getYOnScreen(); if (mouseX >= hintLocation.x && mouseX <= hintLocation.x + hintSize.width && mouseY >= hintLocation.y && mouseY <= hintLocation.y + hintSize.height) { return; } } PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (psiFile == null) { closeQuickDocIfPossible(); return; } VisualPosition visualPosition = editor.xyToVisualPosition(e.getMouseEvent().getPoint()); if (editor.getSoftWrapModel().isInsideOrBeforeSoftWrap(visualPosition)) { closeQuickDocIfPossible(); return; } int mouseOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(visualPosition)); PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset); if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace || elementUnderMouse instanceof PsiPlainText) { closeQuickDocIfPossible(); return; } PsiElement targetElementUnderMouse = documentationManager.findTargetElement(editor, mouseOffset, psiFile, elementUnderMouse); if (targetElementUnderMouse == null) { // No PSI element is located under the current mouse position - close quick doc if any. closeQuickDocIfPossible(); return; } PsiElement activeElement = myActiveElements.get(editor); if (targetElementUnderMouse.equals(activeElement) && (!myAlarm.isEmpty() // Request to show documentation for the target component has been already queued. || hint != null)) // Documentation for the target component is being shown. { return; } allowUpdateFromContext(project, false); closeQuickDocIfPossible(); myActiveElements.put(editor, targetElementUnderMouse); myDelayedQuickDocInfo = new DelayedQuickDocInfo(documentationManager, editor, targetElementUnderMouse, elementUnderMouse); myAlarm.cancelAllRequests(); myAlarm.addRequest(myRequest, EditorSettingsExternalizable.getInstance().getQuickDocOnMouseOverElementDelayMillis()); }