TabLabel (@NotNull TabInfo info) { return new TabLabel(this, info) { { for (MouseListener listener : getMouseListeners()) { removeMouseListener(listener); } TabLabel label = this; addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (!UIUtil.isCloseClick(e, MouseEvent.MOUSE_PRESSED) && !_isSelectionClick(e)) { handlePopup(e); } } @Override public void mouseReleased(MouseEvent e) { handlePopup(e); } @Override public void mouseClicked(MouseEvent e) { if (_isSelectionClick(e)) { Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); if (c instanceof InplaceButton) return; myTabs.select(info, true); JBPopup container = PopupUtil.getPopupContainerFor(label); if (container != null && ClientProperty.isTrue(container.getContent(), MorePopupAware.class)) { container.cancel(); } } else if (e.getButton() == MouseEvent.BUTTON2) { closeTab((IdeFrameImpl)getInfo().getObject(), false); } else { handlePopup(e); } } @Override public void mouseEntered(MouseEvent e) { setHovered(true); } @Override public void mouseExited(MouseEvent e) { setHovered(false); } }); } @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, JBUI.scale(TAB_HEIGHT)); } @Override public void setTabActions(ActionGroup group) { super.setTabActions(group); if (myActionPanel != null) { Container parent = myActionPanel.getParent(); parent.remove(myActionPanel); parent.add(new Wrapper(myActionPanel) { @Override public Dimension getPreferredSize() { return myActionPanel.getPreferredSize(); } }, BorderLayout.WEST); myActionPanel.setBorder(JBUI.Borders.emptyLeft(6)); myActionPanel.setVisible(!showCloseActionOnHover()); } } @Override protected void setHovered(boolean value) { super.setHovered(value); myActionPanel.setVisible(!showCloseActionOnHover() || value || getInfo() == myTabs.getPopupInfo()); } @Override protected void handlePopup(MouseEvent e) { super.handlePopup(e); JPopupMenu popup = myTabs.getActivePopup(); if (popup != null) { popup.addPopupMenuListener(new PopupMenuListenerAdapter() { @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { handle(); } @Override public void popupMenuCanceled(PopupMenuEvent e) { handle(); } private void handle() { popup.removePopupMenuListener(this); myActionPanel.setVisible(!showCloseActionOnHover() || isHovered()); } }); } } @Override protected boolean isTabActionsOnTheRight() { return false; } @Override protected boolean shouldPaintFadeout() { return false; } }; }