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.mskcc.shenkers.view.IntervalViewNGTest.java

@Test
public void testGenericStackedIntervalView() throws InterruptedException {
    List<Pair<Integer, Integer>> intervals = Arrays.asList(new Pair(0, 1), new Pair(1, 2), new Pair(2, 3),
            new Pair(3, 4), new Pair(4, 5), new Pair(5, 6));
    List<Pane> nodes = intervals.stream().map(i -> new RectangleIntervalNode()).collect(Collectors.toList());
    GenericStackedIntervalView p = new GenericStackedIntervalView(0, 6);
    p.setData(intervals, nodes);//from   w  ww.j av  a  2  s  . c  o m

    ScrollPane sp = new ScrollPane(p);
    ScrollBar sb = new ScrollBar();
    sb.maxProperty().bind(sp.vmaxProperty());
    sb.minProperty().bind(sp.vminProperty());
    sb.visibleAmountProperty().bind(sp.heightProperty().divide(p.prefHeightProperty()));
    sb.setOrientation(Orientation.VERTICAL);
    sp.vvalueProperty().bindBidirectional(sb.valueProperty());
    HiddenSidesPane hsp = new HiddenSidesPane();
    hsp.setContent(sp);
    hsp.setRight(sb);
    sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    p.setOrientation(Orientation.VERTICAL);
    p.prefTileHeightProperty().bind(new SimpleDoubleProperty(40));
    //        p.minHeightProperty().bind(new SimpleDoubleProperty(20).multiply(Bindings.size(p.getChildren())));
    p.prefTileWidthProperty().bind(sp.widthProperty());
    p.prefHeightProperty()
            .bind(new SimpleDoubleProperty(50).multiply(Bindings.size(p.getChildren())).subtract(10));
    p.prefWidthProperty().bind(sp.widthProperty());
    sp.setPadding(Insets.EMPTY);
    p.setVgap(10);

    CountDownLatch l = new CountDownLatch(1);
    Platform.runLater(() -> {

        Stage stage = new Stage();
        stage.setOnHidden(e -> {
            l.countDown();
        });
        Scene scene = new Scene(hsp, 300, 300, Color.GRAY);
        stage.setTitle("GenericStackedPaneTest");
        stage.setScene(scene);
        stage.show();

    });
    l.await();
}

