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:com.neuronrobotics.bowlerstudio.MainController.java

public static void updateLog() {
    if (logViewRef != null) {
        String current;/*  w w w  . j  ava  2  s. c om*/
        String finalStr;
        if (getOut().size() == 0) {
            newString = null;
        } else {
            newString = getOut().toString();
            getOut().reset();
        }
        if (newString != null) {
            current = logViewRef.getText() + newString;
            try {
                finalStr = new String(current.substring(current.getBytes().length - sizeOfTextBuffer));
            } catch (StringIndexOutOfBoundsException ex) {
                finalStr = current;
            }
            int strlen = finalStr.length() - 1;
            logViewRef.setText(finalStr);
            Platform.runLater(() -> logViewRef.positionCaret(strlen));
        }

    }
    FxTimer.runLater(Duration.ofMillis(100), () -> {

        updateLog();
    });
}

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

/**
 * Add a file to the GUI history section.
 * @param location file name to add//  w  ww.j a va  2  s . com
 * @throws IOException I/O error
 */
@ThreadPolicy(ThreadPolicy.ThreadId.ANY)
public void updateFile(final String location) throws IOException {
    final int historySize = getFileHistorySize();
    final String expandedFileName = Utility.expandEnvironment(location);
    final String probeName = expandedFileName.replaceFirst("file://", "");
    final String name = RptoolsFileTypeDetector.probeContentName(FileSystems.getDefault().getPath(probeName));
    LOGGER.debug("probeName={}; name={}; location={}", probeName, name, location);
    if (name == null || location == null) { // safeguard
        return;
    }
    final AssetTableRow newRow = new AssetTableRow(name, location);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            if (getURLList().getItems().size() == historySize) {
                getURLList().getItems().remove(historySize - 1);
            }
            // This moves existing rows to the front
            if (getURLList().getItems().contains(newRow)) {
                getURLList().getItems().remove(newRow);
            }
            getURLList().getItems().add(0, newRow);
            guiToState();
        }
    });
}

From source file:org.eclipse.jubula.rc.javafx.driver.EventThreadQueuerJavaFXImpl.java

@Override
public void invokeLater(String name, Runnable runnable) {

    Validate.notNull(runnable, "runnable must not be null"); //$NON-NLS-1$
    Platform.runLater(runnable);
}

From source file:de.mirkosertic.desktopsearch.DesktopSearch.java

@Override
public void start(Stage aStage) throws Exception {

    // This is our base directory
    File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir");
    theBaseDirectory.mkdirs();//w ww.java 2s  .c om

    configurationManager = new ConfigurationManager(theBaseDirectory);

    Notifier theNotifier = new Notifier();

    stage = aStage;

    // Create the known preview processors
    PreviewProcessor thePreviewProcessor = new PreviewProcessor();

    try {
        // Boot the search backend and set it up for listening to configuration changes
        backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor);
        configurationManager.addChangeListener(backend);

        // Boot embedded JSP container
        embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor,
                configurationManager);

        embeddedWebServer.start();
    } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) {
        // In this case, there is already an instance of DesktopSearch running
        // Inform the instance to bring it to front end terminate the current process.
        URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl());
        // Retrieve the content, but it can be safely ignored
        // There must only be the get request
        Object theContent = theURL.getContent();

        // Terminate the JVM. The window of the running instance is visible now.
        System.exit(0);
    }

    aStage.setTitle("Free Desktop Search");
    aStage.setWidth(800);
    aStage.setHeight(600);
    aStage.initStyle(StageStyle.TRANSPARENT);

    FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml"));
    AnchorPane theMainScene = theLoader.load();

    final DesktopSearchController theController = theLoader.getController();
    theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner());

    Undecorator theUndecorator = new Undecorator(stage, theMainScene);
    theUndecorator.getStylesheets().add("/skin/undecorator.css");

    Scene theScene = new Scene(theUndecorator);

    // Hacky, but works...
    theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");

    theScene.setFill(Color.TRANSPARENT);
    aStage.setScene(theScene);

    aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png")));

    if (SystemTray.isSupported()) {
        Platform.setImplicitExit(false);
        SystemTray theTray = SystemTray.getSystemTray();

        // We need to reformat the icon according to the current tray icon dimensions
        // this depends on the underlying OS
        java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit()
                .getImage(getClass().getResource("/fds_small.png"));
        int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width;
        TrayIcon theTrayIcon = new TrayIcon(
                theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH),
                "Free Desktop Search");
        theTrayIcon.setImageAutoSize(true);
        theTrayIcon.setToolTip("FXDesktopSearch");
        theTrayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 1) {
                    Platform.runLater(() -> {
                        if (stage.isIconified()) {
                            stage.setIconified(false);
                        }
                        stage.show();
                        stage.toFront();
                    });
                }
            }
        });
        theTray.add(theTrayIcon);

        aStage.setOnCloseRequest(aEvent -> stage.hide());
    } else {

        aStage.setOnCloseRequest(aEvent -> shutdown());
    }

    aStage.setMaximized(true);
    aStage.show();
}

