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:at.ac.tuwien.qse.sepm.gui.controller.impl.WorldmapViewImpl.java

@FXML
private void initialize() {
    mapScene.setOnLoaded(this::showPlaces);
    mapScene.setMarkerClickCallback(this::handleMarkerClicked);
    clusterService.subscribePlaceChanged(place -> {
        Platform.runLater(() -> {
            this.addPlace(place);
            mapScene.fitToMarkers();//from  w w  w .jav  a 2  s .c om
        });
    });
}

From source file:net.rptools.gui.listeners.fxml.ScriptController.java

@Override
public void assetListChanged(final Collection<String> removed, final Collection<String> added) {
    LOGGER.info("removed={}; added={}", removed, added);
    if (!Platform.isFxApplicationThread()) {
        Platform.runLater(new Runnable() {
            @Override//from  w  w  w. j a v  a  2  s .co m
            public void run() {
                assetListChanged(removed, added);
            }
        });
        return;
    }

    // Now we are in the right thread
    final int selectedIndex = scriptList.getSelectionModel().getSelectedIndex();
    if (added != null && added.size() != 0) {
        final List<AssetTableRow> addRows = new ArrayList<>();
        createRows(added, addRows);
        scriptList.getItems().addAll(addRows);
    }
    if (removed != null && removed.size() != 0) {
        final List<AssetTableRow> removeRows = new ArrayList<>();
        createRows(removed, removeRows);
        scriptList.getItems().removeAll(removeRows);
    }

    if (scriptList.getItems().size() > selectedIndex) {
        scriptList.getSelectionModel().select(selectedIndex);
    }
}

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

public void didChooseUsername(ObservableValue<? extends String> property, String oldValue, String newValue) {
    if (newValue != null) {
        Platform.runLater(passwordField::requestFocus);
    }//from  w w w .j  a v a 2s.  c  o m
    passwordField.setDisable(StringUtils.isEmpty(newValue));
}

From source file:com.gitlab.anlar.lunatic.gui.MainWindowController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    Config config = Config.getInstance();

    createLogPanelAppender();//  w w  w. ja va  2s  .c om

    initListeners(config);
    initElements(config);

    if (config.isStart()) {
        // launch server in separate thread so it won't block main window appearance with warning dialog
        // in case if error will occur during it's start
        Platform.runLater(this::startServer);
    }
}

From source file:net.rptools.layercontrol.LayerStackLayer.java

/**
 * Add a layer.//  w ww .jav a 2s  . com
 * @param i index to add at
 * @param layer layer to add
 */
@ThreadPolicy(ThreadPolicy.ThreadId.ANY)
public synchronized void addLayer(final int i, final Layer layer) {
    if (!Platform.isFxApplicationThread()) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                addLayer(i, layer);
            }
        });
    }
    // Now on JFX thread
    Pane pane = new Pane();
    final String resource = "layer" + layer.getName() + ".fxml";
    try {
        pane = component.getFramework().getFXMLLoader(layer.getClass().getResource(resource)).load();
    } catch (final Exception e) {
        LOGGER.warn("no layer pane found resource={}", resource);
    }
    pane.getStyleClass().add(layer.getName().toLowerCase());
    pane.setId(StringUtils.uncapitalize(layer.getName()));
    pane.minWidthProperty().bind(getDrawable().widthProperty());
    pane.minHeightProperty().bind(getDrawable().heightProperty());
    final int size = getDrawable().getChildren().size();
    getDrawable().getChildren().add(size - i, pane);
    layer.setDrawable(pane);
}

From source file:account.management.controller.POVoucherController.java

/**
 * Initializes the controller class./*from  w  ww.j a va  2 s.c o m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
    balance.focusedProperty().addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue) {
                    Platform.runLater(new Runnable() {

                        @Override
                        public void run() {
                            balance.requestFocus();
                            balance.selectAll();
                        }
                    });

                }
            });
    this.container.getChildren().remove(0);
    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.total_price.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit deposit voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        try {
                            onSubmitButtonClick(null);
                        } catch (ParseException ex) {
                            Logger.getLogger(SalaryVoucherController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();
}

From source file:org.pdfsam.ui.log.TextAreaAppender.java

private void doAppendMessage(String message, ILoggingEvent event) {
    if (StringUtils.isNotBlank(message)) {
        Platform.runLater(() -> logListView.appendLog(LogLevel.toLogLevel(event.getLevel().toInt()), message));
        appendStackIfAvailable(event);//from   w w w.  j av a 2  s. c  o  m
        if (event.getLevel().isGreaterOrEqual(Level.ERROR)) {
            Platform.runLater(() -> eventStudio().broadcast(new ErrorLoggedEvent()));
        }
    }
}

From source file:com.getqube.store.BrowseCategoryController.java

public void initialize() {
    new Thread(new Runnable() {
        @Override/*from w w  w  .ja v a 2 s  . c  o m*/
        public void run() {
            Category c = ApplicationContext.getInstance().getRegisteredObject(Category.class);

            try {
                App[] apps = AppService.allForCategory(String.valueOf(c.getId()));

                // Show the app detail page now that the data has been loaded from the Web.
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {

                        for (App app : apps) {
                            CategoryButtonControl button = new CategoryButtonControl();
                            button.setLink(app.getName());

                            button.setImage(new Image(app.getThumbnail()));

                            button.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
                                public void handle(final MouseEvent mouseEvent) {
                                    ApplicationContext.getInstance().register(app);

                                    TreeItem<String> appItem = new TreeItem<String>(app.getName());
                                    CategoriesController.BREADCRUMBS.getSelectedCrumb().getChildren()
                                            .add(appItem);
                                    CategoriesController.BREADCRUMBS.setSelectedCrumb(appItem);

                                    Navigator.loadVista(Navigator.APP_DETAIL);
                                }
                            });

                            paneApps.getChildren().add(button);
                        }

                        paneLoading.setVisible(false);
                        paneEverything.setVisible(true);
                    }
                });
            } catch (ProcessingException processingException) {
                logger.log(Level.WARNING, processingException.getMessage(), processingException);
                reportConnectionProblem();
            } catch (IOException ioException) {
                logger.log(Level.WARNING, ioException.getMessage(), ioException);
                reportConnectionProblem();
            }
        }
    }).start();
}

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

private void doIt() {
    Task<Void> t = new Task<Void>() {
        @Override/*from   ww  w. j a va 2 s.c o m*/
        protected Void call() throws Exception {
            try {
                final WeatherData weather = WeatherUtils.getWeather(city.getText());
                Platform.runLater(() -> {
                    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:ijfx.ui.widgets.PluginInfoPane.java

private void onModuleChanged(Object o, PluginInfo oldValue, PluginInfo newValue) {
    Platform.runLater(this::updateWebView);
}