Example usage for javafx.application Platform runLater

List of usage examples for javafx.application Platform runLater

Introduction

In this page you can find the example usage for javafx.application Platform runLater.

Prototype

public static void runLater(Runnable runnable) 

Source Link

Document

Run the specified Runnable on the JavaFX Application Thread at some unspecified time in the future.

Usage

From source file:genrsa.GenRSAController.java

/**
 * Mtodo usado cuando se pulsa el boton de generar de manera automtica una clave   
 * @param event /*  ww  w  .j ava2s . c om*/
 */
public void processAutomaticGeneration(ActionEvent event) {

    if (this.startGenKey) {

        Task CAstart = new Task() {
            @Override
            protected Object call() throws Exception {
                startGenKey = false;
                String keySize = bits_clave_automatica.getText();
                boolean isSameSize = sameSizePrimes.isSelected();
                boolean isTipicalPubKey = tipicalPubKey.isSelected();
                boolean isSecurePrimes = securePrimes.isSelected();

                progress.setVisible(true);
                Platform.runLater(() -> {
                    disableOnProgress(true);
                    configureGenKeyStop(true);
                });

                RSA = generate.autoRSAkeys(keySize, isSameSize, isTipicalPubKey, isSecurePrimes);

                Platform.runLater(() -> {
                    disableOnProgress(false);
                    configureGenKeyStop(false);
                    mainWindow.clearPrimality();
                    disableButtons();
                    configureGenKeyButtons(isTipicalPubKey, keySize);
                });
                progress.setVisible(false);
                startGenKey = true;

                return null;
            }
        };

        new Thread(CAstart).start();

    } else {
        this.autoGenerarBttn.setDisable(true);
        this.generate.setGenKeyCancelled();
        this.mainWindow.delete();
        this.startGenKey = true;
    }
}

From source file:Dominion.DynamicCard.ClientModelService.java

private void updateTurnInfo(JSONObject obj) {
    final int actions = Integer.parseInt(obj.getString("actioncount"));
    final int buys = Integer.parseInt(obj.getString("purchasecount"));
    final int coins = Integer.parseInt(obj.getString("money"));
    Platform.runLater(new Runnable() {

        @Override/*from w  w  w . j  av a2s .  co  m*/
        public void run() {
            controller.updateTurnInfo(actions, buys, coins);
        }

    });
}

From source file:com.mycompany.trafficimportfileconverter2.Main2Controller.java

private void autoSearch() {
    new Thread(() -> {
        File[] files = filechooser.getInitialDirectory().listFiles(new FileFilter() {
            @Override//from www .jav  a  2  s. c o  m
            public boolean accept(File pathname) {
                String x = FilenameUtils.getExtension(pathname.getAbsolutePath());
                return x.compareToIgnoreCase("tsv") == 0;
            }
        });

        File mostRecent = Arrays.stream(files).max((x, y) -> Long.compare(x.lastModified(), y.lastModified()))
                .orElse(null);
        if (mostRecent == null) {
            return;
        }
        Platform.runLater(() -> {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setContentText("We found the following TSV file in your default location:\n\""
                    + mostRecent.getName() + "\"\n" + "Modified: " + new Date(mostRecent.lastModified())
                    + "\n\n" + "Would you like load this file?");
            Optional<ButtonType> answer = alert.showAndWait();
            if (answer.isPresent() && answer.get().getButtonData().equals(ButtonData.OK_DONE)) {
                System.out.println(answer.get());
                setInputFile(mostRecent);

                //setting the input file is enough to trigger the load!
                //     loadInInfo(mostRecent);
                //not safe, just load the file in for you.
                //                    onBtnGo(null);
            } else {
            }
        });

    }).start();
}

From source file:org.openbase.display.DisplayView.java

private <V> Future<V> runTask(final Callable<V> callable) throws CouldNotPerformException {
    try {//from   w  ww.j  a  v  a2  s .  co m

        if (Platform.isFxApplicationThread()) {
            try {
                return CompletableFuture.completedFuture(callable.call());
            } catch (Exception ex) {
                ExceptionPrinter.printHistory(new CouldNotPerformException("Could not perform task!", ex),
                        logger);
            }
        }

        FutureTask<V> future = new FutureTask(() -> {
            try {
                return callable.call();
            } catch (Exception ex) {
                throw ExceptionPrinter.printHistoryAndReturnThrowable(ex, logger);
            }
        });
        Platform.runLater(future);
        return future;
    } catch (Exception ex) {
        throw new CouldNotPerformException("Could not perform task!", ex);
    }
}

