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:org.cryptomator.ui.model.Vault.java

public synchronized void activateFrontend(FrontendFactory frontendFactory, Settings settings,
        CharSequence passphrase) throws FrontendCreationFailedException {
    boolean launchSuccess = false;
    boolean mountSuccess = false;
    try {//from   www  . j  a  va2s .  com
        FileSystem fs = getNioFileSystem();
        FileSystem shorteningFs = shorteningFileSystemFactory.get(fs);
        FileSystem cryptoFs = cryptoFileSystemFactory.unlockExisting(shorteningFs, passphrase, this);
        FileSystem normalizingFs = new NormalizedNameFileSystem(cryptoFs,
                SystemUtils.IS_OS_MAC_OSX ? Form.NFD : Form.NFC);
        StatsFileSystem statsFs = new StatsFileSystem(normalizingFs);
        statsFileSystem = Optional.of(statsFs);
        Frontend frontend = frontendFactory.create(statsFs, FrontendId.from(id), stripStart(mountName, "/"));
        launchSuccess = true;
        filesystemFrontend = closer.closeLater(frontend);
        frontend.mount(getMountParams(settings));
        mountSuccess = true;
    } catch (UncheckedIOException e) {
        throw new FrontendCreationFailedException(e);
    } catch (CommandFailedException e) {
        LOG.error("Failed to mount vault " + mountName, e);
    } finally {
        // unlocked is a observable property and should only be changed by the FX application thread
        boolean finalLaunchSuccess = launchSuccess;
        boolean finalMountSuccess = mountSuccess;
        Platform.runLater(() -> {
            unlocked.set(finalLaunchSuccess);
            mounted.set(finalMountSuccess);
        });
    }
}

From source file:ExcelFx.FXMLDocumentController.java

private void mainProcessing(Task task) {
    final Thread thread = new Thread(null, task, "Background");
    thread.setDaemon(true);/*from  w  ww .  ja v a 2 s  . c  o  m*/
    thread.start();
    new Thread() {
        @Override
        public void run() {
            try {
                thread.join();
            } catch (InterruptedException e) {
            }
            Platform.runLater(() -> {
                setProgressBar(0);
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("");
                alert.setHeaderText("");
                alert.setContentText(" ");
                alert.showAndWait();

            });

        }
    }.start();

    this.Print.setDisable(false);
}

From source file:com.imesha.imageprocessor.controllers.MainController.java

/**
 * Utility method to show a given message in the message are of the UI.
 *
 * @param message      The message to be displayed
 * @param messageLabel The @{@link Label} object in which the message should be displayed
 *///from   w  w  w . j  a  v  a2  s . c  om
private static void showMessage(final String message, final Label messageLabel) {
    Platform.runLater(new Runnable() {
        public void run() {
            messageLabel.setText(message);
        }
    });
}

From source file:org.cryptomator.ui.ExitUtil.java

private void restoreFromTray(ActionEvent event) {
    Platform.runLater(() -> {
        macFunctions.map(MacFunctions::uiState)
                .ifPresent(JniException.ignore(MacApplicationUiState::transformToForegroundApplication));
        mainWindow.show();/*from   w w w.j a v a  2 s .c  o  m*/
        mainWindow.requestFocus();
    });
}

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

/**
 * This method is invoked when the daily balance button has been toggled
 *
 * @param actionEvent/*www.j ava2s  .c om*/
 */
