Search in sources :

Example 36 with Timeline

use of javafx.animation.Timeline in project trex-stateless-gui by cisco-system-traffic-generator.

the class TrexApp method speedupTooltip.

/**
     * Speeding up displaying tootlip for JDK 8 ref:
     * http://stackoverflow.com/questions/26854301/control-javafx-tooltip-delay
     */
private void speedupTooltip() {
    try {
        Tooltip tooltip = new Tooltip();
        Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
        fieldBehavior.setAccessible(true);
        Object objBehavior = fieldBehavior.get(tooltip);
        Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
        fieldTimer.setAccessible(true);
        Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
        objTimer.getKeyFrames().clear();
        objTimer.getKeyFrames().add(new KeyFrame(new Duration(250)));
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        LOG.error(e);
    }
}
Also used : Field(java.lang.reflect.Field) Timeline(javafx.animation.Timeline) Tooltip(javafx.scene.control.Tooltip) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration)

Example 37 with Timeline

use of javafx.animation.Timeline in project Gargoyle by callakrsos.

the class DockTabPaneSkin method removeTabs.

private void removeTabs(List<? extends DockTab> removedList) {
    for (final DockTab tab : removedList) {
        stopCurrentAnimation(tab);
        // Animate the tab removal
        final TabHeaderSkin tabRegion = tabHeaderArea.getTabHeaderSkin(tab);
        if (tabRegion != null) {
            tabRegion.isClosing = true;
            tabRegion.removeListeners(tab);
            removeTabContent(tab);
            // remove the menu item from the popup menu
            ContextMenu popupMenu = tabHeaderArea.controlButtons.popup;
            TabMenuItem tabItem = null;
            if (popupMenu != null) {
                for (MenuItem item : popupMenu.getItems()) {
                    tabItem = (TabMenuItem) item;
                    if (tab == tabItem.getTab()) {
                        break;
                    }
                    tabItem = null;
                }
            }
            if (tabItem != null) {
                tabItem.dispose();
                popupMenu.getItems().remove(tabItem);
            }
            // end of removing menu item
            EventHandler<ActionEvent> cleanup = ae -> {
                tabRegion.animationState = TabAnimationState.NONE;
                tabHeaderArea.removeTab(tab);
                tabHeaderArea.requestLayout();
                if (getSkinnable().getTabs().isEmpty()) {
                    tabHeaderArea.setVisible(false);
                }
            };
            if (closeTabAnimation.get() == TabAnimation.GROW) {
                tabRegion.animationState = TabAnimationState.HIDING;
                Timeline closedTabTimeline = tabRegion.currentAnimation = createTimeline(tabRegion, Duration.millis(ANIMATION_SPEED), 0.0F, cleanup);
                closedTabTimeline.play();
            } else {
                cleanup.handle(null);
            }
        }
    }
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) PseudoClass(javafx.css.PseudoClass) Rotate(javafx.scene.transform.Rotate) EnumConverter(com.sun.javafx.css.converters.EnumConverter) LoggerFactory(org.slf4j.LoggerFactory) StackPane(javafx.scene.layout.StackPane) Side(javafx.geometry.Side) InvalidationListener(javafx.beans.InvalidationListener) TabPane(javafx.scene.control.TabPane) ListChangeListener(javafx.collections.ListChangeListener) ContextMenu(javafx.scene.control.ContextMenu) BehaviorSkinBase(com.sun.javafx.scene.control.skin.BehaviorSkinBase) ControlResources.getString(com.sun.javafx.scene.control.skin.resources.ControlResources.getString) DockPos(com.kyj.fx.voeditor.visual.component.dock.pane.DockPos) DockPane(com.kyj.fx.voeditor.visual.component.dock.pane.DockPane) Point2D(javafx.geometry.Point2D) Pane(javafx.scene.layout.Pane) MultiplePropertyChangeListenerHandler(com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler) MenuItem(javafx.scene.control.MenuItem) AccessibleAttribute(javafx.scene.AccessibleAttribute) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) DockEvent(com.kyj.fx.voeditor.visual.component.dock.pane.DockEvent) CssMetaData(javafx.css.CssMetaData) Timeline(javafx.animation.Timeline) Rectangle(javafx.scene.shape.Rectangle) TraversalEngine(com.sun.javafx.scene.traversal.TraversalEngine) Observable(javafx.beans.Observable) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) WeakInvalidationListener(javafx.beans.WeakInvalidationListener) List(java.util.List) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) WeakListChangeListener(javafx.collections.WeakListChangeListener) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) AccessibleRole(javafx.scene.AccessibleRole) Styleable(javafx.css.Styleable) Bounds(javafx.geometry.Bounds) SkinBase(javafx.scene.control.SkinBase) RadioMenuItem(javafx.scene.control.RadioMenuItem) MouseButton(javafx.scene.input.MouseButton) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) SwipeEvent(javafx.scene.input.SwipeEvent) ArrayList(java.util.ArrayList) TabClosingPolicy(javafx.scene.control.TabPane.TabClosingPolicy) VPos(javafx.geometry.VPos) AccessibleAction(javafx.scene.AccessibleAction) Direction(com.sun.javafx.scene.traversal.Direction) StyleableProperty(javafx.css.StyleableProperty) KeyValue(javafx.animation.KeyValue) Animation(javafx.animation.Animation) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Iterator(java.util.Iterator) Node(javafx.scene.Node) ScrollEvent(javafx.scene.input.ScrollEvent) DropShadow(javafx.scene.effect.DropShadow) ContextMenuEvent(javafx.scene.input.ContextMenuEvent) Popup(javafx.stage.Popup) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) StyleableObjectProperty(javafx.css.StyleableObjectProperty) Utils(com.sun.javafx.util.Utils) ImageView(javafx.scene.image.ImageView) WritableValue(javafx.beans.value.WritableValue) Collections(java.util.Collections) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) RadioMenuItem(javafx.scene.control.RadioMenuItem)