From source file:com.tesshu.subsonic.client.sample4_music_andmovie.StreamDownloadAndPlayWithThreadApplication.java

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

    Search2Controller search2 = context.getBean(Search2Controller.class);

    StreamController streamController = context.getBean(StreamController.class);

    SuccessObserver callback = context.getBean(SuccessObserver.class);

    SearchResult2 result2 = search2.get("e", null, null, null, null, 1, null, null);

    List<Child> songs = result2.getSongs();

    File tmpDirectory = new File(tmpPath);
    tmpDirectory.mkdir();/* w w  w .  j av  a  2s . co m*/

    int maxBitRate = 256;

    Child song = songs.get(0);

    new Thread(new Runnable() {
        public void run() {
            try {

                streamController.stream(song, maxBitRate, format, null, null, null, null,

                        (subject, inputStream, contentLength) -> {

                            File dir = new File(
                                    tmpPath + "/" + song.getPath().replaceAll("([^/]+?)?$", StringUtils.EMPTY));
                            dir.mkdirs();

                            file = new File(tmpPath + "/"
                                    + song.getPath().replaceAll("([^.]+?)?$", StringUtils.EMPTY) + format);

                            try {

                                FileOutputStream fos = new FileOutputStream(file);
                                BufferedInputStream reader = new BufferedInputStream(inputStream);

                                byte buf[] = new byte[256];
                                int len;
                                while ((len = reader.read(buf)) != -1) {
                                    fos.write(buf, 0, len);
                                }
                                fos.flush();
                                fos.close();
                                reader.close();
                                inputStream.close();

                                LOG.info("download finished");

                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }, callback);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();

    LOG.info("download thread start");

    new Thread(new Runnable() {
        public void run() {
            while (file == null || file.getPath() == null) {
                LOG.info("wait file writing.");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                String path = Paths.get(file.getPath()).toUri().toString();
                Group root = new Group();
                Scene scene = new Scene(root, 640, 480);
                Media media = new Media(path);
                MediaPlayer player = new MediaPlayer(media);
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            while (MediaPlayer.Status.READY != player.getStatus()) {
                                LOG.info(player.getStatus() + " : " + path);
                                LOG.info(media.errorProperty());
                                Thread.sleep(1000);
                                if (MediaPlayer.Status.PLAYING == player.getStatus()) {
                                    LOG.info(player.getStatus() + " : " + path);
                                    break;
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();

                MediaView view = new MediaView(player);
                ((Group) scene.getRoot()).getChildren().add(view);

                Platform.runLater(() -> {
                    stage.setScene(scene);
                    stage.show();
                    player.play();
                });

            }
        }
    }).start();

}

From source file:org.sleuthkit.autopsy.imagegallery.gui.MetaDataPane.java

@Override
public void setFile(Long fileID) {
    this.fileID = fileID;

    if (fileID == null) {

        Platform.runLater(() -> {
            imageView.setImage(null);/*from  w w w .jav a 2  s .co  m*/
            tableView.getItems().clear();
            getCategoryBorderRegion().setBorder(null);

        });
    } else {
        try {
            file = controller.getFileFromId(fileID);
            updateUI();
        } catch (TskCoreException ex) {
            LOGGER.log(Level.WARNING, "Failed to get drawable file from ID", ex);
        }
    }
}

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

/**
 * Show a given BufferedImage in the UI.
 *
 * @param bufferedImage The image to be shown in the UI
 * @param imageView     The JavaFX ImageView element in which the BufferedImage to be shown.
 *//*from   www  .j  av a  2s  . c om*/
private static void showImageInUI(final BufferedImage bufferedImage, final ImageView imageView) {
    Platform.runLater(new Runnable() {
        public void run() {
            Image loadedImage = SwingFXUtils.toFXImage(bufferedImage, null);
            imageView.setImage(loadedImage);
            imageView.setPreserveRatio(true);
            imageView.setSmooth(true);
            imageView.setCache(true);
        }
    });
}

From source file:org.sleuthkit.autopsy.imagegallery.ImageGalleryController.java

@ThreadConfined(type = ThreadConfined.ThreadType.ANY)
void setStale(Boolean b) {
    Platform.runLater(() -> {
        stale.set(b);/*from  www  . j a  v  a  2  s  . com*/
    });
    if (Case.isCaseOpen()) {
        new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(),
                PerCaseProperties.STALE, b.toString());
    }
}

From source file:de.iew.stagediver.fx.eventbus.services.impl.EventBusImpl.java

protected void notifyIfInPlatformThread(AnnotatedObserver observer, Event event) throws Throwable {
    if (observer.isNotifyInPlatformThread()) {
        Platform.runLater(new JavaFXPlatformRunnable(observer, event));
    }/*from   w  w w . ja  v a 2s.c  o m*/
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.MetaDataPane.java

@Override
public void setFile(Long fileID) {
    this.fileID = fileID;

    if (fileID == null) {

        Platform.runLater(() -> {
            imageView.setImage(null);//from ww w .j av a2  s . c o  m
            tableView.getItems().clear();
            getBorderable().setBorder(null);

        });
    } else {
        try {
            file = controller.getFileFromId(fileID);
            updateUI();

            file.categoryProperty().addListener(new ChangeListener<Category>() {
                @Override
                public void changed(ObservableValue<? extends Category> ov, Category t, final Category t1) {
                    updateUI();
                }
            });
        } catch (TskCoreException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private void loadImages(File dir) {
    // Clear Details panel
    clearDetails();/*from w  ww .j  a va  2  s.  c  o m*/

    currentDirectory = dir;
    File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER);

    Task<Void> task = new Task<Void>() {
        @Override
        public Void call() {
            for (File file : files) {
                Path filePath = file.toPath();

                if (loadOverlaysThread.isInterrupted()) {
                    Platform.runLater(() -> overlayViewFlowPane.getChildren().clear());
                    break;
                }

                try {
                    ToggleButton overlayButton = new ToggleButton();
                    ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath);

                    overlayButton.getStyleClass().add("overlay-toggle-button");
                    overlayButton.setGraphic(imageViewNode);
                    overlayButton.setUserData(file);
                    overlayButton.setToggleGroup(overlayToggleGroup);

                    overlayButton.addEventHandler(ActionEvent.ACTION, event -> {
                        // No modifier keys used so add toggle group back to all buttons
                        resetToggleGroup();

                        // Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO
                        overlayButton.setSelected(true);

                        // Update the Details panel with the last selected overlay
                        File overlayFile = (File) overlayButton.getUserData();
                        updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(),
                                overlayButton.isSelected());

                        // Consume the event, no more logic needed
                        event.consume();
                    });

                    overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                            // Allow multiple selections if shortcutKey+left_mouse is pressed
                            if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) {
                                // Update the Details panel with the last selected overlay
                                File overlayFile = (File) overlayButton.getUserData();
                                updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true);

                                // Remove the toggle group to allow multiple toggle button selection
                                overlayButton.setToggleGroup(null);

                                // Select the button
                                overlayButton.setSelected(true);

                                // Consume the event, no more logic needed
                                event.consume();
                            }
                        }
                    });

                    Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton));
                } catch (IOException e) {
                    log.error("Loading image: " + filePath.getFileName(), e);
                }

            }

            return null;
        }
    };

    loadOverlaysThread.interrupt();
    executorService.execute(task);
}

From source file:gisintegration.SimpleSwingBrowser.java

public void loadURL(final String url) {
    Platform.runLater(new Runnable() {
        @Override//from  w  w  w . jav a2s. co  m
        public void run() {
            String tmp = toURL(url);

            if (tmp == null) {
                tmp = toURL("http://" + url);
            }
            engine.load(url);
        }
    });
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

private void handleDeletePhotos(List<Path> paths) {
    LOGGER.debug("deleting {} photos in grid", paths.size());

    Platform.runLater(() -> {
        List<Photo> photos = grid.getPhotos().stream().filter(p -> paths.contains(p.getFile()))
                .collect(Collectors.toList());

        grid.removePhotos(photos);// ww  w .  j a  v a  2 s  .  c  o  m
    });
}