RangeSelectionComponent extends AnimatedComponent { @Override protected void draw(Graphics2D g, Dimension dim) { Range selectionRange = myModel.getSelectionRange(); if (selectionRange.isEmpty() || selectionRange.getMin() > myViewRange.getMax() || selectionRange.getMax() < myViewRange.getMin()) { return; } float startXPos = rangeToX(selectionRange.getMin(), dim); float endXPos = rangeToX(selectionRange.getMax(), dim); float handleDistance = endXPos - startXPos - HANDLE_WIDTH * 2; if (handleDistance < MIN_HANDLE_DISTANCE) { handleDistance = MIN_HANDLE_DISTANCE; startXPos = (startXPos + endXPos) / 2 - HANDLE_WIDTH - MIN_HANDLE_DISTANCE / 2; endXPos = startXPos + HANDLE_WIDTH * 2 + MIN_HANDLE_DISTANCE; } g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(StudioColorsKt.getContentSelectionBackground()); Rectangle2D.Float rect = new Rectangle2D.Float(startXPos + HANDLE_WIDTH, 0, handleDistance, dim.height); g.fill(rect); if (myMouseMovedX > startXPos && myMouseMovedX < endXPos && myIsMouseOverComponent) { g.setColor(DRAG_BAR_COLOR); g.fill(new Rectangle2D.Float(startXPos + HANDLE_WIDTH, 0, handleDistance, myDragBarHeight)); } g.setColor(StudioColorsKt.getSelectionBackground()); g.fill(new Rectangle2D.Float(startXPos, 0, HANDLE_WIDTH, dim.height)); g.fill(new Rectangle2D.Float(endXPos - HANDLE_WIDTH, 0, HANDLE_WIDTH, dim.height)); } RangeSelectionComponent(@NotNull RangeSelectionModel model, @NotNull Range viewRange);  RangeSelectionComponent(@NotNull RangeSelectionModel model, @NotNull Range viewRange, boolean isPointSelectionReplaced); void addSelectionUpdatedListener(final Consumer<Range> listener); @NotNull Mode getMode(); boolean shouldShowSeekComponent(); void setDragBarHeight(int dragBarHeight); static final double CLICK_RANGE_RATIO; }
@Test public void componentIsNotDrawnIfInvisible() { Range selectionRange = new Range (60, 70); Range viewRange = new Range(30, 50); RangeSelectionComponent component = new RangeSelectionComponent(new RangeSelectionModel(selectionRange), viewRange); Dimension dimension = new Dimension(100, 100); component.setSize(dimension); Graphics2D graphics = mock(Graphics2D.class); component.draw(graphics, dimension); Mockito.verifyZeroInteractions(graphics); selectionRange.set(10, 20); component.draw(graphics, dimension); Mockito.verifyZeroInteractions(graphics); selectionRange.set(0, -1); component.draw(graphics, dimension); Mockito.verifyZeroInteractions(graphics); }