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:bear.fx.DownloadFxApp.java

public static void launchUI() {
    Platform.runLater(new Runnable() {
        @Override/*from  ww w. j a va  2  s  .c o  m*/
        public void run() {
            new DownloadFxApp().createScene(new javafx.stage.Stage());
        }
    });
}

From source file:api.behindTheName.BehindTheNameApi.java

private void Search(final HashSet<String> set, int counter, final PeopleNameOption option,
        final ProgressCallback callback) {
    final int c = counter;
    callback.onProgressUpdate(behindTheNameProgressValues[c]);
    if (!set.isEmpty())
        callback.onProgress(new TreeSet<>(set));

    Platform.runLater(new Runnable() {

        @Override//w  ww .ja  v a2 s.c o m
        public void run() {
            String nation = genres.get(option.genre);
            String gender = getGenderKey(option.gender);
            String url = "http://www.behindthename.com/api/random.php?number=6&usage=" + nation + "&gender="
                    + gender + "&key=" + BEHIND_THE_NAME_KEY;

            final File file = new File("Temp.xml");
            try {
                URL u = new URL(url);
                FileUtils.copyURLToFile(u, file);

                List<String> lines = FileUtils.readLines(file);
                for (String s : lines) {
                    if (s.contains("<name>")) {
                        s = s.substring(s.indexOf(">") + 1, s.lastIndexOf("</"));
                        set.add(s);
                    }
                }

            } catch (MalformedURLException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            }

            try {
                Thread.sleep(250);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (set.size() == MAX_SIZE || c == MAX_SEARCH - 1 || set.isEmpty()) {
                callback.onProgressUpdate(1.0f);

                return;
            }

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    Search(set, c + 1, option, callback);
                }
            });

        }
    });

}

From source file:com.toyota.carservice.controller.CarMenuManagement.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    ApplicationContext appContex = config.getInstance().getApplicationContext();
    rec2 = Screen.getPrimary().getVisualBounds();
    w = 0.1;//w  ww.  ja  v a  2  s.c o m
    h = 0.1;
    Platform.runLater(() -> {
        stage = (Stage) maximize.getScene().getWindow();
        stage.setMaximized(true);
        stage.setHeight(rec2.getHeight());
        maximize.getStyleClass().add("decoration-button-restore");
        resize.setVisible(false);
        loadMenu();
    });
}

From source file:intelligent.wiki.editor.gui.fx.dialogs.ModifyLinkDialog.java

private void initInputControls(String urlText, String captionText) {
    if (urlText != null) {
        urlInput.setText(urlText);// w  w w  . j  a v  a 2s.  co  m
    }
    urlInput.setPromptText("http://example.com");

    if (captionText != null) {
        captionInput.setText(captionText);
    }
    captionInput.setPromptText("example.com");

    Platform.runLater(urlInput::requestFocus);

    buildValidation(urlInput, "insert-link-dialog.empty-url", "insert-link-dialog.not-valid-url");
}

From source file:com.helegris.szorengeteg.ui.HelpView.java

/**
 * Binds pane size to content size.//  w  w w.j av  a2 s  .  c o m
 */
private void setSize() {
    Platform.runLater(() -> {
        this.prefWidthProperty().bind(this.getScene().widthProperty());
        txtContent.prefWidthProperty().bind(this.prefWidthProperty());
        this.prefHeightProperty().bind(this.getScene().heightProperty());
        txtContent.prefHeightProperty().bind(this.prefHeightProperty().subtract(btnClose.heightProperty()));
    });
}

From source file:com.thomaskuenneth.openweathermapweather.FXMLDocumentController.java

@FXML
void handleButtonAction(ActionEvent event) {
    Task<Void> t = new Task<Void>() {

        @Override/*  ww w. jav  a 2s .c  o  m*/
        protected Void call() throws Exception {
            try {
                final WeatherData weather = WeatherUtils.getWeather(city.getText());
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        Image i = new Image("http://openweathermap.org/img/w/" + weather.icon + ".png");
                        image.setImage(i);
                        beschreibung.setText(weather.description);
                        Double temp = weather.temp - 273.15;
                        temperatur.setText(MessageFormat.format("{0} \u2103", temp.intValue()));
                    }

                });
            } catch (JSONException | IOException ex) {
                LOGGER.log(Level.SEVERE, "handleButtonAction()", ex);
            }
            return null;
        }
    };
    new Thread(t).start();
}

