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;
 }
 private void scrollOther(
     int scrollPosCorrected,
     final int maxColumnsOur,
     int maxColumnsOther,
     final List<ScrollingModel> models) {
   int pos2;
   if (myLeftScroll.getValue() == 0) {
     pos2 = 0;
   } else if ((scrollPosCorrected + myLeftScroll.getModel().getExtent()) >= maxColumnsOur) {
     pos2 = maxColumnsOther + 1;
   } else {
     pos2 = (int) (scrollPosCorrected * (((double) maxColumnsOther) / maxColumnsOur));
   }
   final int pointX2 = (int) myEditor.logicalPositionToXY(new LogicalPosition(0, pos2)).getX();
   for (ScrollingModel model : models) {
     model.scrollHorizontally(pointX2);
   }
 }
  @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());
  }
    public void afterPanelsAdded() {
      myLeftScroll.setMinimum(0);
      myLeftScroll.setMaximum(myMaxColumnsLeft);
      myLeftScroll.addAdjustmentListener(
          new AdjustmentListener() {
            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
              myInScrolling = true;

              final int scrollPosCorrected = myLeftScroll.getValue() + 1;
              if (myByLeft) {
                scrollMain(myLeftScroll.getValue(), myLeftModels);
                scrollOther(scrollPosCorrected, myMaxColumnsLeft, myMaxColumnsRight, myRightModels);
              } else {
                scrollMain(myLeftScroll.getValue(), myRightModels);
                scrollOther(scrollPosCorrected, myMaxColumnsRight, myMaxColumnsLeft, myLeftModels);
              }
              myInScrolling = false;
            }
          });
    }
    private MyScrollingHelper() {
      myLeftScroll = new JScrollBar(JScrollBar.HORIZONTAL);
      myLeftScroll.setUI(ButtonlessScrollBarUI.createNormal());

      myLeftEditors = new ArrayList<Editor>();
      myRightEditors = new ArrayList<Editor>();

      myMaxColumnsLeft = 0;
      myMaxColumnsRight = 0;
      myLeftModels = new ArrayList<ScrollingModel>();
      myRightModels = new ArrayList<ScrollingModel>();
    }
    private void recalculateMaxValues() {
      myIdxLeft = widestEditor(myLeftEditors);
      final Editor leftEditor = myLeftEditors.get(myIdxLeft);
      final int wholeWidth = leftEditor.getContentComponent().getWidth();
      final Rectangle va = leftEditor.getScrollingModel().getVisibleArea();
      final int visibleLeft = leftEditor.xyToVisualPosition(new Point(va.width, 0)).column;

      myMaxColumnsLeft = (int) (visibleLeft * ((double) wholeWidth / va.getWidth()));

      myIdxRight = widestEditor(myRightEditors);
      final Editor rightEditor = myRightEditors.get(myIdxRight);
      final int wholeWidthRight = rightEditor.getContentComponent().getWidth();
      final Rectangle vaRight = rightEditor.getScrollingModel().getVisibleArea();
      final int visibleRight = rightEditor.xyToVisualPosition(new Point(va.width, 0)).column;

      myMaxColumnsRight = (int) (visibleRight * ((double) wholeWidthRight / vaRight.getWidth()));

      myByLeft = !(myMaxColumnsLeft <= visibleLeft);
      if (!myByLeft) {
        // check right editor
        if (myLeftScroll.getVisibleAmount() != visibleRight) {
          myLeftScroll.setVisibleAmount(visibleRight);
        }
        myLeftScroll.setMaximum(myMaxColumnsRight);
      } else {
        if (myLeftScroll.getVisibleAmount() != visibleLeft) {
          myLeftScroll.setVisibleAmount(visibleLeft);
        }
        myLeftScroll.setMaximum(myMaxColumnsLeft);
      }
    }