From source file:gov.va.isaac.gui.ConceptNode.java

public void clear() {
    logger.debug("Clear called");
    Runnable r = new Runnable() {
        @Override/*w  w  w .jav a 2 s  .c  o m*/
        public void run() {
            cb_.setValue(new SimpleDisplayConcept("", 0));
        }
    };

    if (Platform.isFxApplicationThread()) {
        r.run();
    } else {
        Platform.runLater(r);
    }
}

From source file:org.ykc.usbcx.MainWindowController.java

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    Preferences.genTempFolders();
    Preferences.loadPreferences();
    bOpen.setGraphic(new ImageView(new Image("/open.png")));
    bOpen.setTooltip(new Tooltip("Open ucx1 file"));
    bSave.setGraphic(new ImageView(new Image("/save.png")));
    bSave.setTooltip(new Tooltip("Save ucx1 file"));
    bStartStop.setGraphic(new ImageView(new Image("/start_stop.png")));
    bStartStop.setTooltip(new Tooltip("Start/Stop Capture"));
    bReset.setGraphic(new ImageView(new Image("/reset.png")));
    bReset.setTooltip(new Tooltip("Reset and clear"));
    bTrigger.setGraphic(new ImageView(new Image("/trigger.png")));
    bTrigger.setTooltip(new Tooltip("Set Trigger"));
    bGetVersion.setGraphic(new ImageView(new Image("/version.png")));
    bGetVersion.setTooltip(new Tooltip("Get Version"));
    bDownload.setGraphic(new ImageView(new Image("/download.png")));
    bDownload.setTooltip(new Tooltip("Download FW"));
    bAbout.setGraphic(new ImageView(new Image("/info.png")));
    bAbout.setTooltip(new Tooltip("About USBCx"));
    bFirstPage.setGraphic(new ImageView(new Image("/double_arrow_left.png")));
    bFirstPage.setTooltip(new Tooltip("Go to First Page"));
    bPrevPage.setGraphic(new ImageView(new Image("/arrow_left.png")));
    bPrevPage.setTooltip(new Tooltip("Go to Previous Page"));
    bNextPage.setGraphic(new ImageView(new Image("/arrow_right.png")));
    bNextPage.setTooltip(new Tooltip("Go to Next Page"));
    bLastPage.setGraphic(new ImageView(new Image("/double_arrow_right.png")));
    bLastPage.setTooltip(new Tooltip("Go to Last Page"));
    bCollapse.setGraphic(new ImageView(new Image("/collapse.png")));
    bCollapse.setTooltip(new Tooltip("Collapse Items"));
    bExpand.setGraphic(new ImageView(new Image("/expand.png")));
    bExpand.setTooltip(new Tooltip("Expand Items"));
    bGraphScrollLeft.setGraphic(new ImageView(new Image("/arrow_left.png")));
    bGraphScrollLeft.setTooltip(new Tooltip("Previous plot"));
    bGraphScrollRight.setGraphic(new ImageView(new Image("/arrow_right.png")));
    bGraphScrollRight.setTooltip(new Tooltip("Next plot"));

    ttColPVName.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("name"));
    ttColPVValue.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("value"));
    ttColPVDecimal.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("decval"));
    ttColPVHex.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("hexval"));
    ttColPVBinary.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("binaryval"));
    ttColPVLength.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("len"));
    ttColPVOffset.setCellValueFactory(new TreeItemPropertyValueFactory<DetailsRow, String>("offset"));
    TreeItem<DetailsRow> rootItem = new TreeItem<DetailsRow>();
    ttViewParseViewer.setRoot(rootItem);

    ttColPVName.setCellFactory((TreeTableColumn<DetailsRow, String> param) -> {
        TreeTableCell<DetailsRow, String> cell = new TreeTableCell<DetailsRow, String>() {
            @Override/*from  ww  w .  j  a v a2 s .  com*/
            protected void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                setText(empty ? "" : getItem().toString());
                TreeTableRow<DetailsRow> ttr = getTreeTableRow();
                DetailsRow x = ttr.getItem();
                DetailsRow.BG bg = BG.NORMAL;
                String style = "";
                if (x != null) {
                    bg = x.getBcolor();
                    style += x.getBold() ? "-fx-font-weight:bold;-fx-font-style:italic;" : "";
                }

                switch (bg) {
                case RED:
                    style += "-fx-text-fill:red;";
                    break;
                case GREEN:
                    style += "-fx-text-fill:green;";
                    break;
                case BLUE:
                    style += "-fx-text-fill:blue;";
                    break;
                case YELLOW:
                    style += "-fx-text-fill:yellow;";
                    break;
                case PINK:
                    style += "-fx-text-fill:pink;";
                    break;
                default:
                    style += "-fx-text-fill:white;" + "-fx-highlight-fill:dodgerblue;"
                            + "-fx-highlight-text-fill:white";
                    break;
                }
                setStyle(style);
            }
        };
        return cell;
    });

    tColMViewSno.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("sno"));
    tColMViewOk.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("ok"));
    tColMViewSop.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("sop"));
    tColMViewMsg.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("msg"));
    tColMViewId.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("id"));
    tColMViewDrole.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("drole"));
    tColMViewProle.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("prole"));
    tColMViewCount.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("count"));
    tColMViewRev.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("rev"));
    tColMViewDuration.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("duration"));
    tColMViewDelta.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("delta"));
    tColMViewVbus.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("vbus"));
    tColMViewData.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("data"));
    tColMViewStartTime.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("stime"));
    tColMViewEndTime.setCellValueFactory(new PropertyValueFactory<MainViewRow, String>("etime"));

    tColDataViewIndex.setCellValueFactory(new PropertyValueFactory<DataViewRow, Integer>("index"));
    tColDataViewValue.setCellValueFactory(new PropertyValueFactory<DataViewRow, String>("value"));

    cBoxMsgClass.getItems().addAll(PDUtils.MSG_CLASS);
    cBoxMsgClass.getSelectionModel().select(0);
    cBoxMsgType.getItems().addAll(PDUtils.CTRL_MSG_TYPE);
    cBoxMsgType.getSelectionModel().select(1);
    cBoxSop.getItems().addAll(PDUtils.SOP_TYPE);
    cBoxSop.getSelectionModel().select(0);

    bFirstPage.setDisable(true);
    bLastPage.setDisable(true);
    bPrevPage.setDisable(true);
    bNextPage.setDisable(true);

    lGraph = new XScope(lchartData, xAxis, yAxis, cboxGraphXScale, bGraphScrollLeft, bGraphScrollRight,
            chkGraphCC1, chkGraphCC2, chkGraphVbus, chkGraphAmp, lblGraphYValue, lblGraphXValue, lblGraphDeltaY,
            lblGraphDeltaX);

    usbcontrol = new USBControl(cBoxDeviceList, statusBar, lblVolt, lblCur, lblCC1, lblCC2);
    cordinator = new Cordinator(usbcontrol, tViewMain, tViewData, ttViewParseViewer, lblStartDelta, lGraph);

    Platform.runLater(() -> {
        handleArgs();
    });
}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

