Search in sources :

Example 1 with ScrollPaneUI

use of javax.swing.plaf.ScrollPaneUI in project intellij-community by JetBrains.

the class JBScrollPane method setUI.

@Override
public void setUI(ScrollPaneUI ui) {
    super.setUI(ui);
    updateViewportBorder();
    if (ui instanceof BasicScrollPaneUI) {
        try {
            Field field = BasicScrollPaneUI.class.getDeclaredField("mouseScrollListener");
            field.setAccessible(true);
            Object value = field.get(ui);
            if (value instanceof MouseWheelListener) {
                MouseWheelListener oldListener = (MouseWheelListener) value;
                MouseWheelListener newListener = event -> {
                    if (isScrollEvent(event)) {
                        Object source = event.getSource();
                        if (source instanceof JScrollPane) {
                            JScrollPane pane = (JScrollPane) source;
                            if (pane.isWheelScrollingEnabled()) {
                                JScrollBar bar = event.isShiftDown() ? pane.getHorizontalScrollBar() : pane.getVerticalScrollBar();
                                if (bar != null && bar.isVisible()) {
                                    if (!(bar instanceof JBScrollBar && ((JBScrollBar) bar).handleMouseWheelEvent(event))) {
                                        oldListener.mouseWheelMoved(event);
                                    }
                                }
                            }
                        }
                    }
                };
                field.set(ui, newListener);
                // replace listener if field updated successfully
                removeMouseWheelListener(oldListener);
                addMouseWheelListener(newListener);
            }
        } catch (Exception exception) {
            LOG.warn(exception);
        }
    }
}
Also used : JBInsets(com.intellij.util.ui.JBInsets) InputEvent(java.awt.event.InputEvent) UIUtil(com.intellij.util.ui.UIUtil) ArrayUtil(com.intellij.util.ArrayUtil) ScrollPaneUI(javax.swing.plaf.ScrollPaneUI) ButtonlessScrollBarUI(com.intellij.util.ui.ButtonlessScrollBarUI) LineBorder(javax.swing.border.LineBorder) Border(javax.swing.border.Border) JBUI.emptyInsets(com.intellij.util.ui.JBUI.emptyInsets) MouseWheelEvent(java.awt.event.MouseWheelEvent) Logger(com.intellij.openapi.diagnostic.Logger) ReflectionUtil(com.intellij.util.ReflectionUtil) BasicScrollPaneUI(javax.swing.plaf.basic.BasicScrollPaneUI) RegionPainter(com.intellij.util.ui.RegionPainter) Key(com.intellij.openapi.util.Key) Field(java.lang.reflect.Field) SystemInfo(com.intellij.openapi.util.SystemInfo) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) BasicScrollBarUI(javax.swing.plaf.basic.BasicScrollBarUI) MouseWheelListener(java.awt.event.MouseWheelListener) UIResource(javax.swing.plaf.UIResource) ScrollBarUI(javax.swing.plaf.ScrollBarUI) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Field(java.lang.reflect.Field) MouseWheelListener(java.awt.event.MouseWheelListener) BasicScrollPaneUI(javax.swing.plaf.basic.BasicScrollPaneUI)

Aggregations

Logger (com.intellij.openapi.diagnostic.Logger)1 Key (com.intellij.openapi.util.Key)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 IdeBorderFactory (com.intellij.ui.IdeBorderFactory)1 ArrayUtil (com.intellij.util.ArrayUtil)1 ReflectionUtil (com.intellij.util.ReflectionUtil)1 ButtonlessScrollBarUI (com.intellij.util.ui.ButtonlessScrollBarUI)1 JBInsets (com.intellij.util.ui.JBInsets)1 JBUI.emptyInsets (com.intellij.util.ui.JBUI.emptyInsets)1 RegionPainter (com.intellij.util.ui.RegionPainter)1 UIUtil (com.intellij.util.ui.UIUtil)1 java.awt (java.awt)1 InputEvent (java.awt.event.InputEvent)1 MouseEvent (java.awt.event.MouseEvent)1 MouseWheelEvent (java.awt.event.MouseWheelEvent)1 MouseWheelListener (java.awt.event.MouseWheelListener)1 Field (java.lang.reflect.Field)1 javax.swing (javax.swing)1 Border (javax.swing.border.Border)1 LineBorder (javax.swing.border.LineBorder)1