private static int getScrollAmount(Component c, MouseWheelEvent me, JScrollBar scrollBar) { final int scrollBarWidth = scrollBar.getWidth(); final int ratio = Registry.is("ide.smart.horizontal.scrolling") && scrollBarWidth > 0 ? Math.max((int) Math.pow(c.getWidth() / scrollBarWidth, 2), 10) : 10; // do annoying scrolling faster if smart scrolling is on return me.getUnitsToScroll() * scrollBar.getUnitIncrement() * ratio; }
private boolean doHorizontalScrolling(Component c, MouseWheelEvent me) { final JScrollBar scrollBar = findHorizontalScrollBar(c); if (scrollBar != null) { if (scrollBar.hashCode() != myLastHorScrolledComponentHash) { FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.horizontal.scrolling"); myLastHorScrolledComponentHash = scrollBar.hashCode(); } scrollBar.setValue(scrollBar.getValue() + getScrollAmount(c, me, scrollBar)); return true; } return false; }
@Nullable private static JScrollBar findHorizontalScrollBar(Component c) { if (c == null) return null; if (c instanceof JScrollPane) { return ((JScrollPane) c).getHorizontalScrollBar(); } if (isDiagramViewComponent(c)) { final JComponent view = (JComponent) c; for (int i = 0; i < view.getComponentCount(); i++) { if (view.getComponent(i) instanceof JScrollBar) { final JScrollBar scrollBar = (JScrollBar) view.getComponent(i); if (scrollBar.getOrientation() == Adjustable.HORIZONTAL) { return scrollBar; } } } } return findHorizontalScrollBar(c.getParent()); }