mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove unused code
This commit is contained in:
@@ -17,7 +17,6 @@ package com.intellij.ide;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.Topic;
|
||||
|
||||
@@ -31,7 +30,6 @@ public class PowerSaveMode {
|
||||
|
||||
public PowerSaveMode(MessageBus bus) {
|
||||
myBus = bus;
|
||||
ComponentSettings.getInstance().setPowerSaveModeEnabled(myEnabled);
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
@@ -44,7 +42,6 @@ public class PowerSaveMode {
|
||||
instance.myEnabled = value;
|
||||
instance.myBus.syncPublisher(TOPIC).powerSaveStateChanged();
|
||||
PropertiesComponent.getInstance().setValue(POWER_SAVE_MODE, value);
|
||||
ComponentSettings.getInstance().setPowerSaveModeEnabled(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.registry.RegistryValue;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* IDE-agnostic component settings.
|
||||
*/
|
||||
public class ComponentSettings {
|
||||
private static final boolean SUPPORTED_JAVA = SystemInfo.isJetbrainsJvm || SystemInfo.isJavaVersionAtLeast("1.9");
|
||||
private static final RegistryValue SUPPORTED = Registry.get("ide.scroll.precise");
|
||||
|
||||
private static final RegistryValue HIGH_PRECISION_SCROLLING = Registry.get("idea.true.smooth.scrolling.high.precision");
|
||||
|
||||
private static final RegistryValue PIXEL_PERFECT_SCROLLING = Registry.get("idea.true.smooth.scrolling.pixel.perfect");
|
||||
|
||||
private boolean mySmoothScrollingEnabled = true;
|
||||
private boolean myRemoteDesktopConnected;
|
||||
private boolean myPowerSaveModeEnabled;
|
||||
|
||||
private static final ComponentSettings ourInstance = new ComponentSettings();
|
||||
|
||||
public static ComponentSettings getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
// Returns whether "true smooth scrolling" is applicable to the particular component
|
||||
public boolean isTrueSmoothScrollingEligibleFor(Component component) {
|
||||
if (ApplicationManager.getApplication() == null) return false;
|
||||
return isSmoothScrollingSupported() &&
|
||||
!ApplicationManager.getApplication().isUnitTestMode() &&
|
||||
mySmoothScrollingEnabled &&
|
||||
!myRemoteDesktopConnected &&
|
||||
!myPowerSaveModeEnabled &&
|
||||
component != null &&
|
||||
component.isShowing();
|
||||
}
|
||||
|
||||
// Returns whether smooth scrolling supported
|
||||
public boolean isSmoothScrollingSupported() {
|
||||
return SUPPORTED.asBoolean() || (SUPPORTED_JAVA && SystemInfo.isMac);
|
||||
}
|
||||
|
||||
// Returns whether high-precision scrolling events are enabled
|
||||
public boolean isHighPrecisionScrollingEnabled() {
|
||||
return HIGH_PRECISION_SCROLLING.asBoolean();
|
||||
}
|
||||
|
||||
// Returns whether pixel-perfect scrolling events are enabled (requires high-precision events to be effective)
|
||||
public boolean isPixelPerfectScrollingEnabled() {
|
||||
return PIXEL_PERFECT_SCROLLING.asBoolean();
|
||||
}
|
||||
|
||||
/* A heuristics that disables scrolling interpolation in diff / merge windows.
|
||||
We need to to make scrolling synchronization compatible with the interpolation first.
|
||||
|
||||
NOTE: The implementation is a temporary, ad-hoc heuristics that is needed solely to
|
||||
facilitate testing of the experimental "true smooth scrolling" feature. */
|
||||
public boolean isInterpolationEligibleFor(JScrollBar scrollbar) {
|
||||
Window window = (Window)scrollbar.getTopLevelAncestor();
|
||||
|
||||
if (window instanceof JDialog && "Commit Changes".equals(((JDialog)window).getTitle())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(window instanceof RootPaneContainer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Component[] components = ((RootPaneContainer)window).getContentPane().getComponents();
|
||||
|
||||
if (components.length == 1 && components[0].getClass().getName().contains("DiffWindow")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (components.length == 2 && components[0] instanceof Container) {
|
||||
Component[] subComponents = ((Container)components[0]).getComponents();
|
||||
if (subComponents.length == 1) {
|
||||
String name = subComponents[0].getClass().getName();
|
||||
if (name.contains("DiffWindow") || name.contains("MergeWindow")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSmoothScrollingEnabled(boolean enabled) {
|
||||
mySmoothScrollingEnabled = enabled;
|
||||
}
|
||||
|
||||
public void setRemoteDesktopConnected(boolean connected) {
|
||||
myRemoteDesktopConnected = connected;
|
||||
}
|
||||
|
||||
public void setPowerSaveModeEnabled(boolean enabled) {
|
||||
myPowerSaveModeEnabled = enabled;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,6 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsApplicationSettings;
|
||||
import com.intellij.openapi.vcs.impl.LineStatusTrackerSettingListener;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
@@ -257,7 +256,6 @@ public class EditorOptionsPanel implements SearchableConfigurable {
|
||||
// Display
|
||||
|
||||
editorSettings.setSmoothScrolling(myCbSmoothScrolling.isSelected());
|
||||
ComponentSettings.getInstance().setSmoothScrollingEnabled(myCbSmoothScrolling.isSelected());
|
||||
|
||||
|
||||
// Brace Highlighting
|
||||
|
||||
@@ -36,7 +36,6 @@ import javax.swing.plaf.basic.BasicTreeUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ContainerEvent;
|
||||
import java.awt.event.ContainerListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
import static com.intellij.util.ui.JBUI.emptyInsets;
|
||||
|
||||
@@ -77,10 +76,6 @@ public class JBViewport extends JViewport implements ZoomableViewport {
|
||||
|
||||
private volatile boolean myBackgroundRequested; // avoid cyclic references
|
||||
|
||||
private boolean myUpdateViewPosition; // avoid cyclic references
|
||||
private final ViewPosition myViewX = new ViewPosition();
|
||||
private final ViewPosition myViewY = new ViewPosition();
|
||||
|
||||
public JBViewport() {
|
||||
addContainerListener(new ContainerListener() {
|
||||
@Override
|
||||
@@ -108,56 +103,9 @@ public class JBViewport extends JViewport implements ZoomableViewport {
|
||||
if (ScrollSettings.isDebugEnabled() && !p.equals(getViewPosition()) && !isInsideLogToolWindow()) {
|
||||
checkScrollingCapabilities();
|
||||
}
|
||||
|
||||
if (myUpdateViewPosition) return;
|
||||
myViewX.set(p.x);
|
||||
myViewY.set(p.y);
|
||||
super.setViewPosition(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a view position directly without using a corresponding scroll bar.
|
||||
*
|
||||
* @param event a wheel event with a precise wheel rotation used to calculate an absolute delta
|
||||
*/
|
||||
void updateViewPosition(MouseWheelEvent event) {
|
||||
Component view = getView();
|
||||
if (view == null) return; // nothing to scroll
|
||||
|
||||
if (event.isShiftDown()) {
|
||||
if (!myViewX.update(view, event, view.getWidth() - getWidth())) return; // nothing changed
|
||||
}
|
||||
else {
|
||||
if (!myViewY.update(view, event, view.getHeight() - getHeight())) return; // nothing changed
|
||||
}
|
||||
try {
|
||||
myUpdateViewPosition = true;
|
||||
super.setViewPosition(new Point(myViewX.get(), myViewY.get()));
|
||||
}
|
||||
finally {
|
||||
myUpdateViewPosition = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates an offset in pixels to scroll a view precisely.
|
||||
*
|
||||
* @param view a view to scroll
|
||||
* @param event a wheel event with a precise wheel rotation used to calculate an absolute delta
|
||||
* @return a non-zero finite floating-point value, if a scrolling should be performed
|
||||
*/
|
||||
private static double getAbsoluteDelta(Component view, MouseWheelEvent event) {
|
||||
// Native code in our JDK for Mac uses 0.1 to convert pixels to units,
|
||||
// so we use 10 to restore amount of pixels to scroll.
|
||||
int unitSizeInPixels = 10;
|
||||
if (!SystemInfo.isMac) {
|
||||
Font font = view.getFont();
|
||||
unitSizeInPixels = font != null ? font.getSize() : JBUI.scale(10); // assume an unit size
|
||||
unitSizeInPixels *= event.getScrollAmount(); // an operating system may increase a scrolling speed
|
||||
}
|
||||
return unitSizeInPixels * event.getPreciseWheelRotation();
|
||||
}
|
||||
|
||||
// A heuristic to detect whether this viewport belongs to the "Event Log" tool window (which we use for output)
|
||||
private boolean isInsideLogToolWindow() {
|
||||
Container parent1 = getParent();
|
||||
@@ -358,21 +306,6 @@ public class JBViewport extends JViewport implements ZoomableViewport {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alignment of the specified scroll bar
|
||||
* if and only if the specified scroll bar
|
||||
* is located over the main viewport.
|
||||
*
|
||||
* @param bar the scroll bar to process
|
||||
* @return the scroll bar alignment or {@code null}
|
||||
*/
|
||||
private static Alignment getAlignment(JScrollBar bar) {
|
||||
if (bar != null && bar.isVisible() && !bar.isOpaque()) {
|
||||
return UIUtil.getClientProperty(bar, Alignment.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isAlignmentNeeded(JComponent view, boolean horizontal) {
|
||||
return (!SystemInfo.isMac || horizontal && ScrollSettings.isHorizontalGapNeededOnMac()) &&
|
||||
(view instanceof JList || view instanceof JTree || (!SystemInfo.isMac && ScrollSettings.isGapNeededForAnyComponent()));
|
||||
@@ -570,56 +503,4 @@ public class JBViewport extends JViewport implements ZoomableViewport {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ViewPosition {
|
||||
private int myValue;
|
||||
private int myDirection;
|
||||
private double myAccumulator;
|
||||
|
||||
/**
|
||||
* @return current view position
|
||||
*/
|
||||
int get() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new view position and resets internal accumulator.
|
||||
*
|
||||
* @param newValue new value for position
|
||||
*/
|
||||
void set(int newValue) {
|
||||
myValue = newValue;
|
||||
myAccumulator = newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates internal accumulator and calculates corresponding view position.
|
||||
*
|
||||
* @param view a view to scroll
|
||||
* @param event a wheel event with a precise wheel rotation used to calculate an absolute delta
|
||||
* @param max a maximal value for
|
||||
* @return {@code true} if current view position is changed, {@code false} otherwise
|
||||
*/
|
||||
boolean update(Component view, MouseWheelEvent event, int max) {
|
||||
int old = myValue;
|
||||
int reset = 0;
|
||||
if (max > 0) {
|
||||
double delta = getAbsoluteDelta(view, event);
|
||||
if (delta == 0.0D || !Double.isFinite(delta)) return false;
|
||||
// remove fractional part if a scrolling direction is changed
|
||||
int direction = delta < 0.0D ? -1 : 1;
|
||||
if (direction != myDirection) myAccumulator = myValue;
|
||||
myDirection = direction;
|
||||
// add the specified delta to the value
|
||||
myAccumulator += delta;
|
||||
myValue = (int)myAccumulator;
|
||||
// bind calculated value to the range [0..max]
|
||||
if (0 <= myValue && myValue <= max) return myValue != old;
|
||||
if (myValue > max) reset = max; // reset accumulator to max value
|
||||
}
|
||||
set(reset); // reset accumulator if a value is out of the range
|
||||
return reset != old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui.components;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
/**
|
||||
* Accessor for absolute scrolling delta in enhanced MouseWheelEvent.
|
||||
*/
|
||||
class MouseWheelEventEx {
|
||||
/**
|
||||
* Returns scrolling delta as an absolute value (if available). Requires JetBrains Runtime.
|
||||
* <p>
|
||||
* Some devices (e.g. high-precision touchpads) may report scrolling deltas
|
||||
* in absolute values rather than in fractions of a "click". This data can be used,
|
||||
* for example, to implement pixel-perfect scrolling (which cannot be
|
||||
* implemented via the {@link MouseWheelEvent#getPreciseWheelRotation} method, as fractions
|
||||
* of scrolling "units" cannot be reliably translated to pixel-precise deltas).
|
||||
* <p>
|
||||
* JetBrains Runtime currently uses <code>preciseWheelRotation = 0.1 * scrollingDelta</code>
|
||||
* mapping in Mac OS to encode absolute scrolling deltas as relative ones.
|
||||
* <p>
|
||||
* That approach is suboptimal, because it:
|
||||
* 1) produces different dynamics of relative deltas (in Mac OS there's no reliable linear mapping between those values),
|
||||
* 2) makes handling of true relative deltas impossible, as there's no way to distinguish them from the encoded absolute ones
|
||||
* (if we choose to decode the absolute deltas).
|
||||
* <p>
|
||||
* Ideally, we need to implement a method of distinguishing between the two kinds of scrolling deltas.
|
||||
*
|
||||
* @param e the event
|
||||
* @return negative values for scrolling up, positive values for scrolling down
|
||||
* 0.0 when absolute deltas are not supported or not available
|
||||
*/
|
||||
static double getAbsoluteDelta(MouseWheelEvent e) {
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
|
||||
return settings.isPixelPerfectScrollingEnabled()
|
||||
? areAbsoluteDeltasSupported() ? 10.0D * e.getPreciseWheelRotation() : 0.0D
|
||||
: 0.0D;
|
||||
}
|
||||
|
||||
private static boolean areAbsoluteDeltasSupported() {
|
||||
return SystemInfo.isJetbrainsJvm && SystemInfo.isMac;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui.components;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
/**
|
||||
* A {@link DefaultBoundedRangeModel} that doesn't notify its scrollbar UI listener on value changes
|
||||
* while the scrollbar value is adjusted if scrollbar interpolation is enabled.
|
||||
*/
|
||||
public class SmoothBoundedRangeModel extends DefaultBoundedRangeModel {
|
||||
private static final String SCROLLBAR_UI_LISTENER_PATTERN = "ScrollBarUI";
|
||||
|
||||
private final JScrollBar myScrollBar;
|
||||
|
||||
public SmoothBoundedRangeModel(JScrollBar scrollBar) {
|
||||
myScrollBar = scrollBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link DefaultBoundedRangeModel#fireStateChanged()} with optional filtering.
|
||||
*/
|
||||
@Override
|
||||
protected void fireStateChanged() {
|
||||
if (!ScrollSource.SCROLLBAR.isInterpolationEnabled()) {
|
||||
super.fireStateChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Object[] listeners = listenerList.getListenerList();
|
||||
for (int i = listeners.length - 2; i >= 0; i -= 2) {
|
||||
if (listeners[i] == ChangeListener.class) {
|
||||
if (changeEvent == null) {
|
||||
changeEvent = new ChangeEvent(this);
|
||||
}
|
||||
ChangeListener listener = (ChangeListener)listeners[i + 1];
|
||||
if (!(myScrollBar.getValueIsAdjusting() && listener.getClass().getName().contains(SCROLLBAR_UI_LISTENER_PATTERN))) {
|
||||
listener.stateChanged(changeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui.components;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
/**
|
||||
* Scroll pane that supports high-precision mouse wheel events (including pixel-perfect ones) and input interpolation.
|
||||
*/
|
||||
public class SmoothScrollPane extends JScrollPane {
|
||||
private static final Logger LOG = Logger.getInstance(SmoothScrollPane.class);
|
||||
private static final double EPSILON = 1E-5D;
|
||||
|
||||
private ScrollSource myScrollSource = ScrollSource.UNKNOWN;
|
||||
private double myWheelRotation;
|
||||
|
||||
public SmoothScrollPane() {
|
||||
}
|
||||
|
||||
public SmoothScrollPane(Component view) {
|
||||
super(view);
|
||||
}
|
||||
|
||||
public SmoothScrollPane(int vsbPolicy, int hsbPolicy) {
|
||||
super(vsbPolicy, hsbPolicy);
|
||||
}
|
||||
|
||||
public SmoothScrollPane(Component view, int vsbPolicy, int hsbPolicy) {
|
||||
super(view, vsbPolicy, hsbPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processMouseWheelEvent(MouseWheelEvent e) {
|
||||
boolean hasAbsoluteDelta = ComponentSettings.getInstance().isPixelPerfectScrollingEnabled() &&
|
||||
MouseWheelEventEx.getAbsoluteDelta(e) != 0.0D;
|
||||
myScrollSource = hasAbsoluteDelta ? ScrollSource.TOUCHPAD : ScrollSource.MOUSE_WHEEL;
|
||||
myWheelRotation = e.getPreciseWheelRotation();
|
||||
super.processMouseWheelEvent(e);
|
||||
myScrollSource = ScrollSource.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JScrollBar createVerticalScrollBar() {
|
||||
return new SmoothScrollBar(Adjustable.VERTICAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JScrollBar createHorizontalScrollBar() {
|
||||
return new SmoothScrollBar(Adjustable.HORIZONTAL);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void setUI(ScrollPaneUI ui) {
|
||||
super.setUI(ui);
|
||||
|
||||
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 = e -> handleMouseWheelEvent(e, oldListener);
|
||||
field.set(ui, newListener);
|
||||
removeMouseWheelListener(oldListener);
|
||||
addMouseWheelListener(newListener);
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
LOG.warn(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private void handleMouseWheelEvent(MouseWheelEvent e, MouseWheelListener delegate) {
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
|
||||
if (settings.isTrueSmoothScrollingEligibleFor(this) &&
|
||||
settings.isHighPrecisionScrollingEnabled() &&
|
||||
isWheelScrollingEnabled() && e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
|
||||
|
||||
mouseWheelMoved(e);
|
||||
e.consume();
|
||||
}
|
||||
else {
|
||||
delegate.mouseWheelMoved(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Although Java 7 introduced {@link MouseWheelEvent#getPreciseWheelRotation} method,
|
||||
* {@link JScrollPane} doesn't use it so far. This methods handles the precise wheel rotation events.
|
||||
* <p>
|
||||
* Additionally, to support pixel-perfect deltas, the handler can be paired up with our custom JRE which
|
||||
* <a href="https://github.com/JetBrains/jdk8u_jdk/commit/568f2dae82b0fe27b79ce6943071d89463758610">enhances MouseWheelEvent</a>
|
||||
* and <a href="https://github.com/JetBrains/jdk8u_jdk/commit/a3cb8807b148879e9c70a74a8a16c30a28991581">implements</a>
|
||||
* those events in Mac OS X.
|
||||
*
|
||||
* @see BasicScrollPaneUI.Handler#mouseWheelMoved(MouseWheelEvent)
|
||||
* @see javax.swing.plaf.basic.BasicScrollBarUI#scrollByUnits
|
||||
*/
|
||||
private void mouseWheelMoved(MouseWheelEvent e) {
|
||||
JScrollBar scrollbar = e.isShiftDown() ? getHorizontalScrollBar() : getVerticalScrollBar();
|
||||
|
||||
double delta = MouseWheelEventEx.getAbsoluteDelta(e);
|
||||
if (delta == 0.0D) {
|
||||
delta = getRelativeDelta(e, scrollbar);
|
||||
}
|
||||
|
||||
int value = scrollbar instanceof Interpolable ? (((Interpolable)scrollbar).getTargetValue()) : scrollbar.getValue();
|
||||
double minDelta = (double)scrollbar.getMinimum() - value;
|
||||
double maxDelta = (double)scrollbar.getMaximum() - scrollbar.getModel().getExtent() - value;
|
||||
double boundedDelta = max(minDelta, min(delta, maxDelta));
|
||||
|
||||
if (scrollbar instanceof FinelyAdjustable) {
|
||||
((FinelyAdjustable)scrollbar).adjustValue(boundedDelta);
|
||||
}
|
||||
else {
|
||||
scrollbar.setValue(value + (int)round(boundedDelta));
|
||||
}
|
||||
}
|
||||
|
||||
private double getRelativeDelta(MouseWheelEvent e, JScrollBar scrollbar) {
|
||||
JViewport viewport = getViewport();
|
||||
|
||||
double rotation = e.getPreciseWheelRotation();
|
||||
int direction = rotation < 0 ? -1 : 1;
|
||||
int unitIncrement = getUnitIncrement(viewport, scrollbar, direction);
|
||||
double delta = rotation * e.getScrollAmount() * unitIncrement;
|
||||
|
||||
boolean adjustDelta = abs(rotation) < 1.0D + EPSILON;
|
||||
int blockIncrement = getBlockIncrement(viewport, scrollbar, direction);
|
||||
return adjustDelta ? max(-(double)blockIncrement, min(delta, (double)blockIncrement)) : delta;
|
||||
}
|
||||
|
||||
private static int getUnitIncrement(JViewport viewport, JScrollBar scrollbar, int direction) {
|
||||
Scrollable scrollable = getScrollable(viewport);
|
||||
|
||||
if (scrollable == null) {
|
||||
return scrollbar.getUnitIncrement(direction);
|
||||
}
|
||||
else {
|
||||
// Use (0, 0) view position to obtain constant unit increment (which might otherwise be variable on smaller-than-unit scrolling).
|
||||
Rectangle r = new Rectangle(new Point(0, 0), viewport.getViewSize());
|
||||
return scrollable.getScrollableUnitIncrement(r, scrollbar.getOrientation(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getBlockIncrement(JViewport viewport, JScrollBar scrollbar, int direction) {
|
||||
Scrollable scrollable = getScrollable(viewport);
|
||||
Rectangle r = new Rectangle(new Point(0, 0), viewport.getViewSize());
|
||||
return scrollable == null ? scrollbar.getBlockIncrement(direction)
|
||||
: scrollable.getScrollableBlockIncrement(r, scrollbar.getOrientation(), 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Scrollable getScrollable(JViewport viewport) {
|
||||
return viewport != null && (viewport.getView() instanceof Scrollable) ? (Scrollable)(viewport.getView()) : null;
|
||||
}
|
||||
|
||||
int getInitialDelay(boolean valueIsAdjusting) {
|
||||
ScrollSource source = valueIsAdjusting ? ScrollSource.SCROLLBAR : myScrollSource;
|
||||
return source.getInterpolationDelay(myWheelRotation);
|
||||
}
|
||||
|
||||
protected class SmoothScrollBar extends ScrollBar implements Interpolable, FinelyAdjustable {
|
||||
private final Interpolator myInterpolator = new Interpolator(this::getValue, this::setCurrentValue);
|
||||
private final Adjuster myAdjuster = new Adjuster(delta -> setValue(getTargetValue() + delta));
|
||||
|
||||
protected SmoothScrollBar(int orientation) {
|
||||
super(orientation);
|
||||
if (SystemProperties.isTrueSmoothScrollingEnabled()) {
|
||||
setModel(new SmoothBoundedRangeModel(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(int value) {
|
||||
int delay = 0;
|
||||
ComponentSettings settings = ComponentSettings.getInstance();
|
||||
|
||||
if (settings.isTrueSmoothScrollingEligibleFor(getViewport().getView()) && settings.isInterpolationEligibleFor(this)) {
|
||||
delay = getInitialDelay(getValueIsAdjusting());
|
||||
}
|
||||
if (delay > 0) {
|
||||
myInterpolator.setTarget(value, delay);
|
||||
}
|
||||
else {
|
||||
super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentValue(int value) {
|
||||
super.setValue(value);
|
||||
|
||||
myAdjuster.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetValue() {
|
||||
return myInterpolator.getTarget();
|
||||
}
|
||||
|
||||
// Support subpixel deltas
|
||||
@Override
|
||||
public void adjustValue(double delta) {
|
||||
myAdjuster.adjustValue(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
|
||||
public class RemoteDesktopDetector extends RemoteDesktopService {
|
||||
@@ -55,7 +54,6 @@ public class RemoteDesktopDetector extends RemoteDesktopService {
|
||||
LOG.debug("Detected remote desktop: ", newValue);
|
||||
if (newValue != myRemoteDesktopConnected) {
|
||||
myRemoteDesktopConnected = newValue;
|
||||
ComponentSettings.getInstance().setRemoteDesktopConnected(newValue);
|
||||
if (myRemoteDesktopConnected) {
|
||||
// We postpone notification to avoid recursive initialization of RemoteDesktopDetector
|
||||
// (in case it's initialized by request from com.intellij.notification.EventLog)
|
||||
|
||||
-2
@@ -23,7 +23,6 @@ import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.ComponentSettings;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -149,7 +148,6 @@ public class EditorSettingsExternalizable implements PersistentStateComponent<Ed
|
||||
public void loadState(OptionSet state) {
|
||||
myOptions = state;
|
||||
parseRawSoftWraps();
|
||||
ComponentSettings.getInstance().setSmoothScrollingEnabled(isSmoothScrolling());
|
||||
}
|
||||
|
||||
private void parseRawSoftWraps() {
|
||||
|
||||
Reference in New Issue
Block a user