RangeTimeScrollBar extends JBScrollBar { private void rangeChanged() { myUpdating = true; int globalLengthMs = unitToMs(myGlobalRange.getLength()); Range intersection = myGlobalRange.getIntersection(myViewRange); if (!intersection.isEmpty()) { int viewLengthMs = unitToMs(intersection.getLength()); int viewRelativeMinMs = unitToMs(intersection.getMin() - myGlobalRange.getMin()); setValues(viewRelativeMinMs, viewLengthMs, 0, globalLengthMs); } else { setValues(myViewRange.getMax() < myGlobalRange.getMin() ? 0 : globalLengthMs, 0, 0, globalLengthMs); } myUpdating = false; } RangeTimeScrollBar(@NotNull Range globalRange, @NotNull Range viewRange, @NotNull TimeUnit unit);   }
@Test public void testRangeChanged() { Range global = new Range(secToUs(0), secToUs(10)); Range view = new Range(secToUs(2), secToUs(5)); RangeTimeScrollBar scrollBar = new RangeTimeScrollBar(global, view, TimeUnit.MICROSECONDS); assertThat(scrollBar.getValue()).isEqualTo(secToMillis(2)); assertThat(scrollBar.getVisibleAmount()).isEqualTo(secToMillis(5 - 2)); view.set(secToUs(3), secToUs(8)); assertThat(scrollBar.getValue()).isEqualTo(secToMillis(3)); assertThat(scrollBar.getVisibleAmount()).isEqualTo(secToMillis(8 - 3)); assertThat(scrollBar.getMinimum()).isEqualTo(secToMillis(0)); assertThat(scrollBar.getMaximum()).isEqualTo(secToMillis(10)); global.set(secToUs(0), secToUs(15)); assertThat(scrollBar.getMinimum()).isEqualTo(secToMillis(0)); assertThat(scrollBar.getMaximum()).isEqualTo(secToMillis(15)); }