From source file:com.github.vatbub.tictactoe.view.AnimationThreadPoolExecutor.java

/**
 * @throws RejectedExecutionException {@inheritDoc}
 * @throws NullPointerException       {@inheritDoc}
 *///ww  w . jav a2s  .c  o  m
@NotNull
@Override
public <T> Future<T> submit(Callable<T> task) {
    Callable<T> effectiveTask = () -> {
        FutureTask<T> effectiveCall = new FutureTask<>(task);
        Platform.runLater(effectiveCall);
        return effectiveCall.get();
    };
    return super.schedule(effectiveTask, 0, NANOSECONDS);
}

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

private <X extends Labeled & GroupCell<?>> void clearCell(X cell) {
    Platform.runLater(() -> {
        cell.setTooltip(null);/*w w  w .  j a v a  2s .c om*/
        cell.setText(null);
        cell.setGraphic(null);
        cell.setStyle("");
    });
}

From source file:calendarioSeries.vistas.MainViewController.java

public void populateImagenes() {
    Platform.runLater(new Runnable() {
        @Override/*from www .  java 2s  .  co m*/
        public void run() {
            imagenes.getChildren().clear();
            for (Serie serie : series) {
                //System.out.println(serie.getLastVisto());
                try {
                    Image image = new Image(serie.getUrlImagen());
                    ImageView poster = new ImageView();
                    ContextMenu menu = new ContextMenu();
                    //String css = MainApp.class.getResource("resources/MainTheme.css").toExternalForm();
                    MenuItem delete = new MenuItem("Eliminar");
                    delete.setId(serie.getId());
                    delete.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent event) {
                            menu.hide();
                            MenuItem clicked = (MenuItem) event.getSource();
                            String toDelete = clicked.getId();
                            for (Serie serie : series) {
                                if (serie.getId().equals(toDelete)) {
                                    series.remove(serie);
                                    populateImagenes();
                                    showDetallesMes(mesActual);
                                }
                            }
                            event.consume();
                        }
                    });

                    menu.getItems().add(delete);

                    poster.setId(serie.getTitulo());
                    poster.setImage(image);
                    poster.setCache(true);
                    // poster.setPreserveRatio(true);
                    poster.setFitWidth(210);
                    poster.setFitHeight(300);
                    poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                        @Override
                        public void handle(ContextMenuEvent event) {
                            menu.show(poster, event.getScreenX(), event.getScreenY());
                            //menu.getScene().getRoot().getStylesheets().add(css);
                            event.consume();
                        }
                    });
                    poster.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                            if (event.getButton() == MouseButton.PRIMARY) {
                                try {
                                    //serieToPass = serie;
                                    sceneToPass = mainApp.scene;

                                    FXMLLoader loader = new FXMLLoader(
                                            getClass().getResource("DetailsSerieController.fxml"));
                                    Parent root = loader.load();
                                    DetailsSerieController controller = loader.getController();
                                    controller.setData(serie, series);
                                    controller.setMainApp(mainApp);

                                    Scene scene = new Scene(root);
                                    mainApp.primaryStage.setScene(scene);
                                    mainApp.primaryStage.show();
                                } catch (IOException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        }

                    });
                    imagenes.getChildren().add(poster);
                } catch (IllegalArgumentException e) {
                    Image image = new Image("file:src/calendarioSeries/resources/no-image.png");
                    ImageView poster = new ImageView();
                    ContextMenu menu = new ContextMenu();
                    MenuItem delete = new MenuItem("Eliminar");
                    delete.setId(serie.getId());
                    delete.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent event) {
                            menu.hide();
                            MenuItem clicked = (MenuItem) event.getSource();
                            String toDelete = clicked.getId();
                            for (Serie serie : series) {
                                if (serie.getId().equals(toDelete)) {
                                    series.remove(serie);
                                    populateImagenes();
                                    showDetallesMes(mesActual);
                                }
                            }
                            event.consume();
                        }
                    });

                    menu.getItems().add(delete);

                    poster.setId(serie.getTitulo());
                    poster.setImage(image);
                    poster.setCache(true);
                    //poster.setPreserveRatio(true);
                    poster.setFitWidth(210);
                    poster.setFitHeight(300);
                    poster.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                        @Override
                        public void handle(ContextMenuEvent event) {
                            menu.show(poster, event.getScreenX(), event.getScreenY());
                            event.consume();
                        }
                    });
                    Text text = new Text(serie.getTitulo());
                    text.getStyleClass().add("label");
                    StackPane pane = new StackPane();
                    pane.getChildren().addAll(poster, text);

                    imagenes.getChildren().add(pane);
                } finally {
                    rellenarArchivo();
                }
            }
        }
    });

}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.GroupTreeItem.java

