use of javafx.animation.Timeline in project JFoenix by jfoenixadmin.
the class JFXScrollPane method smoothScrolling.
public static void smoothScrolling(ScrollPane scrollPane) {
final double[] frictions = { 0.99, 0.1, 0.05, 0.04, 0.03, 0.02, 0.01, 0.04, 0.01, 0.008, 0.008, 0.008, 0.008, 0.0006, 0.0005, 0.00003, 0.00001 };
final double[] pushes = { 1 };
final double[] derivatives = new double[frictions.length];
Timeline timeline = new Timeline();
scrollPane.getContent().addEventHandler(MouseEvent.DRAG_DETECTED, event -> timeline.stop());
scrollPane.getContent().addEventHandler(ScrollEvent.ANY, event -> {
if (event.getEventType().equals(ScrollEvent.SCROLL)) {
int direction = event.getDeltaY() > 0 ? -1 : 1;
for (int i = 0; i < pushes.length; i++) derivatives[i] += direction * pushes[i];
if (timeline.getStatus().equals(Animation.Status.STOPPED))
timeline.play();
event.consume();
}
});
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(3), (event) -> {
for (int i = 0; i < derivatives.length; i++) derivatives[i] *= frictions[i];
for (int i = 1; i < derivatives.length; i++) derivatives[i] += derivatives[i - 1];
double dy = derivatives[derivatives.length - 1];
double height = scrollPane.getContent().getLayoutBounds().getHeight();
scrollPane.setVvalue(Math.min(Math.max(scrollPane.getVvalue() + dy / height, 0), 1));
if (Math.abs(dy) < 0.001)
timeline.stop();
}));
timeline.setCycleCount(Animation.INDEFINITE);
}
use of javafx.animation.Timeline in project JFoenix by jfoenixadmin.
the class JFXSnackbar method show.
public void show(String message, String actionText, long timeout, EventHandler<? super MouseEvent> actionHandler) {
toast.setText(message);
if (actionText != null && !actionText.isEmpty()) {
action.setVisible(true);
actionContainer.setVisible(true);
actionContainer.setManaged(true);
// to force updating the layout bounds
action.setText("");
action.setText(actionText);
action.setOnMouseClicked(actionHandler);
} else {
actionContainer.setVisible(false);
actionContainer.setManaged(false);
action.setVisible(false);
}
Timeline animation = getTimeline(timeout);
animation.play();
}
use of javafx.animation.Timeline in project JFoenix by jfoenixadmin.
the class JFXRadioButtonSkin method updateAnimation.
private void updateAnimation() {
Color unSelectedColor = ((JFXRadioButton) getSkinnable()).getUnSelectedColor();
Color selectedColor = ((JFXRadioButton) getSkinnable()).getSelectedColor();
timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(dot.scaleXProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(dot.scaleYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(radio.strokeProperty(), unSelectedColor, Interpolator.EASE_BOTH)), new KeyFrame(Duration.millis(200), new KeyValue(dot.scaleXProperty(), 0.6, Interpolator.EASE_BOTH), new KeyValue(dot.scaleYProperty(), 0.6, Interpolator.EASE_BOTH), new KeyValue(radio.strokeProperty(), selectedColor, Interpolator.EASE_BOTH)));
}
use of javafx.animation.Timeline in project JFoenix by jfoenixadmin.
the class JFXSliderSkin method initAnimation.
private void initAnimation(Orientation orientation) {
double thumbPos, thumbNewPos;
DoubleProperty layoutProperty;
if (orientation == Orientation.HORIZONTAL) {
if (((JFXSlider) getSkinnable()).getIndicatorPosition() == IndicatorPosition.RIGHT) {
thumbPos = thumb.getLayoutY() - thumb.getHeight();
thumbNewPos = thumbPos - shifting;
} else {
thumbPos = thumb.getLayoutY() - animatedThumb.getHeight() / 2;
thumbNewPos = thumb.getLayoutY() - animatedThumb.getHeight() - thumb.getHeight();
}
layoutProperty = animatedThumb.translateYProperty();
} else {
if (((JFXSlider) getSkinnable()).getIndicatorPosition() == IndicatorPosition.RIGHT) {
thumbPos = thumb.getLayoutX() - thumb.getWidth();
thumbNewPos = thumbPos - shifting;
} else {
thumbPos = thumb.getLayoutX() - animatedThumb.getWidth() / 2;
thumbNewPos = thumb.getLayoutX() - animatedThumb.getWidth() - thumb.getWidth();
}
layoutProperty = animatedThumb.translateXProperty();
}
timeline = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(animatedThumb.scaleXProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(animatedThumb.scaleYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(layoutProperty, thumbPos, Interpolator.EASE_BOTH)), new KeyFrame(Duration.seconds(0.2), new KeyValue(animatedThumb.scaleXProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(animatedThumb.scaleYProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(layoutProperty, thumbNewPos, Interpolator.EASE_BOTH)));
}
use of javafx.animation.Timeline in project JFoenix by jfoenixadmin.
the class JFXTabPaneSkin method layoutChildren.
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
double headerHeight = snapSize(headerContainer.prefHeight(-1));
headerContainer.resize(w, headerHeight);
headerContainer.relocate(x, y);
headerContainerClip.setX(0);
headerContainerClip.setY(0);
headerContainerClip.setWidth(w);
// 10 is the height of the shadow effect
headerContainerClip.setHeight(headerHeight + 10);
// position the tab content for the selected tab only
double contentStartX = 0;
double contentStartY = 0;
contentStartX = x;
contentStartY = y + headerHeight;
double contentWidth = w - (0);
double contentHeight = h - (headerHeight);
Rectangle clip = new Rectangle(contentWidth, contentHeight);
tabsContainerHolder.setClip(clip);
tabsContainerHolder.resize(contentWidth, contentHeight);
tabsContainerHolder.relocate(contentStartX, contentStartY);
tabsContainer.resize(contentWidth * tabContentHolders.size(), contentHeight);
for (int i = 0, max = tabContentHolders.size(); i < max; i++) {
TabContentHolder tabContentHolder = tabContentHolders.get(i);
tabContentHolder.setVisible(true);
tabContentHolder.setTranslateX(contentWidth * i);
if (tabContentHolder.getClip() != null) {
((Rectangle) tabContentHolder.getClip()).setWidth(contentWidth);
((Rectangle) tabContentHolder.getClip()).setHeight(contentHeight);
}
if (tabContentHolder.tab == selectedTab) {
int index = getSkinnable().getTabs().indexOf(selectedTab);
if (index != i) {
tabsContainer.setTranslateX(-contentWidth * i);
diffTabsIndices = i - index;
} else {
// fix X translation after changing the tabs
if (diffTabsIndices != 0) {
tabsContainer.setTranslateX(tabsContainer.getTranslateX() + contentWidth * diffTabsIndices);
diffTabsIndices = 0;
}
// animate upon tab selection only otherwise just translate the selected tab
if (isSelectingTab) {
new CachedTransition(tabsContainer, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(tabsContainer.translateXProperty(), -contentWidth * index, Interpolator.EASE_BOTH)))) {
{
setCycleDuration(Duration.seconds(0.320));
setDelay(Duration.seconds(0));
}
}.play();
} else
tabsContainer.setTranslateX(-contentWidth * index);
}
}
tabContentHolder.resize(contentWidth, contentHeight);
}
}
Aggregations