mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-156745 move utility method from UIUtil to JBScrollPane
This commit is contained in:
@@ -40,7 +40,9 @@ import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.image.*;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -182,7 +184,7 @@ public class JBScrollPane extends JScrollPane {
|
||||
if (value instanceof MouseWheelListener) {
|
||||
MouseWheelListener oldListener = (MouseWheelListener)value;
|
||||
MouseWheelListener newListener = event -> {
|
||||
if (UIUtil.isScrollEvent(event)) {
|
||||
if (isScrollEvent(event)) {
|
||||
Object source = event.getSource();
|
||||
if (source instanceof JScrollPane) {
|
||||
JScrollPane pane = (JScrollPane)source;
|
||||
@@ -988,4 +990,17 @@ public class JBScrollPane extends JScrollPane {
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the specified event is not consumed and does not have unexpected modifiers.
|
||||
*
|
||||
* @param event a mouse wheel event to check for validity
|
||||
* @return {@code true} if the specified event is valid, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isScrollEvent(@NotNull MouseWheelEvent event) {
|
||||
if (event.isConsumed()) return false; // event should not be consumed already
|
||||
if (event.getWheelRotation() == 0) return false; // any rotation expected (forward or backward)
|
||||
int modifiers = ~InputEvent.SHIFT_MASK & ~InputEvent.SHIFT_DOWN_MASK & event.getModifiers();
|
||||
return modifiers == 0; // no modifiers expected except SHIFT for horizontal scrolling
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -46,6 +46,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.ui.components.JBScrollPane.isScrollEvent;
|
||||
import static java.awt.event.MouseEvent.*;
|
||||
|
||||
/**
|
||||
@@ -325,7 +326,7 @@ public final class IdeMouseEventDispatcher {
|
||||
final MouseWheelEvent mwe = (MouseWheelEvent)e;
|
||||
return mwe.isShiftDown()
|
||||
&& mwe.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL
|
||||
&& UIUtil.isScrollEvent(mwe)
|
||||
&& isScrollEvent(mwe)
|
||||
&& findHorizontalScrollBar(c) != null;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -109,7 +109,6 @@ ide.tree.deferred.icon.invalidates.cache=true
|
||||
|
||||
ide.splitter.mouseZone=6
|
||||
ide.smart.horizontal.scrolling=true
|
||||
ide.scroll.event.old.behavior=false
|
||||
ide.scroll.new.layout=true
|
||||
ide.scroll.align.component=true
|
||||
ide.scroll.background.auto=true
|
||||
|
||||
@@ -3710,18 +3710,4 @@ public class UIUtil {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the specified event is not consumed and does not have unexpected modifiers.
|
||||
*
|
||||
* @param event a mouse wheel event to check for validity
|
||||
* @return {@code true} if the specified event is valid, {@code false} otherwise
|
||||
*/
|
||||
public static boolean isScrollEvent(@NotNull MouseWheelEvent event) {
|
||||
if (Registry.is("ide.scroll.event.old.behavior")) return true;
|
||||
if (event.isConsumed()) return false; // event should not be consumed already
|
||||
if (event.getWheelRotation() == 0) return false; // any rotation expected (forward or backward)
|
||||
int modifiers = ~InputEvent.SHIFT_MASK & ~InputEvent.SHIFT_DOWN_MASK & event.getModifiers();
|
||||
return modifiers == 0; // no modifiers expected except SHIFT for horizontal scrolling
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user