private void setToLoggedOut() {
    Platform.runLater(() -> {
        myGists.getItems().clear();//from   ww  w.  j  av  a  2  s . co m
        logoutGithub.disableProperty().set(true);
        logoutGithub.setText("Anonymous");
    });
}

From source file:org.noroomattheinn.visibletesla.MainController.java

private void jumpToTab(final Tab tab) {
    Platform.runLater(new Runnable() {
        @Override/*from   w w  w .j av a  2 s.c  om*/
        public void run() {
            tabPane.getSelectionModel().select(tab);
        }
    });
}

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

public void yearlyInOutToggled(ActionEvent actionEvent) {
    final NumberAxis xAxis = new NumberAxis();
    final CategoryAxis yAxis = new CategoryAxis();
    yAxis.setLabel("In/Out in Euro");
    xAxis.setLabel("Year");

    final BarChart<Number, String> barChart = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Yearly in/out");

    chartFrame.setCenter(barChart);//  w  w w  .  j a v a  2  s  .c  om

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Account account = accountCombo.getValue();
        String accountLabel = getAccountLabel(account);

        XYChart.Series<Number, String> inSeries = new XYChart.Series<>();
        inSeries.setName("In" + accountLabel);
        barChart.getData().add(inSeries);

        XYChart.Series<Number, String> outSeries = new XYChart.Series<>();
        outSeries.setName("Out" + accountLabel);
        barChart.getData().add(outSeries);

        ValueRange<LocalDate> period = getTransactionOpRange(account, yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        ObservableList<String> categories = FXCollections.observableArrayList();
        for (int y = period.from().getYear(); y < period.to().getYear() + 6; y++) {
            categories.add(String.valueOf(y));
        }
        yAxis.setCategories(categories);
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {

                        List<TransactionVolume> incomingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getYearlyIncomingVolumes(false)
                                : transactionRepository.getYearlyIncomingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            incomingVolumes = incomingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : incomingVolumes) {
                            XYChart.Data<Number, String> inData = new XYChart.Data<>(volume.getVolume(),
                                    String.valueOf(volume.getYear()));
                            Platform.runLater(() -> {
                                inSeries.getData().add(inData);
                                StackPane node = (StackPane) inData.getNode();
                                node.getChildren().add(
                                        new Label(CurrencyFormat.getInstance().format(volume.getVolume())));
                                node.addEventHandler(MOUSE_CLICKED,
                                        event -> handleYearlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS) ? null : account,
                                                ofYearDay(volume.getYear(), 1), event));
                            });
                        }

                        List<TransactionVolume> outgoingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getYearlyOutgoingVolumes(false)
                                : transactionRepository.getYearlyOutgoingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            outgoingVolumes = outgoingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : outgoingVolumes) {
                            XYChart.Data<Number, String> outData = new XYChart.Data<>(volume.getVolume().abs(),
                                    String.valueOf(volume.getYear()));
                            Platform.runLater(() -> {
                                outSeries.getData().add(outData);
                                StackPane node = (StackPane) outData.getNode();
                                node.getChildren().add(
                                        new Label(CurrencyFormat.getInstance().format(volume.getVolume())));
                                node.addEventHandler(MOUSE_CLICKED,
                                        event -> handleYearlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS) ? null : account,
                                                ofYearDay(volume.getYear(), 1), event));
                            });
                        }

                        return null;
                    }
                };
            }
        };
        service.start();

    }
}

