MinimizedPanel extends JPanel implements SideModel.Listener<T> { public int drag(@NotNull AttachedToolWindow<T> tool, int position) { AbstractButton button = tool.getMinimizedButton(); if (!isOpaque()) { enableMinimizeButtonDragAndDrop(true); button.setVisible(true); } int insertIndex = findInsertIndex(position, button); int index = getComponentIndex(button); if (index == insertIndex) { return insertIndex; } if (index >= 0) { remove(index); } add(button, insertIndex); revalidate(); repaint(); return insertIndex; } MinimizedPanel(@NotNull Side side, @NotNull SideModel<T> model); @Override void modelChanged(@NotNull SideModel<T> model, @NotNull SideModel.EventType unused); int drag(@NotNull AttachedToolWindow<T> tool, int position); void dragExit(@NotNull AttachedToolWindow<T> tool); void dragDrop(@NotNull AttachedToolWindow<T> tool, int position);  }
@Test public void testDrag() { myPanel.setSize(21, 400); myButton1.setPreferredSize(new Dimension(21, 21)); myButton2.setPreferredSize(new Dimension(21, 21)); when(myToolWindow1.isMinimized()).thenReturn(true); when(myToolWindow2.isMinimized()).thenReturn(true); when(myModel.getTopTools(Side.LEFT)).thenReturn(Collections.singletonList(myToolWindow1)); when(myModel.getBottomTools(Side.LEFT)).thenReturn(Collections.singletonList(myToolWindow2)); myPanel.modelChanged(myModel, SideModel.EventType.LOCAL_UPDATE); myPanel.doLayout(); myPanel.drag(myToolWindow1, -99999999); assertThat(findVisibleComponents(Split.TOP)).containsExactly(myButton1); myPanel.doLayout(); myPanel.drag(myToolWindow1, 26); assertThat(findVisibleComponents(Split.TOP)).containsExactly(myButton1); myPanel.drag(myToolWindow1, 125); assertThat(findVisibleComponents(Split.TOP)).containsExactly(myButton1); myPanel.drag(myToolWindow1, 135); assertThat(findVisibleComponents(Split.TOP)).isEmpty(); assertThat(findVisibleComponents(Split.BOTTOM)).containsExactly(myButton1, myButton2).inOrder(); myPanel.drag(myToolWindow1, 255); assertThat(findVisibleComponents(Split.TOP)).isEmpty(); assertThat(findVisibleComponents(Split.BOTTOM)).containsExactly(myButton1, myButton2).inOrder(); myPanel.drag(myToolWindow1, 265); assertThat(findVisibleComponents(Split.TOP)).isEmpty(); assertThat(findVisibleComponents(Split.BOTTOM)).containsExactly(myButton2, myButton1).inOrder(); myPanel.drag(myToolWindow1, 99999999); assertThat(findVisibleComponents(Split.TOP)).isEmpty(); assertThat(findVisibleComponents(Split.BOTTOM)).containsExactly(myButton2, myButton1).inOrder(); }