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:ninja.eivind.hotsreplayuploader.files.tempwatcher.RecursiveTempWatcherTest.java

@After
public void tearDown() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> {
        if (tempWatcher.cancel()) {
            latch.countDown();//from   w ww . j av  a2  s .c o m
        }
    });
    if (!latch.await(1, TimeUnit.SECONDS)) {
        fail("Service failed to stop");
    }
    // give watchers some time to wind down recursively
    Thread.sleep(1000L);
    cleanupRecursive(directories.getRoot());
}

From source file:com.properned.model.MultiLanguageProperties.java

public void setBaseName(String baseName) {
    logger.info("new baseName : " + baseName);
    Platform.runLater(new Runnable() {
        @Override/*from   w w w.j  av a2s .  c o  m*/
        public void run() {
            MultiLanguageProperties.this.baseName.set(baseName);
        }
    });
}

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

public EditSchema(Stage stage) {
    this.stage = stage;

    if (MainApplication.icon != null)
        stage.getIcons().add(MainApplication.icon);

    menuBar = new MenuBar();
    menuBar.setUseSystemMenuBar(true);/*from w  ww .j ava  2 s.co  m*/
    menuBar.getMenus().add(menuFile = new Menu("_File"));
    menuBar.getMenus().add(menuEdit = new Menu("_Edit"));
    menuBar.getMenus().add(menuValue = new Menu("_Value"));
    menuBar.getMenus().add(menuView = new Menu("Vie_w"));
    createMenuItems();

    treeRoot = new TreeItem<>(new Branch(this));
    treeView = new TreeView<>(treeRoot);
    treeView.setEditable(true);
    treeView.setCellFactory(p -> new HierarchyTreeCell());
    treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldVal, newVal) -> {
        if (oldVal != null)
            pullDetail(oldVal);
        if (newVal != null)
            pushDetail(newVal);
    });
    treeView.focusedProperty()
            .addListener((val, oldValue, newValue) -> Platform.runLater(() -> maybeUpdateTree()));

    detail = new DetailPane(this);

    StackPane sp1 = new StackPane(), sp2 = new StackPane();
    sp1.getChildren().add(treeView);
    sp2.getChildren().add(detail);

    splitter = new SplitPane();
    splitter.setOrientation(Orientation.HORIZONTAL);
    splitter.getItems().addAll(sp1, sp2);
    splitter.setDividerPositions(0.4, 1.0);

    progBar = new ProgressBar();
    progBar.setMaxWidth(Double.MAX_VALUE);

    root = new BorderPane();
    root.setTop(menuBar);
    root.setCenter(splitter);
    root.setBottom(progBar);

    BorderPane.setMargin(progBar, new Insets(2, 2, 2, 2));

    Scene scene = new Scene(root, 1000, 800, Color.WHITE);

    stage.setScene(scene);

    treeView.setShowRoot(false);
    treeRoot.getChildren().add(treeTemplate = new TreeItem<>(new Branch(this, "Template")));
    treeRoot.getChildren().add(treeAssays = new TreeItem<>(new Branch(this, "Assays")));
    treeTemplate.setExpanded(true);
    treeAssays.setExpanded(true);

    rebuildTree();

    Platform.runLater(() -> treeView.getFocusModel().focus(treeView.getSelectionModel().getSelectedIndex())); // for some reason it defaults to not the first item

    stage.setOnCloseRequest(event -> {
        if (!confirmClose())
            event.consume();
    });

    updateTitle();

    // loading begins in a background thread, and is updated with a status bar
    Vocabulary.Listener listener = new Vocabulary.Listener() {
        public void vocabLoadingProgress(Vocabulary vocab, float progress) {
            Platform.runLater(() -> {
                progBar.setProgress(progress);
                if (vocab.isLoaded())
                    root.getChildren().remove(progBar);
            });
        }

        public void vocabLoadingException(Exception ex) {
            ex.printStackTrace();
        }
    };
    Vocabulary.globalInstance(listener);
}

From source file:net.rptools.gui.GuiBuilder.java