From source file:gov.va.isaac.sync.view.SyncView.java

private void promptUserForCreds(UserProfile up) throws InterruptedException {
    CountDownLatch awaitCreds = new CountDownLatch(1);

    Platform.runLater(() -> {
        AppContext.getService(CredentialsPromptDialog.class).showView(up.getSyncUsername(),
                up.getSyncPassword(), "Please provide the Sync credentials", credentials -> {
                    if (credentials == null) {
                        addLine("Cancelling");
                        cancelRequested_ = true;
                    } else {

                        if (!up.getSyncUsername().equals(credentials.getUsername())) {
                            try {
                                syncService_
                                        .relinkRemote(
                                                syncService_.substituteURL(
                                                        AppContext.getAppConfiguration()
                                                                .getCurrentChangeSetUrl(),
                                                        credentials.getUsername()),
                                                credentials.getUsername(), credentials.getPassword());
                            } catch (AuthenticationException e) {
                                log.info("Sync credentials still incorrect", e);
                            } catch (Exception e) {
                                //highly unlikely.. don't care, it will just fail - will work next time.
                                log.error("Unexpected", e);
                            }//ww w .  j a  va2  s. co  m
                        }
                        up.setSyncUsername(credentials.getUsername());
                        up.setSyncPassword(credentials.getPassword());

                        try {
                            AppContext.getService(UserProfileManager.class).saveChanges(up);
                        } catch (Exception e) {
                            //doesn't really matter - just a pw change, no big deal if we can't save it.
                            log.error("Unexpected error changing profile change", e);
                        }
                    }
                    awaitCreds.countDown();
                });
    });

    awaitCreds.await();
}