public void dailyBalanceToggled(ActionEvent actionEvent) {
    LocalDateAxis xAxis = new LocalDateAxis();
    NumberAxis yAxis = new NumberAxis();

    final LineChart<LocalDate, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setCreateSymbols(false);

    chartFrame.setCenter(lineChart);

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        xAxis.setLabel("Day of year");
        yAxis.setLabel("Balance in Euro");
        lineChart.setTitle("Balance development day by day");

        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(), yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        xAxis.setLowerBound(period.from());
        xAxis.setUpperBound(period.to());

        Service<Void> service = new Service<Void>() {

            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {

                    @Override
                    protected Void call() throws Exception {
                        Map<Account, List<Transaction>> transactionMap = getTransactions(
                                accountCombo.getValue(), yearCombo.getValue());

                        transactionMap.entrySet().forEach(entry -> {
                            Account account = entry.getKey();
                            List<Transaction> transactionList = entry.getValue();

                            XYChart.Series<LocalDate, Number> series = new XYChart.Series<>();
                            series.setName(format("%s [%s]", account.toPresentableString(),
                                    account.getFormattedBalance()));

                            // sort transactions by operation value descending
                            transactionList.sort((t1, t2) -> t2.getDtOp().compareTo(t1.getDtOp()));
                            account.calculateStartingBalance(transactionList);
                            series.getData()
                                    .add(new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));

                            // sort transactions by operation value ascending
                            transactionList.sort((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()));
                            transactionList.forEach(trx -> {
                                account.calculateCurrentBalance(trx);
                                series.getData().add(
                                        new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));
                            });

                            Platform.runLater(() -> lineChart.getData().add(series));
                        });

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

From source file:ca.wumbo.doommanager.client.controller.file.DXMLProjectCreatorController.java

@FXML
private void initialize() {
    // This image has no icon, so let's set it with a nice looking one.
    folderImageIcon.setImage(resources.getImage("dxmlfolderlarge"));

    // If anything changes in the fields, notify the updater.
    projectFolderTextfield.setOnKeyReleased((event) -> projectInfoTextUpdated());
    projectNameTextfield.setOnKeyReleased((event) -> projectInfoTextUpdated());
    projectAuthorsTextfield.setOnKeyReleased((event) -> projectInfoTextUpdated());
    projectWebsiteTextfield.setOnKeyReleased((event) -> projectInfoTextUpdated());
    compilationFileNameTextField.setOnKeyReleased((event) -> compilationTextUpdated());
    compilationVersionTextField.setOnKeyReleased((event) -> compilationTextUpdated());
    layoutSourceTextField.setOnKeyReleased((event) -> layoutTextUpdated());
    layoutResourcesTextField.setOnKeyReleased((event) -> layoutTextUpdated());
    layoutBuildTextField.setOnKeyReleased((event) -> layoutTextUpdated());

    // We want the base values to be selected.
    compilationPackagingComboBox.getSelectionModel().select(0);
    licenseComboBox.getSelectionModel().select(0);
    sourceControlComboBox.getSelectionModel().select(0);

    // Remove the panes from the middle stack pane so we can start the wizard on the first pane.
    // Then add in the children, we want the background pane and the first pane.
    middleStackPane.getChildren().clear();
    middleStackPane.getChildren().add(projectInfoPane);

    // This will make it so we don't always focus on the first textfield at the top.
    Platform.runLater(() -> rootBorderPane.requestFocus());
}

From source file:org.cryptomator.ui.model.Vault.java

public synchronized void deactivateFrontend() throws Exception {
    filesystemFrontend.close();/*www.j  a  v a2 s.c o m*/
    statsFileSystem = Optional.empty();
    Platform.runLater(() -> {
        mounted.set(false);
        unlocked.set(false);
    });
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.navpanel.NavPanel.java

private void rebuildTrees() {
    navTreeRoot = new GroupTreeItem("", null, sortByBox.getSelectionModel().selectedItemProperty().get());
    hashTreeRoot = new GroupTreeItem("", null, sortByBox.getSelectionModel().selectedItemProperty().get());

    ObservableList<DrawableGroup> groups = controller.getGroupManager().getAnalyzedGroups();

    for (DrawableGroup g : groups) {
        insertIntoNavTree(g);/*from w w  w.  j av  a 2 s  .  c  o m*/
        if (g.getHashSetHitsCount() > 0) {
            insertIntoHashTree(g);
        }
    }

    Platform.runLater(() -> {
        navTree.setRoot(navTreeRoot);
        navTreeRoot.setExpanded(true);
        hashTree.setRoot(hashTreeRoot);
        hashTreeRoot.setExpanded(true);
    });
}

From source file:ijfx.ui.plugin.panel.OverlayPanel.java

@EventHandler
public void handleEvent(OverlaySelectedEvent event) {

    if (event.getOverlay() == null) {
        return;/*from  w ww .java 2 s  .  c o m*/
    }

    // task calculating the stats in a new thread
    Task<HashMap<String, Double>> task = new Task<HashMap<String, Double>>() {
        @Override
        protected HashMap<String, Double> call() throws Exception {
            return statsService.getStat(event.getDisplay(), event.getOverlay());
        }

        @Override
        protected void succeeded() {
            super.succeeded();

            tableView.getItems().clear();
            this.getValue().forEach((key, value) -> {
                entries.add(new MyEntry(key, value));
            });

        }
    };
    overlayProperty.setValue(event.getOverlay());
    Platform.runLater(() -> updateChart(event.getOverlay()));
    ImageJFX.getThreadPool().submit(task);

}

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void tractAlertMessage(AlertMessage am) {
    Platform.runLater(new Runnable() {
        @Override//www .j  a  va  2 s  .  c o m
        public void run() {
            Alert alert;
            // Create alert
            if (am.getType().equals(AlertMessage.Type.CONFIRMATION)) {
                alert = AlertsManager.createConfirmationAlert(am);
            } else {
                alert = AlertsManager.createSimpleAlert(am);
            }

            // Show alert
            if (!am.getType().equals(AlertMessage.Type.CONFIRMATION)) {
                alert.showAndWait();
                if (am.getNext() != null) {
                    context.send(am.getTarget(), am.getNext());
                }
            } else {
                Optional<ButtonType> result = alert.showAndWait();
                am.setResult(result.get().getButtonData().equals(ButtonBar.ButtonData.YES));
                context.send(am.getSourceId(), am);
            }
        }
    });
}