/** Final GUI show. */
@ThreadPolicy(ThreadPolicy.ThreadId.MAIN)
public void showGUI() {
    Platform.runLater(new Runnable() {
        @Override//from  w w  w . j  a  v  a2  s.c  o m
        public void run() {
            rootStage.setTitle("Maptool");
            final Scene rootScene = new Scene(rootRegion);
            rootScene.getStylesheets().add(StylesheetMonitor.STYLESHEET);
            rootStage.setScene(rootScene);
            component.setRootScene(rootScene);
            rootStage.show();
            component.stopSplasher();
        }
    });
}

From source file:org.cryptomator.ui.controllers.WelcomeController.java

private void compareVersions(final Map<String, String> latestVersions) {
    final String latestVersion;
    if (SystemUtils.IS_OS_MAC_OSX) {
        latestVersion = latestVersions.get("mac");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        latestVersion = latestVersions.get("win");
    } else if (SystemUtils.IS_OS_LINUX) {
        latestVersion = latestVersions.get("linux");
    } else {//from w  w w  .java  2 s. c  o m
        // no version check possible on unsupported OS
        return;
    }
    final String currentVersion = ApplicationVersion.orElse(null);
    LOG.debug("Current version: {}, lastest version: {}", currentVersion, latestVersion);
    if (currentVersion != null && semVerComparator.compare(currentVersion, latestVersion) < 0) {
        final String msg = String.format(localization.getString("welcome.newVersionMessage"), latestVersion,
                currentVersion);
        Platform.runLater(() -> {
            this.updateLink.setText(msg);
            this.updateLink.setVisible(true);
            this.updateLink.setDisable(false);
        });
    }
}

From source file:de.digiway.rapidbreeze.client.infrastructure.cnl.ClickAndLoadHandler.java

private boolean addLinks(HttpServletRequest request) throws IOException {
    String passwords = null;//  w  ww  .ja  v  a 2 s.c o m
    String source = null;
    String jk = null;
    String crypted = null;
    for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
        String value = entry.getValue()[0];
        switch (entry.getKey().toLowerCase()) {
        case "passwords":
            passwords = value;
            break;
        case "source":
            source = value;
            break;
        case "jk":
            jk = value;
            break;
        case "crypted":
            crypted = value;
            break;
        }
    }

    if (jk != null) {
        Context cx = null;
        try {
            cx = ContextFactory.getGlobal().enterContext();
            Scriptable scope = cx.initStandardObjects();
            String fun = jk + "  f()";
            Object result = cx.evaluateString(scope, fun, "<cmd>", 1, null);
            byte[] key = hexStringToByteArray(Context.toString(result));
            byte[] decoded = Base64.decode(crypted);
            String decryptedUrls = decrypt(decoded, key);
            String[] split = StringUtils.split(decryptedUrls, "\n");
            if (split.length > 0) {
                List<URL> urls = new ArrayList<>();
                for (String url : split) {
                    String trimmed = url.trim();
                    if (!trimmed.isEmpty()) {
                        urls.add(new URL(url));
                    }
                }
                LinkBundle lb = new LinkBundle(urls);
                RRB.get().send(BusEvents.ADD_LINK_BUNDLE, lb);
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        RRB.get().send(BusEvents.OPEN_DOWNLOAD_COLLECTOR_WINDOW);
                    }
                });
                return true;
            }
        } finally {
            if (cx != null) {
                Context.exit();
            }
        }
    }

    return false;
}

From source file:org.pdfsam.ui.selection.single.SingleSelectionPane.java

private void initContextMenu() {
    MenuItem infoItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Document properties"),
            AwesomeIcon.INFO);//from w  w  w . j av  a2  s . c  o  m
    infoItem.setOnAction(e -> Platform.runLater(() -> {
        eventStudio().broadcast(new ShowPdfDescriptorRequest(descriptor));
    }));

    MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set output"),
            AwesomeIcon.PENCIL_SQUARE_ALT);
    setDestinationItem.setOnAction(e -> {
        eventStudio().broadcast(new SetDestinationRequest(descriptor.getFile().getParentFile()),
                getOwnerModule());
    });

    MenuItem openFileItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open"), AwesomeIcon.FILE_ALT);
    openFileItem.setOnAction(e -> {
        eventStudio().broadcast(new OpenFileRequest(descriptor.getFile()));
    });

    MenuItem openFolderItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open Folder"),
            AwesomeIcon.FOLDER_OPEN);
    openFolderItem.setOnAction(e -> {
        eventStudio().broadcast(new OpenFileRequest(descriptor.getFile().getParentFile()));
    });

    field.getTextField().setContextMenu(new ContextMenu(setDestinationItem, new SeparatorMenuItem(), infoItem,
            openFileItem, openFolderItem));
}

