package com.jclarity.region.fx;

import javafx.scene.control.ProgressBar;
import javafx.scene.control.SkinBase;
import javafx.scene.control.Slider;


public class TimeSliderSkin extends SkinBase<TimeSlider> {

    final private Slider slider;
    final private ProgressBar progressBar;
    private double frameCount = 1.0;

    protected TimeSliderSkin(TimeSlider control) {
        super(control);

        slider = control.getSlider();
        slider.setMinWidth(control.getMinWidth());
        slider.setMaxWidth(control.getMaxWidth());

        progressBar = control.getProgressBar();
        progressBar.setMinWidth(control.getMinWidth());
        progressBar.setMaxWidth(control.getMaxWidth());

        slider.valueProperty().addListener((observable, oldValue, newValue) -> progressBar.setProgress(newValue.doubleValue() / control.getMax()));

        getChildren().addAll(progressBar,slider);
    }

    public void setFrameCount( int frameCount) {
        this.frameCount = (double) frameCount;
    }

    @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
        slider.minWidth(height);
        return progressBar.minWidth(height);
    }

    @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
        slider.minHeight(width);
        return progressBar.minHeight(width);
    }

    @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
        slider.prefWidth(height);
        return progressBar.prefWidth(height) + leftInset + rightInset;
    }

    @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
        slider.prefHeight(width);
        return progressBar.prefHeight(width) + topInset + bottomInset;
    }

    @Override protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
        return computePrefWidth(height, topInset, rightInset, bottomInset, leftInset);
    }

    @Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
        return computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
    }

    @Override protected void layoutChildren( double x, double y, double w, double h) {
        slider.resizeRelocate(x,y,w,h);
        progressBar.resizeRelocate(x,y,w,h);
    }

    void moveTo(double value) {
        progressBar.setProgress(value);
    }
}

@@ -282,45 +282,8 @@
 Bar;
-%0A    private double frameCount = 1.0;
 %0A%0A  
@@ -868,111 +868,8 @@
  %7D%0A%0A
-    public void setFrameCount( int frameCount) %7B%0A        this.frameCount = (double) frameCount;%0A    %7D%0A%0A
     
@@ -2457,86 +2457,7 @@
    %7D
-%0A%0A    void moveTo(double value) %7B%0A        progressBar.setProgress(value);%0A    %7D
 %0A%7D%0A

delete unused methods/variables