void (@NotNull JComponent c, @NotNull ToolWindowContentUi ui, boolean allowResize) { if (c.getClientProperty(TOOLWINDOW_UI_INSTALLED) != null) { return; } MouseAdapter mouseAdapter = new MouseAdapter() { final Ref<Point> myLastPoint = Ref.create(); final Ref<Point> myPressPoint = Ref.create(); final Ref<Integer> myInitialHeight = Ref.create(0); final Ref<Boolean> myIsLastComponent = Ref.create(); final Ref<LocationOnDragTracker> myDragTracker = Ref.create(); private Component getActualSplitter() { if (!allowResize || !ui.isResizeable()) { return null; } Component component = c; Component parent = component.getParent(); while(parent != null) { if (parent instanceof ThreeComponentsSplitter && ((ThreeComponentsSplitter)parent).getOrientation()) { if (component != ((ThreeComponentsSplitter)parent).getFirstComponent()) { return parent; } } if (parent instanceof Splitter && ((Splitter)parent).isVertical() && ((Splitter)parent).getSecondComponent() == component && ((Splitter)parent).getFirstComponent() != null) { return parent; } if (parent instanceof ToolWindowPane) { return parent; } component = parent; parent = parent.getParent(); } return null; } private void arm(Component c) { Component component = c != null ? getActualSplitter() : null; if (component instanceof ThreeComponentsSplitter) { ThreeComponentsSplitter splitter = (ThreeComponentsSplitter)component; myIsLastComponent.set(SwingUtilities.isDescendingFrom(c, splitter.getLastComponent())); myInitialHeight.set(myIsLastComponent.get() ? splitter.getLastSize() : splitter.getFirstSize()); return; } if (component instanceof Splitter) { Splitter splitter = (Splitter)component; myIsLastComponent.set(true); myInitialHeight.set(splitter.getSecondComponent().getHeight()); return; } if (component instanceof ToolWindowPane) { myIsLastComponent.set(ui.window.getAnchor() == ToolWindowAnchor.BOTTOM || ui.window.getAnchor() == ToolWindowAnchor.RIGHT); myInitialHeight.set(ui.window.getAnchor().isHorizontal() ? ui.window.getDecorator().getHeight() : ui.window.getDecorator().getWidth()); return; } myIsLastComponent.set(null); myInitialHeight.set(null); myPressPoint.set(null); myDragTracker.set(null); } @Override public void mousePressed(@NotNull MouseEvent e) { if (e.isPopupTrigger() || UIUtil.isCloseClick(e)) return; if (!isToolWindowDrag(e)) { myLastPoint.set(e.getLocationOnScreen()); myPressPoint.set(myLastPoint.get()); myDragTracker.set(LocationOnDragTracker.startDrag(e)); if (allowResize && ui.isResizeable()) { arm(c.getComponentAt(e.getPoint()) == c && ui.isResizeable(e.getPoint()) ? c : null); } } ui.window.fireActivated(ToolWindowEventSource.ToolWindowHeader); } @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { if (ui.tabsLayout.doubleClickActions.isEmpty() || !(e.getComponent() instanceof ContentTabLabel)) { ToolWindowManagerEx manager = ui.window.getToolWindowManager(); manager.setMaximized(ui.window, !manager.isMaximized(ui.window)); } } } @Override public void mouseReleased(@NotNull MouseEvent e) { if (!e.isPopupTrigger()) { if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) { ui.processHide(e); } arm(null); } } @Override public void mouseMoved(MouseEvent e) { if (isToolWindowDrag(e)) { c.setCursor(Cursor.getDefaultCursor()); return; } c.setCursor(allowResize && ui.isResizeable() && getActualSplitter() != null && c.getComponentAt(e.getPoint()) == c && ui.isResizeable(e.getPoint()) ? Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR) : Cursor.getDefaultCursor()); } @Override public void mouseExited(MouseEvent e) { c.setCursor(null); } private boolean isToolWindowDrag(MouseEvent e) { if (!AdvancedSettings.getBoolean("ide.tool.window.header.dnd")) { return false; } Component realMouseTarget = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); Component decorator = InternalDecoratorImpl.findTopLevelDecorator(realMouseTarget); if (decorator == null || ui.window.getType() == ToolWindowType.FLOATING || ui.window.getType() == ToolWindowType.WINDOWED) { return false; } if (ui.window.getAnchor() != ToolWindowAnchor.BOTTOM || SwingUtilities.convertMouseEvent(e.getComponent(), e, decorator).getY() > ToolWindowPane.Companion.getHeaderResizeArea$intellij_platform_ide_impl()) { return true; } //it's drag, not resize! return false; } @Override public void mouseDragged(MouseEvent e) { if (myLastPoint.isNull() || myPressPoint.isNull() || myDragTracker.isNull()) return; //"Dock" modes, // for "Undock" mode processing see com.intellij.toolWindow.InternalDecoratorImpl.ResizeOrMoveDocketToolWindowMouseListener Point newMouseLocation = e.getLocationOnScreen(); Window window = SwingUtilities.windowForComponent(c); if (!(window instanceof IdeFrame)) { myDragTracker.get().updateLocationOnDrag(window, newMouseLocation); } myLastPoint.set(newMouseLocation); Component component = getActualSplitter(); if (isToolWindowDrag(e)) return;//it's drag, not resize! if (component instanceof ThreeComponentsSplitter) { ThreeComponentsSplitter splitter = (ThreeComponentsSplitter)component; if (myIsLastComponent.get() == Boolean.TRUE) { splitter.setLastSize(myInitialHeight.get() + myPressPoint.get().y - myLastPoint.get().y); } else { splitter.setFirstSize(myInitialHeight.get() + myLastPoint.get().y - myPressPoint.get().y); } } if (component instanceof Splitter) { Splitter splitter = (Splitter)component; splitter.setProportion(Math.max(0, Math.min(1, 1f - (float)(myInitialHeight.get() + myPressPoint.get().y - myLastPoint.get().y )/ splitter.getHeight()))); } if (component instanceof ToolWindowPane) { if (ui.window.getType() == ToolWindowType.SLIDING) { ui.window.getDecorator().updateBounds(e); } else { Dimension size = ui.window.getDecorator().getSize(); if (ui.window.getAnchor().isHorizontal()) { size.height = myInitialHeight.get() - myLastPoint.get().y + myPressPoint.get().y; } ui.window.getDecorator().setSize(size); } } } }; c.addMouseMotionListener(mouseAdapter); c.addMouseListener(mouseAdapter); c.addMouseListener(new PopupHandler() { @Override public void invokePopup(final Component comp, final int x, final int y) { final Content content = c instanceof BaseLabel ? ((BaseLabel)c).getContent() : null; ui.showContextMenu(comp, x, y, ui.window.createPopupGroup(), content); } }); c.putClientProperty(TOOLWINDOW_UI_INSTALLED, Boolean.TRUE); }