/**
 * Recursive method to add a grouping at a given path.
 *
 * @param path Full path (or subset not yet added) to add
 * @param g Group to add/*from w w w .j av  a2 s  . co m*/
 * @param tree True if it is part of a tree (versus a list)
 */
void insert(List<String> path, DrawableGroup g, Boolean tree) {
    if (tree) {
        // Are we at the end of the recursion?
        if (path.isEmpty()) {
            getValue().setGroup(g);
        } else {
            String prefix = path.get(0);

            GroupTreeItem prefixTreeItem = childMap.get(prefix);
            if (prefixTreeItem == null) {
                final GroupTreeItem newTreeItem = new GroupTreeItem(prefix, null, comp);

                prefixTreeItem = newTreeItem;
                childMap.put(prefix, prefixTreeItem);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (getChildren()) {
                            getChildren().add(newTreeItem);
                        }
                    }
                });

            }

            // recursively go into the path
            prefixTreeItem.insert(path.subList(1, path.size()), g, tree);
        }
    } else {
        //flat list
        GroupTreeItem treeItem = childMap.get(StringUtils.join(path, "/"));
        if (treeItem == null) {
            final GroupTreeItem newTreeItem = new GroupTreeItem(StringUtils.join(path, "/"), g, comp);
            newTreeItem.setExpanded(true);
            childMap.put(path.get(0), newTreeItem);

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    synchronized (getChildren()) {
                        getChildren().add(newTreeItem);
                        if (comp != null) {
                            FXCollections.sort(getChildren(), comp);
                        }
                    }
                }
            });
        }
    }
}

From source file:org.springsource.ide.eclipse.commons.browser.javafx.JavaFxBrowserManager.java

/**
 * Calls Javascript functions <i>to</i> the browser, refreshing the browser
 * when all calls have completed./*w ww  . ja  va2 s .  c o  m*/
 * @param functions
 */
public void callOnBrowser(final Collection<IEclipseToBrowserFunction> functions) {
    final Collection<IEclipseToBrowserFunction> waitingFunctions = new CopyOnWriteArrayList<IEclipseToBrowserFunction>();
    IEclipseToBrowserFunction.Callback callback = new IEclipseToBrowserFunction.Callback() {
        @Override
        public void ready(IEclipseToBrowserFunction function) {
            waitingFunctions.remove(function);
            if (waitingFunctions.isEmpty() && !disposed) {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        JSObject js = (JSObject) getEngine().executeScript("window");
                        for (IEclipseToBrowserFunction provider : functions) {
                            js.call(provider.getFunctionName(), (Object[]) provider.getArguments());
                        }
                        getView().requestLayout();
                        getView().setVisible(true);
                        if (DEBUG) {
                            printPageHtml();
                        }
                    }
                });
            }
        }
    };
    for (IEclipseToBrowserFunction function : functions) {
        if (!function.isReady()) {
            waitingFunctions.add(function);
            function.setCallback(callback);
        }
    }
    callback.ready(null);
}

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

private void quit() {
    Platform.runLater(() -> {
        WebDavServer.getInstance().stop();
        CLEAN_SHUTDOWN_PERFORMER.run();/* ww w.  jav a2  s . c o m*/
        Settings.save();
        Platform.exit();
        System.exit(0);
    });
}