/** * Update bounds of the tooltip component. It gets called when the tooltip * component is about to be shown or when it was updated by * {@link #setToolTip(javax.swing.JComponent)}. */ protected void updateToolTipBounds() { Dimension prefSize = toolTip.getPreferredSize(); Rectangle extBounds = extEditorUI.getExtentBounds(); int x = Math.min(lastMouseEvent.getX() - prefSize.width / 2, extBounds.x + extBounds.width - prefSize.width); x = Math.max(x, extBounds.x); int lineHeight = extEditorUI.getLineHeight(); int y = lastMouseEvent.getY() - 2 * lineHeight; if (y - extBounds.y < lineHeight) { y = lastMouseEvent.getY() + lineHeight; } toolTip.setBounds(x - extBounds.x, y - extBounds.y, prefSize.width, prefSize.height); }
/** * Helper method to get the identifier under the mouse cursor. * * @return string containing identifier under mouse cursor. */ public String getIdentifierUnderCursor() { String word = null; try { JTextComponent component = extEditorUI.getComponent(); BaseTextUI ui = (BaseTextUI) component.getUI(); int pos = ui.viewToModel(component, lastMouseEvent.getPoint()); if (pos >= 0) { BaseDocument doc = (BaseDocument) component.getDocument(); int eolPos = Utilities.getRowEnd(doc, pos); Rectangle eolRect = ui.modelToView(component, eolPos); int lineHeight = extEditorUI.getLineHeight(); if (lastMouseEvent.getX() <= eolRect.x && lastMouseEvent.getY() <= eolRect.y + lineHeight) { word = Utilities.getIdentifier(doc, pos); } } } catch (BadLocationException e) { // word will be null } return word; }
/** Helper method to get the identifier * under the mouse cursor. * @return string containing identifier under * mouse cursor. */ public String getIdentifierUnderCursor() { String word = null; if (!isGlyphGutterMouseEvent(lastMouseEvent)) { try { JTextComponent component = extEditorUI.getComponent(); BaseTextUI ui = (BaseTextUI)component.getUI(); Point lmePoint = getLastMouseEventPoint(); int pos = ui.viewToModel(component, lmePoint); if (pos >= 0) { BaseDocument doc = (BaseDocument)component.getDocument(); int eolPos = Utilities.getRowEnd(doc, pos); Rectangle eolRect = ui.modelToView(component, eolPos); int lineHeight = extEditorUI.getLineHeight(); if (lmePoint.x <= eolRect.x && lmePoint.y <= eolRect.y + lineHeight) { word = Utilities.getIdentifier(doc, pos); } } } catch (BadLocationException e) { // word will be null } } return word; }