From source file:com.cdd.bao.editor.MainApplication.java

public void start(Stage primaryStage) {
    // open a main window: either a new schema or an existing one
    EditSchema edit = new EditSchema(primaryStage);
    for (String fn : getParameters().getUnnamed()) {
        File f = new File(fn);
        if (!f.exists()) {
            Util.writeln("File not found: " + f.getPath());
            return;
        }/*from   w w w.  ja  v a 2s.  com*/
        edit.loadFile(f);
        break;
    }

    final Stage stage = primaryStage;
    Platform.runLater(() -> stage.show());
}

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

@Override
public void start(final Stage primaryStage) throws IOException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    Platform.runLater(() -> {
        /*/*from  ww w  . j a v a2s .c  o m*/
         * This fixes a bug on OSX where the magic file open handler leads
         * to no context class loader being set in the AppKit (event) thread
         * if the application is not started opening a file.
         */
        if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    });

    Runtime.getRuntime().addShutdownHook(MainApplication.CLEAN_SHUTDOWN_PERFORMER);

    executorService = Executors.newCachedThreadPool();
    addShutdownTask(() -> {
        executorService.shutdown();
    });

    WebDavServer.getInstance().start();
    chooseNativeStylesheet();
    final ResourceBundle rb = ResourceBundle.getBundle("localization");
    final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"), rb);
    final Parent root = loader.load();
    final MainController ctrl = loader.getController();
    ctrl.setStage(primaryStage);
    final Scene scene = new Scene(root);
    primaryStage.setTitle(rb.getString("app.name"));
    primaryStage.setScene(scene);
    primaryStage.sizeToScene();
    primaryStage.setResizable(false);
    primaryStage.show();
    ActiveWindowStyleSupport.startObservingFocus(primaryStage);
    TrayIconUtil.init(primaryStage, rb, () -> {
        quit();
    });

    for (String arg : getParameters().getUnnamed()) {
        handleCommandLineArg(ctrl, arg);
    }

    if (org.controlsfx.tools.Platform.getCurrent().equals(org.controlsfx.tools.Platform.OSX)) {
        Main.OPEN_FILE_HANDLER.complete(file -> handleCommandLineArg(ctrl, file.getAbsolutePath()));
    }

    LocalInstance cryptomatorGuiInstance = SingleInstanceManager.startLocalInstance(APPLICATION_KEY,
            executorService);
    addShutdownTask(() -> {
        cryptomatorGuiInstance.close();
    });

    cryptomatorGuiInstance.registerListener(arg -> handleCommandLineArg(ctrl, arg));
}

From source file:de.digiway.rapidbreeze.client.controller.StatusbarController.java

@Listener(hint = BusEvents.SERVER_CONNECTION_CHANGED_EVENT)
public void onConnectionStateChanged(final boolean newState) {
    Platform.runLater(new Runnable() {
        @Override//from  w  w  w  .j a v a 2s.c o  m
        public void run() {
            if (newState) {
                setConnectedTo(clientConfiguration.getServerName());
            } else {
                setDisconnected();
            }
        }
    });
}

From source file:org.pdfsam.update.UpdatesController.java

@EventListener
public void checkForUpdates(UpdateCheckRequest event) {
    LOG.debug(DefaultI18nContext.getInstance().i18n("Checking for updates"));
    CompletableFuture.supplyAsync(service::getLatestVersion).thenAccept(current -> {
        if (isNotBlank(current) && !pdfsam.version().equals(current)) {
            LOG.info(DefaultI18nContext.getInstance().i18n("PDFsam {0} is available for download", current));
            Platform.runLater(() -> eventStudio().broadcast(new UpdateAvailableEvent(current)));
        }// ww w .  j a v  a2  s.com
    }).whenComplete((r, e) -> {
        if (nonNull(e)) {
            LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to find the latest available version."), e);
        }
    });
}