Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package javafx.scene.control.skin;
- import com.sun.javafx.scene.control.Properties;
- import com.sun.javafx.scene.control.behavior.ScrollBarBehavior;
- import com.sun.javafx.util.Utils;
- import java.util.function.Consumer;
- import javafx.beans.value.ObservableValue;
- import javafx.geometry.Orientation;
- import javafx.geometry.Point2D;
- import javafx.scene.AccessibleAction;
- import javafx.scene.AccessibleAttribute;
- import javafx.scene.AccessibleRole;
- import javafx.scene.Node;
- import javafx.scene.control.ScrollBar;
- import javafx.scene.control.SkinBase;
- import javafx.scene.input.MouseButton;
- import javafx.scene.input.ScrollEvent;
- import javafx.scene.layout.Region;
- import javafx.scene.layout.StackPane;
- public class ScrollBarSkin extends SkinBase<ScrollBar> {
- private final ScrollBarBehavior behavior;
- private StackPane thumb;
- private StackPane trackBackground;
- private StackPane track;
- private ScrollBarSkin.EndButton incButton;
- private ScrollBarSkin.EndButton decButton;
- private double trackLength;
- private double thumbLength;
- private double preDragThumbPos;
- private Point2D dragStart;
- private double trackPos;
- public ScrollBarSkin(ScrollBar control) {
- super(control);
- this.behavior = new ScrollBarBehavior(control);
- this.initialize();
- ((ScrollBar)this.getSkinnable()).requestLayout();
- Consumer<ObservableValue<?>> consumer = (e) -> {
- this.positionThumb();
- ((ScrollBar)this.getSkinnable()).requestLayout();
- };
- this.registerChangeListener(control.minProperty(), consumer);
- this.registerChangeListener(control.maxProperty(), consumer);
- this.registerChangeListener(control.visibleAmountProperty(), consumer);
- this.registerChangeListener(control.valueProperty(), (e) -> {
- this.positionThumb();
- });
- this.registerChangeListener(control.orientationProperty(), (e) -> {
- ((ScrollBar)this.getSkinnable()).requestLayout();
- });
- }
- public void dispose() {
- super.dispose();
- if (this.behavior != null) {
- this.behavior.dispose();
- }
- }
- protected void layoutChildren(double x, double y, double w, double h) {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- double visiblePortion;
- if (s.getMax() > s.getMin()) {
- visiblePortion = s.getVisibleAmount() / (s.getMax() - s.getMin());
- } else {
- visiblePortion = 1.0D;
- }
- double decHeight;
- double incHeight;
- if (s.getOrientation() == Orientation.VERTICAL) {
- if (!Properties.IS_TOUCH_SUPPORTED) {
- decHeight = this.snapSizeY(this.decButton.prefHeight(-1.0D));
- incHeight = this.snapSizeY(this.incButton.prefHeight(-1.0D));
- this.decButton.resize(w, decHeight);
- this.incButton.resize(w, incHeight);
- this.trackLength = this.snapSizeY(h - (decHeight + incHeight));
- this.thumbLength = this.snapSizeY(Utils.clamp(this.minThumbLength(), this.trackLength * visiblePortion, this.trackLength));
- this.trackBackground.resizeRelocate(this.snapPositionX(x), this.snapPositionY(y), w, this.trackLength + decHeight + incHeight);
- this.decButton.relocate(this.snapPositionX(x), this.snapPositionY(y));
- this.incButton.relocate(this.snapPositionX(x), this.snapPositionY(y + h - incHeight));
- this.track.resizeRelocate(this.snapPositionX(x), this.snapPositionY(y + decHeight), w, this.trackLength);
- this.thumb.resize(this.snapSizeX(x >= 0.0D ? w : w + x), this.thumbLength);
- this.positionThumb();
- } else {
- this.trackLength = this.snapSizeY(h);
- this.thumbLength = this.snapSizeY(Utils.clamp(this.minThumbLength(), this.trackLength * visiblePortion, this.trackLength));
- this.track.resizeRelocate(this.snapPositionX(x), this.snapPositionY(y), w, this.trackLength);
- this.thumb.resize(this.snapSizeX(x >= 0.0D ? w : w + x), this.thumbLength);
- this.positionThumb();
- }
- } else {
- if (!Properties.IS_TOUCH_SUPPORTED) {
- decHeight = this.snapSizeX(this.decButton.prefWidth(-1.0D));
- incHeight = this.snapSizeX(this.incButton.prefWidth(-1.0D));
- this.decButton.resize(decHeight, h);
- this.incButton.resize(incHeight, h);
- this.trackLength = this.snapSizeX(w - (decHeight + incHeight));
- this.thumbLength = this.snapSizeX(Utils.clamp(this.minThumbLength(), this.trackLength * visiblePortion, this.trackLength));
- this.trackBackground.resizeRelocate(this.snapPositionX(x), this.snapPositionY(y), this.trackLength + decHeight + incHeight, h);
- this.decButton.relocate(this.snapPositionX(x), this.snapPositionY(y));
- this.incButton.relocate(this.snapPositionX(x + w - incHeight), this.snapPositionY(y));
- this.track.resizeRelocate(this.snapPositionX(x + decHeight), this.snapPositionY(y), this.trackLength, h);
- this.thumb.resize(this.thumbLength, this.snapSizeY(y >= 0.0D ? h : h + y));
- this.positionThumb();
- } else {
- this.trackLength = this.snapSizeX(w);
- this.thumbLength = this.snapSizeX(Utils.clamp(this.minThumbLength(), this.trackLength * visiblePortion, this.trackLength));
- this.track.resizeRelocate(this.snapPositionX(x), this.snapPositionY(y), this.trackLength, h);
- this.thumb.resize(this.thumbLength, this.snapSizeY(y >= 0.0D ? h : h + y));
- this.positionThumb();
- }
- s.resize(this.snapSizeX(s.getWidth()), this.snapSizeY(s.getHeight()));
- }
- if (s.getOrientation() == Orientation.VERTICAL && h >= this.computeMinHeight(-1.0D, (double)((int)y), this.snappedRightInset(), this.snappedBottomInset(), (double)((int)x)) - (y + this.snappedBottomInset()) || s.getOrientation() == Orientation.HORIZONTAL && w >= this.computeMinWidth(-1.0D, (double)((int)y), this.snappedRightInset(), this.snappedBottomInset(), (double)((int)x)) - (x + this.snappedRightInset())) {
- this.trackBackground.setVisible(true);
- this.track.setVisible(true);
- this.thumb.setVisible(true);
- if (!Properties.IS_TOUCH_SUPPORTED) {
- this.incButton.setVisible(true);
- this.decButton.setVisible(true);
- }
- } else {
- this.trackBackground.setVisible(false);
- this.track.setVisible(false);
- this.thumb.setVisible(false);
- if (!Properties.IS_TOUCH_SUPPORTED) {
- if (h >= this.decButton.computeMinWidth(-1.0D)) {
- this.decButton.setVisible(true);
- } else {
- this.decButton.setVisible(false);
- }
- if (h >= this.incButton.computeMinWidth(-1.0D)) {
- this.incButton.setVisible(true);
- } else {
- this.incButton.setVisible(false);
- }
- }
- }
- }
- protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
- if (((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL) {
- return this.getBreadth();
- } else {
- return !Properties.IS_TOUCH_SUPPORTED ? this.decButton.minWidth(-1.0D) + this.incButton.minWidth(-1.0D) + this.minTrackLength() + leftInset + rightInset : this.minTrackLength() + leftInset + rightInset;
- }
- }
- protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
- if (((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL) {
- return !Properties.IS_TOUCH_SUPPORTED ? this.decButton.minHeight(-1.0D) + this.incButton.minHeight(-1.0D) + this.minTrackLength() + topInset + bottomInset : this.minTrackLength() + topInset + bottomInset;
- } else {
- return this.getBreadth();
- }
- }
- protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- return s.getOrientation() == Orientation.VERTICAL ? this.getBreadth() : 100.0D + leftInset + rightInset;
- }
- protected double computePrefHeight(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- return s.getOrientation() == Orientation.VERTICAL ? 100.0D + topInset + bottomInset : this.getBreadth();
- }
- protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- return s.getOrientation() == Orientation.VERTICAL ? s.prefWidth(-1.0D) : 1.7976931348623157E308D;
- }
- protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- return s.getOrientation() == Orientation.VERTICAL ? 1.7976931348623157E308D : s.prefHeight(-1.0D);
- }
- private void initialize() {
- this.track = new StackPane();
- this.track.getStyleClass().setAll(new String[]{"track"});
- this.trackBackground = new StackPane();
- this.trackBackground.getStyleClass().setAll(new String[]{"track-background"});
- this.thumb = new StackPane() {
- public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
- switch(attribute) {
- case VALUE:
- return ((ScrollBar)ScrollBarSkin.this.getSkinnable()).getValue();
- default:
- return super.queryAccessibleAttribute(attribute, parameters);
- }
- }
- };
- this.thumb.getStyleClass().setAll(new String[]{"thumb"});
- this.thumb.setAccessibleRole(AccessibleRole.THUMB);
- if (!Properties.IS_TOUCH_SUPPORTED) {
- this.incButton = new ScrollBarSkin.EndButton("increment-button", "increment-arrow") {
- public void executeAccessibleAction(AccessibleAction action, Object... parameters) {
- switch(action) {
- case FIRE:
- ((ScrollBar)ScrollBarSkin.this.getSkinnable()).increment();
- break;
- default:
- super.executeAccessibleAction(action, parameters);
- }
- }
- };
- this.incButton.setAccessibleRole(AccessibleRole.INCREMENT_BUTTON);
- this.incButton.setOnMousePressed((me) -> {
- if (!this.thumb.isVisible() || this.trackLength > this.thumbLength) {
- this.behavior.incButtonPressed();
- }
- me.consume();
- });
- this.incButton.setOnMouseReleased((me) -> {
- if (!this.thumb.isVisible() || this.trackLength > this.thumbLength) {
- this.behavior.incButtonReleased();
- }
- me.consume();
- });
- this.decButton = new ScrollBarSkin.EndButton("decrement-button", "decrement-arrow") {
- public void executeAccessibleAction(AccessibleAction action, Object... parameters) {
- switch(action) {
- case FIRE:
- ((ScrollBar)ScrollBarSkin.this.getSkinnable()).decrement();
- break;
- default:
- super.executeAccessibleAction(action, parameters);
- }
- }
- };
- this.decButton.setAccessibleRole(AccessibleRole.DECREMENT_BUTTON);
- this.decButton.setOnMousePressed((me) -> {
- if (!this.thumb.isVisible() || this.trackLength > this.thumbLength) {
- this.behavior.decButtonPressed();
- }
- me.consume();
- });
- this.decButton.setOnMouseReleased((me) -> {
- if (!this.thumb.isVisible() || this.trackLength > this.thumbLength) {
- this.behavior.decButtonReleased();
- }
- me.consume();
- });
- }
- this.track.setOnMousePressed((me) -> {
- if (!this.thumb.isPressed() && me.getButton() == MouseButton.PRIMARY) {
- if (((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL) {
- if (this.trackLength != 0.0D) {
- this.behavior.trackPress(me.getY() / this.trackLength);
- me.consume();
- }
- } else if (this.trackLength != 0.0D) {
- this.behavior.trackPress(me.getX() / this.trackLength);
- me.consume();
- }
- }
- });
- this.track.setOnMouseReleased((me) -> {
- this.behavior.trackRelease();
- me.consume();
- });
- this.thumb.setOnMousePressed((me) -> {
- if (me.isSynthesized()) {
- me.consume();
- } else {
- if (((ScrollBar)this.getSkinnable()).getMax() > ((ScrollBar)this.getSkinnable()).getMin()) {
- this.dragStart = this.thumb.localToParent(me.getX(), me.getY());
- double clampedValue = Utils.clamp(((ScrollBar)this.getSkinnable()).getMin(), ((ScrollBar)this.getSkinnable()).getValue(), ((ScrollBar)this.getSkinnable()).getMax());
- this.preDragThumbPos = (clampedValue - ((ScrollBar)this.getSkinnable()).getMin()) / (((ScrollBar)this.getSkinnable()).getMax() - ((ScrollBar)this.getSkinnable()).getMin());
- me.consume();
- }
- }
- });
- this.thumb.setOnMouseDragged((me) -> {
- if (me.isSynthesized()) {
- me.consume();
- } else {
- if (((ScrollBar)this.getSkinnable()).getMax() > ((ScrollBar)this.getSkinnable()).getMin()) {
- if (this.trackLength > this.thumbLength) {
- Point2D cur = this.thumb.localToParent(me.getX(), me.getY());
- if (this.dragStart == null) {
- this.dragStart = this.thumb.localToParent(me.getX(), me.getY());
- }
- double dragPos = ((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? cur.getY() - this.dragStart.getY() : cur.getX() - this.dragStart.getX();
- this.behavior.thumbDragged(this.preDragThumbPos + dragPos / (this.trackLength - this.thumbLength));
- }
- me.consume();
- }
- }
- });
- this.thumb.setOnScrollStarted((se) -> {
- if (se.isDirect() && ((ScrollBar)this.getSkinnable()).getMax() > ((ScrollBar)this.getSkinnable()).getMin()) {
- this.dragStart = this.thumb.localToParent(se.getX(), se.getY());
- double clampedValue = Utils.clamp(((ScrollBar)this.getSkinnable()).getMin(), ((ScrollBar)this.getSkinnable()).getValue(), ((ScrollBar)this.getSkinnable()).getMax());
- this.preDragThumbPos = (clampedValue - ((ScrollBar)this.getSkinnable()).getMin()) / (((ScrollBar)this.getSkinnable()).getMax() - ((ScrollBar)this.getSkinnable()).getMin());
- se.consume();
- }
- });
- this.thumb.setOnScroll((event) -> {
- if (event.isDirect() && ((ScrollBar)this.getSkinnable()).getMax() > ((ScrollBar)this.getSkinnable()).getMin()) {
- if (this.trackLength > this.thumbLength) {
- Point2D cur = this.thumb.localToParent(event.getX(), event.getY());
- if (this.dragStart == null) {
- this.dragStart = this.thumb.localToParent(event.getX(), event.getY());
- }
- double dragPos = ((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? cur.getY() - this.dragStart.getY() : cur.getX() - this.dragStart.getX();
- this.behavior.thumbDragged(this.preDragThumbPos + dragPos / (this.trackLength - this.thumbLength));
- }
- event.consume();
- }
- });
- ((ScrollBar)this.getSkinnable()).addEventHandler(ScrollEvent.SCROLL, (event) -> {
- if (this.trackLength > this.thumbLength) {
- double dx = event.getDeltaX();
- double dy = event.getDeltaY();
- dx = Math.abs(dx) < Math.abs(dy) ? dy : dx;
- ScrollBar sb = (ScrollBar)this.getSkinnable();
- double delta = ((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? dy : dx;
- if (event.isDirect()) {
- if (this.trackLength > this.thumbLength) {
- this.behavior.thumbDragged((((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? event.getY() : event.getX()) / this.trackLength);
- event.consume();
- }
- } else if (delta > 0.0D && sb.getValue() > sb.getMin()) {
- sb.decrement();
- event.consume();
- } else if (delta < 0.0D && sb.getValue() < sb.getMax()) {
- sb.increment();
- event.consume();
- }
- }
- });
- this.getChildren().clear();
- if (!Properties.IS_TOUCH_SUPPORTED) {
- this.getChildren().addAll(new Node[]{this.trackBackground, this.incButton, this.decButton, this.track, this.thumb});
- } else {
- this.getChildren().addAll(new Node[]{this.track, this.thumb});
- }
- }
- double getBreadth() {
- if (!Properties.IS_TOUCH_SUPPORTED) {
- return ((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? Math.max(this.decButton.prefWidth(-1.0D), this.incButton.prefWidth(-1.0D)) + this.snappedLeftInset() + this.snappedRightInset() : Math.max(this.decButton.prefHeight(-1.0D), this.incButton.prefHeight(-1.0D)) + this.snappedTopInset() + this.snappedBottomInset();
- } else {
- return ((ScrollBar)this.getSkinnable()).getOrientation() == Orientation.VERTICAL ? Math.max(8.0D, 8.0D) + this.snappedLeftInset() + this.snappedRightInset() : Math.max(8.0D, 8.0D) + this.snappedTopInset() + this.snappedBottomInset();
- }
- }
- double minThumbLength() {
- return 1.5D * this.getBreadth();
- }
- double minTrackLength() {
- return 2.0D * this.getBreadth();
- }
- void positionThumb() {
- ScrollBar s = (ScrollBar)this.getSkinnable();
- double clampedValue = Utils.clamp(s.getMin(), s.getValue(), s.getMax());
- this.trackPos = s.getMax() - s.getMin() > 0.0D ? (this.trackLength - this.thumbLength) * (clampedValue - s.getMin()) / (s.getMax() - s.getMin()) : 0.0D;
- if (!Properties.IS_TOUCH_SUPPORTED) {
- if (s.getOrientation() == Orientation.VERTICAL) {
- this.trackPos += this.decButton.prefHeight(-1.0D);
- } else {
- this.trackPos += this.decButton.prefWidth(-1.0D);
- }
- }
- this.thumb.setTranslateX(this.snapPositionX(s.getOrientation() == Orientation.VERTICAL ? this.snappedLeftInset() : this.trackPos + this.snappedLeftInset()));
- this.thumb.setTranslateY(this.snapPositionY(s.getOrientation() == Orientation.VERTICAL ? this.trackPos + this.snappedTopInset() : this.snappedTopInset()));
- }
- private Node getThumb() {
- return this.thumb;
- }
- private Node getTrack() {
- return this.track;
- }
- private Node getIncrementButton() {
- return this.incButton;
- }
- private Node getDecrementButton() {
- return this.decButton;
- }
- private static class EndButton extends Region {
- private Region arrow;
- private EndButton(String styleClass, String arrowStyleClass) {
- this.getStyleClass().setAll(new String[]{styleClass});
- this.arrow = new Region();
- this.arrow.getStyleClass().setAll(new String[]{arrowStyleClass});
- this.getChildren().setAll(new Node[]{this.arrow});
- this.requestLayout();
- }
- protected void layoutChildren() {
- double top = this.snappedTopInset();
- double left = this.snappedLeftInset();
- double bottom = this.snappedBottomInset();
- double right = this.snappedRightInset();
- double aw = this.snapSizeX(this.arrow.prefWidth(-1.0D));
- double ah = this.snapSizeY(this.arrow.prefHeight(-1.0D));
- double yPos = this.snapPositionY((this.getHeight() - (top + bottom + ah)) / 2.0D);
- double xPos = this.snapPositionX((this.getWidth() - (left + right + aw)) / 2.0D);
- this.arrow.resizeRelocate(xPos + left, yPos + top, aw, ah);
- }
- protected double computeMinHeight(double width) {
- return this.prefHeight(-1.0D);
- }
- protected double computeMinWidth(double height) {
- return this.prefWidth(-1.0D);
- }
- protected double computePrefWidth(double height) {
- double left = this.snappedLeftInset();
- double right = this.snappedRightInset();
- double aw = this.snapSizeX(this.arrow.prefWidth(-1.0D));
- return left + aw + right;
- }
- protected double computePrefHeight(double width) {
- double top = this.snappedTopInset();
- double bottom = this.snappedBottomInset();
- double ah = this.snapSizeY(this.arrow.prefHeight(-1.0D));
- return top + ah + bottom;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement