private void maybeShowFor(Component c, MouseEvent me) { if (!(c instanceof JComponent)) return; JComponent comp = (JComponent) c; Window wnd = SwingUtilities.getWindowAncestor(comp); if (wnd == null) return; if (!wnd.isActive()) { if (JBPopupFactory.getInstance().isChildPopupFocused(wnd)) return; } String tooltipText = comp.getToolTipText(me); if (tooltipText == null || tooltipText.trim().isEmpty()) return; boolean centerDefault = Boolean.TRUE.equals(comp.getClientProperty(UIUtil.CENTER_TOOLTIP_DEFAULT)); boolean centerStrict = Boolean.TRUE.equals(comp.getClientProperty(UIUtil.CENTER_TOOLTIP_STRICT)); int shift = centerStrict ? 0 : centerDefault ? 4 : 0; // Balloon may appear exactly above useful content, such behavior is rather annoying. if (c instanceof JTree) { TreePath path = ((JTree) c).getClosestPathForLocation(me.getX(), me.getY()); if (path != null) { Rectangle pathBounds = ((JTree) c).getPathBounds(path); if (pathBounds != null && pathBounds.y + 4 < me.getY()) { shift += me.getY() - pathBounds.y - 4; } } } queueShow(comp, me, centerStrict || centerDefault, shift, -shift, -shift); }
public void addNotify() { super.addNotify(); uninstallListeners(); myWindow = SwingUtilities.getWindowAncestor(this); if (myWindow != null) { if (myWindow instanceof Frame) { setState(((Frame) myWindow).getExtendedState()); } else { setState(0); } setActive(myWindow.isActive()); installListeners(); updateSystemIcon(); } }
public void paintComponent(Graphics g) { if (getFrame() != null) { setState(getFrame().getExtendedState()); } JRootPane rootPane = getRootPane(); Window window = getWindow(); boolean leftToRight = (window == null) ? rootPane.getComponentOrientation().isLeftToRight() : window.getComponentOrientation().isLeftToRight(); boolean isSelected = (window == null) ? true : window.isActive(); int width = getWidth(); int height = getHeight(); Color background; Color foreground; Color darkShadow; if (isSelected) { background = UIUtil.getPanelBackground(); // myActiveBackground; foreground = myActiveForeground; darkShadow = Gray._73; // myActiveShadow; } else { background = UIUtil.getPanelBackground(); // myInactiveBackground; foreground = myInactiveForeground; darkShadow = myInactiveShadow; } g.setColor(background); g.fillRect(0, 0, width, height); // g.setColor(darkShadow); // g.drawLine(0, height - 1, width, height - 1); // g.drawLine(0, 0, 0, 0); // g.drawLine(width - 1, 0, width - 1, 0); int xOffset = leftToRight ? 5 : width - 5; if (getWindowDecorationStyle() == JRootPane.FRAME) { xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5; } String theTitle = getTitle(); if (theTitle != null) { FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g); g.setColor(foreground); int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent(); Rectangle rect = new Rectangle(0, 0, 0, 0); if (myIconifyButton != null && myIconifyButton.getParent() != null) { rect = myIconifyButton.getBounds(); } int titleW; if (leftToRight) { if (rect.x == 0) { rect.x = window.getWidth() - window.getInsets().right - 2; } titleW = rect.x - xOffset - 4; theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW); } else { titleW = xOffset - rect.x - rect.width - 4; theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW); xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle); } int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle); if (myIdeMenu == null) { SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset); xOffset += leftToRight ? titleLength + 5 : -5; } } int w = width; int h = height; h--; g.setColor(UIManager.getColor("MenuBar.darcula.borderColor")); g.drawLine(0, h, w, h); h--; g.setColor(UIManager.getColor("MenuBar.darcula.borderShadowColor")); g.drawLine(0, h, w, h); }