<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui.components;

import com.intellij.ui.ComponentUtil;
import com.intellij.ui.components.JBScrollPane.Alignment;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.MathUtil;
import com.intellij.util.ui.*;
import consulo.util.dataholder.Key;

import javax.swing.Timer;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ScrollBarUI;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import static java.awt.Adjustable.VERTICAL;

class DefaultScrollBarUI extends ScrollBarUI {
  static final Key<Component> LEADING = Key.create("JB_SCROLL_BAR_LEADING_COMPONENT");
  static final Key<Component> TRAILING = Key.create("JB_SCROLL_BAR_TRAILING_COMPONENT");

  private final Listener myListener = new Listener();
  private final Timer myScrollTimer = TimerUtil.createNamedTimer("ScrollBarThumbScrollTimer", 60, myListener);

  private final int myThickness;
  private final int myThicknessMax;
  private final int myThicknessMin;

  JScrollBar myScrollBar;

  final ScrollBarPainter.Track myTrack = new ScrollBarPainter.Track(() -> myScrollBar);
  final ScrollBarPainter.Thumb myThumb = new ScrollBarPainter.Thumb(() -> myScrollBar, false);

  private boolean isValueCached;
  private int myCachedValue;
  private int myOldValue;

  DefaultScrollBarUI() {
    this(12, 12, 12);
  }

  DefaultScrollBarUI(int thickness, int thicknessMax, int thicknessMin) {
    myThickness = thickness;
    myThicknessMax = thicknessMax;
    myThicknessMin = thicknessMin;
  }

  int getThickness() {
    return scale(myScrollBar == null || isOpaque(myScrollBar) ? myThickness : myThicknessMax);
  }

  int getMinimalThickness() {
    return scale(myScrollBar == null || isOpaque(myScrollBar) ? myThickness : myThicknessMin);
  }

  static boolean isOpaque(Component c) {
    if (c.isOpaque()) return true;
    Container parent = c.getParent();
    // do not allow non-opaque scroll bars, because default layout does not support them
    return parent instanceof JScrollPane && parent.getLayout() instanceof ScrollPaneLayout.UIResource;
  }

  boolean isAbsolutePositioning(MouseEvent event) {
    return SwingUtilities.isMiddleMouseButton(event);
  }

  boolean isTrackClickable() {
    return isOpaque(myScrollBar) || myTrack.animator.myValue > 0;
  }

  boolean isTrackExpandable() {
    return false;
  }

  boolean isTrackContains(int x, int y) {
    return myTrack.bounds.contains(x, y);
  }

  boolean isThumbContains(int x, int y) {
    return myThumb.bounds.contains(x, y);
  }

  void onTrackHover(boolean hover) {
    myTrack.animator.start(hover);
  }

  void onThumbHover(boolean hover) {
    myThumb.animator.start(hover);
  }

  void paintTrack(Graphics2D g, JComponent c) {
    paint(myTrack, g, c, false);
  }

  void paintThumb(Graphics2D g, JComponent c) {
    paint(myThumb, g, c, ScrollSettings.isThumbSmallIfOpaque() && isOpaque(c));
  }

  void onThumbMove() {
  }

  void paint(ScrollBarPainter p, Graphics2D g, JComponent c, boolean small) {
    int x = p.bounds.x;
    int y = p.bounds.y;
    int width = p.bounds.width;
    int height = p.bounds.height;

    Alignment alignment = Alignment.get(c);
    if (alignment == Alignment.LEFT || alignment == Alignment.RIGHT) {
      int offset = getTrackOffset(width - getMinimalThickness());
      if (offset > 0) {
        width -= offset;
        if (alignment == Alignment.RIGHT) x += offset;
      }
    }
    else {
      int offset = getTrackOffset(height - getMinimalThickness());
      if (offset > 0) {
        height -= offset;
        if (alignment == Alignment.BOTTOM) y += offset;
      }
    }
    if (small) {
      x += 1;
      y += 1;
      width -= 2;
      height -= 2;
    }
    p.paint(g, x, y, width, height, p.animator.myValue);
  }