Example 38 with Timeline

use of javafx.animation.Timeline in project Gargoyle by callakrsos.

the class DockTabPaneSkin method stopCurrentAnimation.

private void stopCurrentAnimation(DockTab tab) {
    final TabHeaderSkin tabRegion = tabHeaderArea.getTabHeaderSkin(tab);
    if (tabRegion != null) {
        // Execute the code immediately, don't wait for the animation to finish.
        Timeline timeline = tabRegion.currentAnimation;
        if (timeline != null && timeline.getStatus() == Animation.Status.RUNNING) {
            timeline.getOnFinished().handle(null);
            timeline.stop();
            tabRegion.currentAnimation = null;
        }
    }
}
Also used : Timeline(javafx.animation.Timeline)

Example 39 with Timeline

use of javafx.animation.Timeline in project fx2048 by brunoborges.

the class Board method animateScore.

public void animateScore() {
    if (gameMovePoints.get() == 0) {
        return;
    }
    final Timeline timeline = new Timeline();
    lblPoints.setText("+" + gameMovePoints.getValue().toString());
    lblPoints.setOpacity(1);
    double posX = vScore.localToScene(vScore.getWidth() / 2d, 0).getX();
    lblPoints.setTranslateX(0);
    lblPoints.setTranslateX(lblPoints.sceneToLocal(posX, 0).getX() - lblPoints.getWidth() / 2d);
    lblPoints.setLayoutY(20);
    final KeyValue kvO = new KeyValue(lblPoints.opacityProperty(), 0);
    final KeyValue kvY = new KeyValue(lblPoints.layoutYProperty(), 100);
    Duration animationDuration = Duration.millis(600);
    final KeyFrame kfO = new KeyFrame(animationDuration, kvO);
    final KeyFrame kfY = new KeyFrame(animationDuration, kvY);
    timeline.getKeyFrames().add(kfO);
    timeline.getKeyFrames().add(kfY);
    timeline.play();
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration)

Example 40 with Timeline

use of javafx.animation.Timeline in project fx2048 by brunoborges.

the class Board method createScore.