From source file:eu.ggnet.dwoss.redtape.document.DocumentUpdateView.java

private void initFxComponents() {
    final JFXPanel jfxp = new JFXPanel();
    positionPanelFx.add(jfxp, BorderLayout.CENTER);

    Platform.runLater(() -> {
        BorderPane pane = new BorderPane();
        Scene scene = new Scene(pane, Color.ALICEBLUE);

        positionsFxList = new ListView<>();
        positionsFxList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        positionsFxList.setCellFactory(new PositionListCell.Factory());
        positionsFxList.setItems(positions);
        positionsFxList.setOnMouseClicked((mouseEvent) -> {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY) && mouseEvent.getClickCount() == 2) {
                if (isChangeAllowed()) {
                    controller.editPosition(positionsFxList.getSelectionModel().getSelectedItem());
                    positionsFxList.refresh();
                } else {
                    Alert.show("nderung an Positionen ist nicht erlaubt.");
                }/*from   ww  w. j  a v  a2 s .  c om*/
            }
        });

        pane.setCenter(positionsFxList);
        jfxp.setScene(scene);
    });
}

From source file:org.sleuthkit.autopsy.imagegallery.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//w  w w .ja  va  2  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(() -> {
                    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(() -> {
                synchronized (getChildren()) {
                    getChildren().add(newTreeItem);
                    if (comp != null) {
                        FXCollections.sort(getChildren(), comp);
                    }
                }
            });
        }
    }
}

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

@FXML
private void initialize() {
    tagImageTiles.addAll(Arrays.asList(tag1, tag2, tag3, tag4, tag5));

    wikipediaInfoPane = new WikipediaInfoPane(wikipediaService);
    HBox.setHgrow(wikipediaInfoPane, Priority.ALWAYS);
    wikipediaInfoPaneContainer.getChildren().addAll(wikipediaInfoPane, wikipediaPlaceholder);

    wikipediaPlaceholder.setGlyphSize(80);
    wikipediaInfoPaneContainer.setAlignment(Pos.CENTER);
    wikipediaPlaceholder.getStyleClass().addAll("wikipedia-placeholder");
    wikipediaInfoPane.managedProperty().bind(wikipediaInfoPane.visibleProperty());
    wikipediaPlaceholder.visibleProperty().bind(wikipediaInfoPane.visibleProperty().not());
    wikipediaInfoPane.setVisible(false);

    journeyPlaceList.setOnJourneySelected(this::handleJourneySelected);
    journeyPlaceList.setOnPlaceSelected(this::handlePlaceSelected);
    journeyPlaceList.setOnAllPlacesSelected(this::handleAllPlacesSelected);

    // give each row and each column in the grid the same size
    ColumnConstraints column1 = new ColumnConstraints();
    column1.setPercentWidth(25);/*w  w  w.j  a v a  2s .  c o m*/
    ColumnConstraints column2 = new ColumnConstraints();
    column2.setPercentWidth(25);
    ColumnConstraints column3 = new ColumnConstraints();
    column3.setPercentWidth(25);
    ColumnConstraints column4 = new ColumnConstraints();
    column4.setPercentWidth(25);
    gridPane.getColumnConstraints().addAll(column1, column2, column3, column4);

    RowConstraints row1 = new RowConstraints();
    row1.setPercentHeight(33);
    RowConstraints row2 = new RowConstraints();
    row2.setPercentHeight(33);
    RowConstraints row3 = new RowConstraints();
    row3.setPercentHeight(33);
    gridPane.getRowConstraints().addAll(row1, row2, row3);

    clusterService.subscribeJourneyChanged((journey) -> scheduler
            .schedule(() -> Platform.runLater(this::reloadJourneys), 2, TimeUnit.SECONDS));

    clusterService.subscribePlaceChanged(
            (place) -> scheduler.schedule(() -> Platform.runLater(this::reloadJourneys), 2, TimeUnit.SECONDS));

    photoService.subscribeCreate(addBuffer::add);

    reloadJourneys();
}