  private int getTrackOffset(int offset) {
    if (!isTrackExpandable()) return offset;
    float value = myTrack.animator.myValue;
    if (value <= 0) return offset;
    if (value >= 1) return 0;
    return (int)(.5f + offset * (1 - value));<commit_msg>disable small scroll for mac<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui.components;

import com.intellij.ui.ComponentUtil;
import com.intellij.ui.components.JBScrollPane.Alignment;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.MathUtil;
import com.intellij.util.ui.*;
import consulo.util.dataholder.Key;

import javax.swing.Timer;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ScrollBarUI;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import static java.awt.Adjustable.VERTICAL;

class DefaultScrollBarUI extends ScrollBarUI {
  static final Key<Component> LEADING = Key.create("JB_SCROLL_BAR_LEADING_COMPONENT");
  static final Key<Component> TRAILING = Key.create("JB_SCROLL_BAR_TRAILING_COMPONENT");

  private final Listener myListener = new Listener();
  private final Timer myScrollTimer = TimerUtil.createNamedTimer("ScrollBarThumbScrollTimer", 60, myListener);

  private final int myThickness;
  private final int myThicknessMax;
  private final int myThicknessMin;

  JScrollBar myScrollBar;

  final ScrollBarPainter.Track myTrack = new ScrollBarPainter.Track(() -> myScrollBar);
  final ScrollBarPainter.Thumb myThumb = new ScrollBarPainter.Thumb(() -> myScrollBar, false);

  private boolean isValueCached;
  private int myCachedValue;
  private int myOldValue;

  DefaultScrollBarUI() {
    this(12, 12, 12);
  }

  DefaultScrollBarUI(int thickness, int thicknessMax, int thicknessMin) {
    myThickness = thickness;
    myThicknessMax = thicknessMax;
    myThicknessMin = thicknessMin;
  }

  int getThickness() {
    return scale(myScrollBar == null || isOpaque(myScrollBar) ? myThickness : myThicknessMax);
  }

  int getMinimalThickness() {
    return scale(myScrollBar == null || isOpaque(myScrollBar) ? myThickness : myThicknessMin);
  }

  static boolean isOpaque(Component c) {
    if (c.isOpaque()) return true;
    Container parent = c.getParent();
    // do not allow non-opaque scroll bars, because default layout does not support them
    return parent instanceof JScrollPane && parent.getLayout() instanceof ScrollPaneLayout.UIResource;
  }

  boolean isAbsolutePositioning(MouseEvent event) {
    return SwingUtilities.isMiddleMouseButton(event);
  }

  boolean isTrackClickable() {
    return isOpaque(myScrollBar) || myTrack.animator.myValue > 0;
  }

  boolean isTrackExpandable() {
    return false;
  }

  boolean isTrackContains(int x, int y) {
    return myTrack.bounds.contains(x, y);
  }

  boolean isThumbContains(int x, int y) {
    return myThumb.bounds.contains(x, y);
  }

  void onTrackHover(boolean hover) {
    myTrack.animator.start(hover);
  }

  void onThumbHover(boolean hover) {
    myThumb.animator.start(hover);
  }

  void paintTrack(Graphics2D g, JComponent c) {
    paint(myTrack, g, c, false);
  }

  void paintThumb(Graphics2D g, JComponent c) {
    paint(myThumb, g, c, ScrollSettings.isThumbSmallIfOpaque() && isOpaque(c));
  }

  void onThumbMove() {
  }

  void paint(ScrollBarPainter p, Graphics2D g, JComponent c, boolean small) {
    int x = p.bounds.x;
    int y = p.bounds.y;
    int width = p.bounds.width;
    int height = p.bounds.height;

    Alignment alignment = Alignment.get(c);
    if (alignment == Alignment.LEFT || alignment == Alignment.RIGHT) {
      int offset = getTrackOffset(width - getMinimalThickness());
      if (offset > 0) {
        width -= offset;
        if (alignment == Alignment.RIGHT) x += offset;
      }
    }
    else {
      int offset = getTrackOffset(height - getMinimalThickness());
      if (offset > 0) {
        height -= offset;
        if (alignment == Alignment.BOTTOM) y += offset;
      }
    }
    //if (small) {
    //  x += 1;
    //  y += 1;
    //  width -= 2;
    //  height -= 2;
    //}
    p.paint(g, x, y, width, height, p.animator.myValue);
  }

  private int getTrackOffset(int offset) {
    if (!isTrackExpandable()) return offset;
    float value = myTrack.animator.myValue;
    if (value <= 0) return offset;
    if (value >= 1) return 0;
    return (int)(.5f + offset * (1 - value));
{'fraction_non_alphanumeric': 0.10947466079090803, 'fraction_numerical': 0.007653948741737214, 'mean_word_length': 3.689505165851006, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400549', 'n_tokens_mistral': 2923, 'n_tokens_neox': 2746, 'n_words': 695}