private void createScore() {
    Label lblTitle = new Label("2048");
    lblTitle.getStyleClass().addAll("game-label", "game-title");
    Label lblSubtitle = new Label("FX");
    lblSubtitle.getStyleClass().addAll("game-label", "game-subtitle");
    HBox hFill = new HBox();
    HBox.setHgrow(hFill, Priority.ALWAYS);
    hFill.setAlignment(Pos.CENTER);
    VBox vScores = new VBox();
    HBox hScores = new HBox(5);
    vScore.setAlignment(Pos.CENTER);
    vScore.getStyleClass().add("game-vbox");
    Label lblTit = new Label("SCORE");
    lblTit.getStyleClass().addAll("game-label", "game-titScore");
    lblScore.getStyleClass().addAll("game-label", "game-score");
    lblScore.textProperty().bind(gameScoreProperty.asString());
    vScore.getChildren().addAll(lblTit, lblScore);
    VBox vRecord = new VBox(-5);
    vRecord.setAlignment(Pos.CENTER);
    vRecord.getStyleClass().add("game-vbox");
    Label lblTitBest = new Label("BEST");
    lblTitBest.getStyleClass().addAll("game-label", "game-titScore");
    lblBest.getStyleClass().addAll("game-label", "game-score");
    lblBest.textProperty().bind(gameBestProperty.asString());
    vRecord.getChildren().addAll(lblTitBest, lblBest);
    hScores.getChildren().addAll(vScore, vRecord);
    VBox vFill = new VBox();
    VBox.setVgrow(vFill, Priority.ALWAYS);
    vScores.getChildren().addAll(hScores, vFill);
    hTop.getChildren().addAll(lblTitle, lblSubtitle, hFill, vScores);
    hTop.setMinSize(gridWidth, TOP_HEIGHT);
    hTop.setPrefSize(gridWidth, TOP_HEIGHT);
    hTop.setMaxSize(gridWidth, TOP_HEIGHT);
    vGame.getChildren().add(hTop);
    HBox hTime = new HBox();
    hTime.setMinSize(gridWidth, GAP_HEIGHT);
    hTime.setAlignment(Pos.BOTTOM_RIGHT);
    lblTime.getStyleClass().addAll("game-label", "game-time");
    lblTime.textProperty().bind(clock);
    timer = new Timeline(new KeyFrame(Duration.ZERO, e -> {
        clock.set(LocalTime.now().minusNanos(time.toNanoOfDay()).format(fmt));
    }), new KeyFrame(Duration.seconds(1)));
    timer.setCycleCount(Animation.INDEFINITE);
    hTime.getChildren().add(lblTime);
    vGame.getChildren().add(hTime);
    getChildren().add(vGame);
    lblPoints.getStyleClass().addAll("game-label", "game-points");
    lblPoints.setAlignment(Pos.CENTER);
    lblPoints.setMinWidth(100);
    getChildren().add(lblPoints);
}
Also used : HBox(javafx.scene.layout.HBox) Timeline(javafx.animation.Timeline) Label(javafx.scene.control.Label) KeyFrame(javafx.animation.KeyFrame) VBox(javafx.scene.layout.VBox)

Aggregations

Timeline (javafx.animation.Timeline)111 KeyFrame (javafx.animation.KeyFrame)107 KeyValue (javafx.animation.KeyValue)81 Duration (javafx.util.Duration)32 ActionEvent (javafx.event.ActionEvent)22 JFXButton (com.jfoenix.controls.JFXButton)20 IOException (java.io.IOException)19 URL (java.net.URL)19 ResourceBundle (java.util.ResourceBundle)19 FXML (javafx.fxml.FXML)19 Initializable (javafx.fxml.Initializable)18 FXMLLoader (javafx.fxml.FXMLLoader)17 Pane (javafx.scene.layout.Pane)17 AnchorPane (javafx.scene.layout.AnchorPane)16 Level (java.util.logging.Level)15 Logger (java.util.logging.Logger)15 MouseEvent (javafx.scene.input.MouseEvent)14 Rotate (javafx.scene.transform.Rotate)14 JFXTextField (com.jfoenix.controls.JFXTextField)12 Interpolator (javafx.animation.Interpolator)12