List of usage examples for javafx.util Duration seconds
public static Duration seconds(double s)
From source file:mesclasses.view.RootLayoutController.java
private void displayNotification(int type, String texte) { notificationMessageLabel.setText(texte); notificationPane.getStyleClass().clear(); CssUtil.removeClass(deleteNotifBtn, "notif-warning"); CssUtil.removeClass(deleteNotifBtn, "notif-error"); Double timeDisplayed = 3.0D;//from w w w . j a v a 2 s . com switch (type) { case MessageEvent.SUCCESS: CssUtil.addClass(notificationPane, "notif-success"); deleteNotifBtn.setManaged(false); deleteNotifBtn.setVisible(false); notificationTitleLabel.setText("SUCCES"); break; case MessageEvent.WARNING: CssUtil.addClass(notificationPane, "notif-warning"); CssUtil.addClass(deleteNotifBtn, "notif-warning"); notificationTitleLabel.setText("ATTENTION"); break; case MessageEvent.ERROR: CssUtil.addClass(notificationPane, "notif-error"); CssUtil.addClass(deleteNotifBtn, "notif-error"); notificationTitleLabel.setText("ERREUR"); timeDisplayed = 0.0; break; } notificationPane.setManaged(true); notificationPane.setVisible(true); if (timeDisplayed > 0.0) { FadeTransition ft = new FadeTransition(Duration.millis(150), notificationPane); ft.setFromValue(0.0); ft.setToValue(1.0); ft.setCycleCount(1); ft.play(); Timeline timeline = new Timeline(); timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(timeDisplayed), (ActionEvent event) -> { FadeTransition ft2 = new FadeTransition(Duration.millis(150), notificationPane); ft2.setFromValue(1.0); ft2.setToValue(0.0); ft2.setCycleCount(1); ft2.play(); ft2.setOnFinished((ActionEvent event1) -> { notificationPane.setManaged(false); notificationPane.setVisible(false); }); })); timeline.play(); } }
From source file:hd3gtv.as5kpc.Serverchannel.java
void appInitialize(ControllerUpdater updater) { AboutServerbackgound absb = createAboutServerbackgound(); absb.setOnSucceeded((WorkerStateEvent event_absb) -> { ServerResponseAbout about = absb.getValue(); updater.updateVTRMedia(getVtrIndex(), "PROTOCOL VERSION: " + about.getVersion(), ""); if (about.isCan_record()) { updater.updateVTRStatus(getVtrIndex(), about.getOsd_name() + " #" + about.getCh_num(), about.getChannel_name(), "--:--:--:--", "Loading..."); } else {// ww w. j ava2 s .c om updater.updateVTRStatus(getVtrIndex(), about.getOsd_name() + " #" + about.getCh_num(), about.getChannel_name(), "--:--:--:--", "CAN'T RECORD"); return; } BackgroundWatcher bw = createBackgroundWatcher(); bw.setDelay(Duration.seconds(1)); bw.setOnSucceeded((WorkerStateEvent event_bw) -> { ServerResponseStatus status = bw.getValue(); String warn = ""; if (status.isRec_mode() == false) { warn = "Standby"; } else if (status.isHas_video() == false) { warn = "NO VIDEO!"; } updater.updateVTRStatus(getVtrIndex(), about.getOsd_name(), status.getControl(), status.getActual_tc(), warn); updater.updateVTRMedia(getVtrIndex(), status.getActive_name(), status.getActive_id()); }); bw.start(); }); absb.setOnFailed((WorkerStateEvent event_absb_e) -> { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Erreur"); alert.setHeaderText("Impossible de communiquer avec le serveur"); alert.setContentText("La machine " + toString() + " n'est pas joignable. Verifiez vos parametres rseau et la configuration du client et/ou du serveur."); alert.showAndWait(); System.exit(1); }); absb.start(); }
From source file:AudioPlayer3.java
private Node createControlPanel() { final HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER);/*from ww w.j a va 2 s . co m*/ hbox.setFillHeight(false); final Button playPauseButton = createPlayPauseButton(); final Button seekStartButton = new Button(); seekStartButton.setId("seekStartButton"); seekStartButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { seekAndUpdatePosition(Duration.ZERO); } }); final Button seekEndButton = new Button(); seekEndButton.setId("seekEndButton"); seekEndButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final MediaPlayer mediaPlayer = songModel.getMediaPlayer(); final Duration totalDuration = mediaPlayer.getTotalDuration(); final Duration oneSecond = Duration.seconds(1); seekAndUpdatePosition(totalDuration.subtract(oneSecond)); } }); hbox.getChildren().addAll(seekStartButton, playPauseButton, seekEndButton); return hbox; }
From source file:ubicrypt.ui.ctrl.HomeController.java
@PostConstruct public void init() { gProgress = new GeneralProgress(inProgress, inProgressMessage); treeView.setCellFactory(treeView1 -> new TreeCellFactory(treeView1, fileUntracker, appEvents, gProgress)); addProvider.setOnMouseClicked(event -> ctx.browse("selectProvider")); addFile.setOnMouseClicked(event -> { if (!localConfig.getProviders().stream().findAny().isPresent()) { ctx.browse("selectProvider"); return; }/*from w ww. ja v a2 s . c o m*/ fileAdder.accept(emptyPath); }); settings.setOnMouseClicked(event -> ctx.browse("settings")); filesRoot = new TreeItem<>(new RootFilesItem(event -> fileAdder.accept(emptyPath))); TreeItem<ITreeItem> root = new TreeItem<>(); treeView.setRoot(root); root.getChildren().add(filesRoot); treeView.setShowRoot(false); localConfig.getLocalFiles().stream().filter(Utils.ignoredFiles) .forEach(localFile -> addFiles(localFile.getPath().iterator(), basePath, filesRoot, localFile)); //providers providersRoot = new TreeItem<>(new RootProvidersItem()); root.getChildren().add(providersRoot); localConfig.getProviders().stream().forEach(providerAdder); //provider status events providerEvent.subscribe(pevent -> { switch (pevent.getEvent()) { case added: log.info("new provider added:{}", pevent.getHook().getProvider()); final Optional<TreeItem<ITreeItem>> optItem = providersRoot.getChildren().stream() .filter(item -> ((ProviderItem) item.getValue()).getProvider() .equals(pevent.getHook().getProvider())) .findFirst(); if (!optItem.isPresent()) { providerAdder.accept(pevent.getHook().getProvider()); } pevent.getHook().getStatusEvents().subscribe(event -> { Function<String, String> classLabel; log.info("provider status {}:{}", event, pevent.getHook().getProvider()); switch (event) { case error: classLabel = code -> format("tree-provider-%s-error", code); break; default: //TODO:labels for other statuses classLabel = code -> format("tree-provider-%s", code); } optItem.ifPresent(item -> { final ProviderItem providerItem = (ProviderItem) item.getValue(); final Node graphics = providerItem.getGraphics(); graphics.getStyleClass().clear(); providerDescriptors.stream() .filter(pd -> pd.getType().equals(providerItem.getProvider().getClass())) .map(ProviderDescriptor::getCode).findFirst() .ifPresent(code -> graphics.getStyleClass().add(classLabel.apply(code))); }); }); break; case removed: //TODO: remove provider break; default: log.warn("unmanaged event:{}", pevent.getEvent()); } }); //remote file events fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.remote) .subscribe(fileEvent -> { log.debug("file remote event:{}", fileEvent); //update file icon final UbiFile<UbiFile> file = fileEvent.getFile(); Observable.create(fileInSync.call(file)).subscribe(res -> { searchFile(filesRoot, file).ifPresent(treeView -> { final Node graphics = treeView.getValue().getGraphics(); graphics.getStyleClass().clear(); graphics.getStyleClass().add(format("tree-file-saved-%s", res)); }); }); }); //local file events fileEvents.filter(fileEvent -> fileEvent.getLocation() == FileEvent.Location.local && fileEvent.getType() == FileEvent.Type.created).subscribe(fileEvent -> { log.debug("file local event:{}", fileEvent); localConfig.getLocalFiles().stream().filter(fileEvent.getFile()::equals).findFirst().ifPresent( fe -> addFiles(fileEvent.getFile().getPath().iterator(), basePath, filesRoot, fe)); searchFile(filesRoot, fileEvent.getFile()).ifPresent(treeView -> { final Node graphics = treeView.getValue().getGraphics(); graphics.getStyleClass().clear(); graphics.getStyleClass().add(format("tree-file-saved-%s", true)); }); }); //file progress monitor progressEvents.subscribe(progress -> { Platform.runLater(() -> { if (progress.isCompleted()) { log.debug("progress completed"); if (!filesInProgress.remove(progress)) { log.warn("progress not tracked. progress file:{}, element:{}", progress.getProvenience().getFile()); } Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), ae -> { progressFile.setText(""); progressProvider.setText(""); progressBar.setProgress(0D); })); timeline.play(); } else { filesInProgress.add(progress); } if (filesInProgress.isEmpty()) { // footer.setVisible(false); return; } footer.setVisible(true); filesInProgress.stream().findFirst().ifPresent(pr -> { progressFile.setText(StringUtils .abbreviate(pr.getProvenience().getFile().getPath().getFileName().toString(), 30)); progressProvider.setText(StringUtils.abbreviate(pr.getTarget().toString(), 30)); progressBar.setProgress((double) progress.getChunk() / pr.getProvenience().getFile().getSize()); }); }); }); //sync-done events appEvents.subscribe(ClassMatcher.newMatcher().on(SyncBeginEvent.class, event -> { log.info("sync begin received"); Platform.runLater(() -> { gProgress.startProgress("Synchronizing providers"); addFile.setDisable(true); addProvider.setDisable(true); }); }).on(SynchDoneEvent.class, event -> { log.debug("sync done"); refreshItems(filesRoot); Platform.runLater(() -> { gProgress.stopProgress(); addFile.setDisable(false); addProvider.setDisable(false); }); })); }
From source file:eu.over9000.skadi.ui.MainWindow.java
public void doDetailSlide(final boolean doOpen) { final KeyValue positionKeyValue = new KeyValue(this.sp.getDividers().get(0).positionProperty(), doOpen ? 0.15 : 1);//from w w w.j av a 2 s . com final KeyValue opacityKeyValue = new KeyValue(this.detailPane.opacityProperty(), doOpen ? 1 : 0); final KeyFrame keyFrame = new KeyFrame(Duration.seconds(0.1), positionKeyValue, opacityKeyValue); final Timeline timeline = new Timeline(keyFrame); timeline.setOnFinished(evt -> { if (!doOpen) { MainWindow.this.sp.getItems().remove(MainWindow.this.detailPane); MainWindow.this.detailPane.setOpacity(1); } }); timeline.play(); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void setLoadingStatusText(String textToSet, boolean noAnimation) { if (!loadingStatusText.getText().equals(textToSet) && !noAnimation) { KeyValue keyValueTranslation1 = new KeyValue(loadingStatusText.translateYProperty(), -loadingStatusText.getHeight()); KeyValue keyValueOpacity1 = new KeyValue(loadingStatusText.opacityProperty(), 0); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValueOpacity1, keyValueTranslation1);//from w w w . j a v a 2 s .c om Timeline timeline1 = new Timeline(keyFrame1); timeline1.setOnFinished((event) -> { loadingStatusText.setText(textToSet); loadingStatusText.setTranslateY(loadingStatusText.getHeight()); KeyValue keyValueTranslation2 = new KeyValue(loadingStatusText.translateYProperty(), 0); KeyValue keyValueOpacity2 = new KeyValue(loadingStatusText.opacityProperty(), 1); KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed), keyValueOpacity2, keyValueTranslation2); Timeline timeline2 = new Timeline(keyFrame2); timeline2.play(); }); timeline1.play(); } else { loadingStatusText.setText(textToSet); } }
From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java
@FXML void initialize() { assert clearLogButton != null : "fx:id=\"clearLogButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTable != null : "fx:id=\"fundsTable\" was not injected: check your FXML file 'mainlayout.fxml'."; assert logField != null : "fx:id=\"logField\" was not injected: check your FXML file 'mainlayout.fxml'."; assert buyButton != null : "fx:id=\"buyButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert sellButton != null : "fx:id=\"sellButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert showActiveOrdersButton != null : "fx:id=\"showActiveOrdersButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableLastColumn != null : "fx:id=\"tickerTableLastColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTablePairColumn != null : "fx:id=\"tickerTablePairColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTable != null : "fx:id=\"tickersTable\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableBuyColumn != null : "fx:id=\"tickersTableBuyColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableFeeColumn != null : "fx:id=\"tickersTableFeeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tickersTableSellColumn != null : "fx:id=\"tickersTableSellColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradeAmountValue != null : "fx:id=\"tradeAmountValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradePriceCurrencyType != null : "fx:id=\"tradeCurrencyPriceValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradeCurrencyType != null : "fx:id=\"tradeCurrencyType\" was not injected: check your FXML file 'mainlayout.fxml'."; assert tradePriceValue != null : "fx:id=\"tradePriceValue\" was not injected: check your FXML file 'mainlayout.fxml'."; assert updateFundsButton != null : "fx:id=\"updateFundsButton\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTableCurrencyColumn != null : "fx:id=\"fundsTableCurrencyColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert fundsTableValueColumn != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTable != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersAmountColumn != null : "fx:id=\"activeOrdersAmountColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersPairColumn != null : "fx:id=\"activeOrdersPairColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersRateColumn != null : "fx:id=\"activeOrdersRateColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTimeColumn != null : "fx:id=\"activeOrdersTimeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersTypeColumn != null : "fx:id=\"activeOrdersTypeColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; assert activeOrdersCancelColumn != null : "fx:id=\"activeOrdersCancelColumn\" was not injected: check your FXML file 'mainlayout.fxml'."; //Holder for all main API methods of exchange app = new App(); //Loading configs loadExchangeConfig();//from www . jav a 2 s. c o m //Populate choiceboxes at the trading section tradeCurrencyType.setItems(FXCollections.observableArrayList(currencies)); tradeCurrencyType.setValue(currencies.get(0)); tradePriceCurrencyType.setItems(FXCollections.observableArrayList(currencies)); tradePriceCurrencyType.setValue(currencies.get(0)); //Active Orders table activeOrdersAmountColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("amount")); activeOrdersPairColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("pair")); activeOrdersRateColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("rate")); activeOrdersTimeColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ActiveOrder, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call( TableColumn.CellDataFeatures<ActiveOrder, String> activeOrderStringCellDataFeatures) { ActiveOrder activeOrder = activeOrderStringCellDataFeatures.getValue(); DateFormat dateFormat = DateFormat.getDateTimeInstance(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(activeOrder.getTimestamp() * 1000); return new SimpleStringProperty(dateFormat.format(calendar.getTime())); } }); activeOrdersTypeColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("type")); activeOrdersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); activeOrdersCancelColumn .setCellFactory(new Callback<TableColumn<ActiveOrder, Boolean>, TableCell<ActiveOrder, Boolean>>() { @Override public TableCell<ActiveOrder, Boolean> call( TableColumn<ActiveOrder, Boolean> activeOrderBooleanTableColumn) { return new ButtonCell<>(activeOrdersTable); } }); activeOrdersCancelColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ActiveOrder, Boolean>, ObservableValue<Boolean>>() { @Override public ObservableValue<Boolean> call( TableColumn.CellDataFeatures<ActiveOrder, Boolean> activeOrderBooleanCellDataFeatures) { return new SimpleBooleanProperty(true); } }); //Tickers Table MenuItem showOrdersBook = new MenuItem("Show Orders Book"); MenuItem showPublicTrades = new MenuItem("Show Public Trades"); ContextMenu contextMenu = new ContextMenu(showOrdersBook, showPublicTrades); tickersTable.setItems(tickers); tickersTable.setContextMenu(contextMenu); tickersTableBuyColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("buy")); tickersTableFeeColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("fee")); tickersTableSellColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("sell")); tickersTableLastColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("last")); tickersTablePairColumn.setCellValueFactory(new PropertyValueFactory<Ticker, String>("pair")); tickersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tickersTable.setRowFactory(new Callback<TableView<Ticker>, TableRow<Ticker>>() { @Override public TableRow<Ticker> call(TableView<Ticker> tickerTableView) { return new TableRow<Ticker>() { @Override protected void updateItem(Ticker ticker, boolean b) { super.updateItem(ticker, b); if (!b) { if (tickersData.containsKey(ticker.getPair())) { if (ticker.getLast() < tickersData.get(ticker.getPair()).getLast()) { setStyle("-fx-control-inner-background: rgba(186, 0, 0, 0.5);"); } else if (ticker.getLast() == tickersData.get(ticker.getPair()).getLast()) { setStyle("-fx-control-inner-background: rgba(215, 193, 44, 0.5);"); } else { setStyle("-fx-control-inner-background: rgba(0, 147, 0, 0.5);"); } } } } }; } }); //Menu item to show Orders Book showOrdersBook.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem(); Parent root; try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_ORDERS_BOOK_LAYOUT), resources); root = (Parent) fxmlLoader.load(); OrdersBookController ordersBookController = fxmlLoader.getController(); ordersBookController.injectPair(selectedTicker.getPair()); Stage stage = new Stage(); stage.setTitle("Orders Book for " + selectedTicker.getPair().replace("_", "/").toUpperCase()); stage.setScene(new Scene(root)); stage.setResizable(false); stage.show(); } catch (IOException e) { e.printStackTrace(); } } }); //Menu item to show Public Trades showPublicTrades.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem(); Parent root; try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_TRADES_LAYOUT), resources); root = (Parent) fxmlLoader.load(); PublicTradesController publicTradesController = fxmlLoader.getController(); publicTradesController.injectPair(selectedTicker.getPair()); Stage stage = new Stage(); stage.setTitle("Public Trades for " + selectedTicker.getPair().replace("_", "/").toUpperCase()); stage.setScene(new Scene(root)); stage.setResizable(false); stage.show(); } catch (IOException e) { e.printStackTrace(); } } }); //Funds Table fundsTableCurrencyColumn.setCellValueFactory(new PropertyValueFactory<Fund, String>("currency")); fundsTableValueColumn.setCellValueFactory(new PropertyValueFactory<Fund, Double>("value")); fundsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); fundsTable.setItems(fundsData); //Task to load tickers data from server final javafx.concurrent.Service loadTickersService = new javafx.concurrent.Service() { @Override protected Task createTask() { Task<JSONObject> loadTickers = new Task<JSONObject>() { @Override protected JSONObject call() throws Exception { String[] pairsArray = new String[pairs.size()]; pairsArray = pairs.toArray(pairsArray); return App.getPairInfo(pairsArray); } }; loadTickers.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n"); } }); loadTickers.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent workerStateEvent) { JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue(); //ugly hack to store old values //dump old values to tickersData //TODO think about better solution if (tickers.size() != 0) { for (Ticker x : tickers) { tickersData.put(x.getPair(), x); } } tickers.clear(); for (Iterator iterator = jsonObject.keys(); iterator.hasNext();) { String key = (String) iterator.next(); JSONObject data = jsonObject.getJSONObject(key); Ticker ticker = new Ticker(); ticker.setPair(key); ticker.setUpdated(data.optLong("updated")); ticker.setAvg(data.optDouble("avg")); ticker.setBuy(data.optDouble("buy")); ticker.setSell(data.optDouble("sell")); ticker.setHigh(data.optDouble("high")); ticker.setLast(data.optDouble("last")); ticker.setLow(data.optDouble("low")); ticker.setVol(data.optDouble("vol")); ticker.setVolCur(data.optDouble("vol_cur")); tickers.add(ticker); } } }); return loadTickers; } }; //Update tickers every 15 seconds //TODO better solution is required Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { loadTickersService.restart(); } }), new KeyFrame(Duration.seconds(15))); timeline.setCycleCount(Timeline.INDEFINITE); timeline.playFromStart(); }
From source file:com.github.vatbub.tictactoe.view.Main.java
private void updateAILevelLabel(boolean forceUpdate) { double sliderPos = 100 * Math.round(aiLevelSlider.getValue() * 3.0 / 100.0) / 3.0; if (sliderPos != aiLevelLabelPositionProperty.get() || forceUpdate) { aiLevelLabelPositionProperty.set(sliderPos); // request focus of the current ai label for accessibility aiLevelLabelHBox.getChildren().get((int) (sliderPos * 3 / 100)).requestFocus(); updateAccessibleTexts();/*from w w w . j av a2 s . co m*/ // get the slider position double[] xDouble = new double[] { 0, 100.0 / 3.0, 200.0 / 3.0, 300.0 / 3.0 }; double[] translationYDouble = new double[4]; double[] widthYDouble = new double[4]; double[] trueWidthYDouble = new double[4]; for (int i = 0; i < translationYDouble.length; i++) { // {-getAILevelLabelCenter(0), -getAILevelLabelCenter(1), -getAILevelLabelCenter(2), -getAILevelLabelCenter(3)}; translationYDouble[i] = -getAILevelLabelCenter(i); widthYDouble[i] = Math.max(90, ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth() + 8 * aiLevelLabelHBox.getSpacing()); trueWidthYDouble[i] = ((Label) aiLevelLabelHBox.getChildren().get(i)).getWidth(); } SplineInterpolator splineInterpolator = new SplineInterpolator(); PolynomialSplineFunction translateFunction = splineInterpolator.interpolate(xDouble, translationYDouble); PolynomialSplineFunction widthFunction = splineInterpolator.interpolate(xDouble, widthYDouble); PolynomialSplineFunction trueWidthFunction = splineInterpolator.interpolate(xDouble, trueWidthYDouble); KeyValue hBoxLayoutXKeyValue1 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), aiLevelLabelHBox.getLayoutX(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue1 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), aiLevelLabelClipRectangle.getWidth(), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue1 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelClipRectangle.getX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue1 = new KeyValue(aiLevelCenterLine.startXProperty(), aiLevelCenterLine.getStartX(), Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue1 = new KeyValue(aiLevelCenterLine.endXProperty(), aiLevelCenterLine.getEndX(), Interpolator.EASE_BOTH); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(0), hBoxLayoutXKeyValue1, aiLevelLabelClipRectangleWidthKeyValue1, aiLevelLabelClipRectangleXKeyValue1, aiLevelCenterLineStartXKeyValue1, aiLevelCenterLineEndXKeyValue1); double interpolatedLabelWidth = trueWidthFunction.value(sliderPos); KeyValue hBoxLayoutXKeyValue2 = new KeyValue(aiLevelLabelHBox.layoutXProperty(), translateFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleWidthKeyValue2 = new KeyValue( aiLevelLabelClipRectangle.widthProperty(), widthFunction.value(sliderPos), Interpolator.EASE_BOTH); KeyValue aiLevelLabelClipRectangleXKeyValue2 = new KeyValue(aiLevelLabelClipRectangle.xProperty(), aiLevelLabelPane.getWidth() / 2 - widthFunction.value(sliderPos) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineStartXKeyValue2 = new KeyValue(aiLevelCenterLine.startXProperty(), (aiLevelLabelPane.getWidth() - interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyValue aiLevelCenterLineEndXKeyValue2 = new KeyValue(aiLevelCenterLine.endXProperty(), (aiLevelLabelPane.getWidth() + interpolatedLabelWidth) / 2, Interpolator.EASE_BOTH); KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(animationSpeed * 0.9), hBoxLayoutXKeyValue2, aiLevelLabelClipRectangleWidthKeyValue2, aiLevelLabelClipRectangleXKeyValue2, aiLevelCenterLineStartXKeyValue2, aiLevelCenterLineEndXKeyValue2); Timeline timeline = new Timeline(keyFrame1, keyFrame2); timeline.play(); } }
From source file:Main.java
private void initializeBoundsPathTransition() { LOCAL_BOUNDS_PATH_TRANSITION.setDuration(Duration.seconds(2)); LOCAL_BOUNDS_PATH_TRANSITION.setNode(LOCAL_BOUNDS_PATH_CIRCLE); LOCAL_BOUNDS_PATH_TRANSITION.setOrientation(PathTransition.OrientationType.NONE); LOCAL_BOUNDS_PATH_TRANSITION.setCycleCount(Timeline.INDEFINITE); PARENT_BOUNDS_PATH_TRANSITION.setDuration(Duration.seconds(2)); PARENT_BOUNDS_PATH_TRANSITION.setNode(PARENT_BOUNDS_PATH_CIRCLE); PARENT_BOUNDS_PATH_TRANSITION.setOrientation(PathTransition.OrientationType.NONE); PARENT_BOUNDS_PATH_TRANSITION.setCycleCount(Timeline.INDEFINITE); LAYOUT_BOUNDS_PATH_TRANSITION.setDuration(Duration.seconds(2)); LAYOUT_BOUNDS_PATH_TRANSITION.setNode(LAYOUT_BOUNDS_PATH_CIRCLE); LAYOUT_BOUNDS_PATH_TRANSITION.setOrientation(PathTransition.OrientationType.NONE); LAYOUT_BOUNDS_PATH_TRANSITION.setCycleCount(Timeline.INDEFINITE); }
From source file:com.github.vatbub.tictactoe.view.Main.java
public void updateCurrentPlayerLabel(boolean noAnimation, boolean setBlockedValueAfterAnimation) { Platform.runLater(() -> stage.setTitle(getWindowTitle())); if (board.getCurrentPlayer() != null) { if (!board.getCurrentPlayer().getLetter().equals(currentPlayerLabel.getText())) { if (noAnimation) { setCurrentPlayerValue(); } else { guiAnimationQueue.submitWaitForUnlock(() -> { guiAnimationQueue.setBlocked(true); GaussianBlur blur = (GaussianBlur) currentPlayerLabel.getEffect(); if (blur == null) { blur = new GaussianBlur(0); }/* w w w. j av a 2 s . c o m*/ Calendar changeLabelTextDate = Calendar.getInstance(); changeLabelTextDate.add(Calendar.MILLISECOND, (int) (animationSpeed * 1000)); runLaterTimer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(() -> setCurrentPlayerValue()); } }, changeLabelTextDate.getTime()); currentPlayerLabel.setEffect(blur); Timeline timeline = new Timeline(); KeyValue keyValue1 = new KeyValue(blur.radiusProperty(), 20); KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValue1); KeyValue keyValue2 = new KeyValue(blur.radiusProperty(), 0); KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(2 * animationSpeed), keyValue2); timeline.getKeyFrames().addAll(keyFrame1, keyFrame2); timeline.setOnFinished((event) -> { currentPlayerLabel.setEffect(null); guiAnimationQueue.setBlocked(false); setBlockedForInput(setBlockedValueAfterAnimation); }); timeline.play(); }); return; } } } guiAnimationQueue.setBlocked(false); setBlockedForInput(setBlockedValueAfterAnimation); }