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.properned.application.SystemController.java

public void loadFileList(File selectedFile) {
    Platform.runLater(new Runnable() {

        @Override// w w w.  j a  va 2 s  .co m
        public void run() {
            logger.info("Load the file list associated to '" + selectedFile.getAbsolutePath() + "'");

            if (MultiLanguageProperties.getInstance().getIsDirty()) {
                ButtonType result = askForSave();
                if (result.getButtonData() == ButtonData.CANCEL_CLOSE) {
                    // The file must not be loaded
                    return;
                }
            }
            Preferences.getInstance().setLastPathUsed(selectedFile.getAbsolutePath());
            String fileName = selectedFile.getName();
            String baseNameTemp = fileName.substring(0, fileName.lastIndexOf("."));

            if (fileName.contains("_")) {
                baseNameTemp = fileName.substring(0, fileName.indexOf("_"));
            }
            final String baseName = baseNameTemp;

            List<PropertiesFile> fileList = Arrays
                    .asList(selectedFile.getParentFile().listFiles(new FileFilter() {
                        @Override
                        public boolean accept(File pathname) {
                            return pathname.isFile() && pathname.getName().startsWith(baseName)
                                    && pathname.getName().endsWith(".properties");
                        }
                    })).stream().map(new Function<File, PropertiesFile>() {
                        @Override
                        public PropertiesFile apply(File t) {
                            String language = "";
                            if (t.getName().contains("_")) {
                                language = t.getName().substring(t.getName().indexOf("_") + 1,
                                        t.getName().lastIndexOf("."));
                            }
                            return new PropertiesFile(t.getAbsolutePath(), baseName, new Locale(language));
                        }
                    }).collect(Collectors.<PropertiesFile>toList());

            try {
                multiLanguageProperties.loadFileList(baseName, fileList);
                Preferences.getInstance().addFileToRecentFileList(selectedFile.getAbsolutePath());
                Properned.getInstance().getPrimaryStage().getScene()
                        .setOnKeyReleased(new EventHandler<KeyEvent>() {
                            @Override
                            public void handle(KeyEvent event) {
                                if (event.getCode() == KeyCode.S && event.isControlDown()) {
                                    logger.info("CTRL-S detected");
                                    save();
                                    event.consume();
                                }
                            }
                        });
            } catch (IOException e) {
                Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.load"), e);
            }
        }
    });
}

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

@FXML
void onlineStartButtonOnAction(ActionEvent event) {
    hideOnlineMenu();/*  www.ja  va 2  s  .co  m*/
    setLoadingStatusText("Searching for an opponent...", true);
    showLoadingScreen();
    String clientIdentifier = onlineMyUsername.getText();
    if (clientIdentifier.equals("")) {
        clientIdentifier = onlineMyUsername.getPromptText();
    }

    String desiredOpponentIdentifier = null;
    if (!onlineDesiredOpponentName.getText().equals("")) {
        desiredOpponentIdentifier = onlineDesiredOpponentName.getText();
    }

    KryoGameConnections.requestOpponent(clientIdentifier, desiredOpponentIdentifier,
            new OnOpponentFoundRunnable() {
                private boolean inversePlayerOrder = true;

                @Override
                public void run(OnlineMultiplayerRequestOpponentResponse response) {
                    if (response.getResponseCode() == ResponseCode.WaitForOpponent) {
                        inversePlayerOrder = false;
                    } else {
                        Main.this.setLoadingStatusText("Waiting for the opponent...");
                        Platform.runLater(() -> Main.this.startGame(response.getOpponentIdentifier(),
                                inversePlayerOrder));
                    }
                }
            }, () -> Platform.runLater(
                    () -> showErrorMessage("The game was cancelled.", "Disconnected from the server.")));
}

From source file:org.sleuthkit.autopsy.imageanalyzer.ImageAnalyzerController.java

/**
 * reset the state of the controller (eg if the case is closed)
 *///from  ww w. ja  v  a2 s .c  om
public synchronized void reset() {
    LOGGER.info("resetting ImageAnalyzerControler to initial state.");
    selectionModel.clearSelection();
    Platform.runLater(() -> {
        historyManager.clear();
    });

    Toolbar.getDefault().reset();
    groupManager.clear();
    if (db != null) {
        db.closeDBCon();
    }
    db = null;
}

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

private void restartWorker() {
    if (dbWorkerThread != null) {
        // Keep using the same worker thread if one exists
        return;/*from w  w w  .  j a va  2 s  . c om*/
    }
    dbWorkerThread = new DBWorkerThread();

    getFileUpdateQueueSizeProperty().addListener((Observable o) -> {
        Platform.runLater(this::updateRegroupDisabled);
    });

    Thread th = new Thread(dbWorkerThread);
    th.setDaemon(false); // we want it to go away when it is done
    th.start();
}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private void urlTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_urlTextFieldKeyPressed
    //System.out.println("evt.getKeyCode() == "+evt.getKeyCode());
    if (webEngine != null && evt.getKeyCode() == 10) {
        final String u = toURL(urlTextField.getText());
        Platform.runLater(new Runnable() {
            @Override/*w  ww. j  a  v a2 s  . com*/
            public void run() {
                urlTextField.setBackground(Color.WHITE);
                webEngine.load(u);
            }
        });
    }
}

From source file:com.github.drbookings.ui.controller.MainController.java

@FXML
private void handleButtonAddBooking(final ActionEvent event) {
    Platform.runLater(() -> showAddBookingDialog());
}

From source file:com.vladsch.idea.multimarkdown.editor.MultiMarkdownFxPreviewEditor.java

/**
 * Build a new instance of {@link MultiMarkdownFxPreviewEditor}.
 *
 * @param project the {@link Project} containing the document
 * @param doc     the {@link Document} previewed in this editor.
 *//*from w ww  . jav a  2 s  .c  o  m*/
public MultiMarkdownFxPreviewEditor(@NotNull final Project project, @NotNull Document doc, boolean isRawHtml) {
    this.isRawHtml = isRawHtml;
    this.document = doc;
    this.project = project;
    this.isWikiDocument = isWikiDocument(document);
    containingFile = FileDocumentManager.getInstance().getFile(document);
    resolver = containingFile == null ? null : new GitHubLinkResolver(containingFile, project);

    // Listen to the document modifications.
    this.document.addDocumentListener(new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent e) {
            delayedHtmlPreviewUpdate(false);
        }
    });

    // Listen to settings changes
    MultiMarkdownGlobalSettings.getInstance()
            .addListener(globalSettingsListener = new MultiMarkdownGlobalSettingsListener() {
                public void handleSettingsChanged(@NotNull final MultiMarkdownGlobalSettings newSettings) {
                    if (project.isDisposed())
                        return;
                    processor = null;
                    updateEditorTabIsVisible();
                    updateLinkRenderer();
                    delayedHtmlPreviewUpdate(true);
                    checkNotifyUser();
                }
            });

    MultiMarkdownProjectComponent projectComponent = MultiMarkdownPlugin.getProjectComponent(project);
    if (projectComponent != null) {
        projectComponent.addListener(projectFileListener = new ReferenceChangeListener() {
            @Override
            public void referenceChanged(@Nullable String name) {
                if (project.isDisposed())
                    return;
                delayedHtmlPreviewUpdate(false);
            }
        });
    }

    project.getMessageBus().connect(this).subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
        @Override
        public void enteredDumbMode() {
        }

        @Override
        public void exitDumbMode() {
            // need to re-evaluate class link accessibility
            if (project.isDisposed())
                return;
            delayedHtmlPreviewUpdate(false);
        }
    });

    updateLinkRenderer();

    if (isRawHtml) {
        jEditorPane = null;
        jfxPanel = null;
        webView = null;
        webEngine = null;
        Language language = Language.findLanguageByID("HTML");
        FileType fileType = language != null ? language.getAssociatedFileType() : null;
        Document myDocument = EditorFactory.getInstance().createDocument("");
        myTextViewer = (EditorImpl) EditorFactory.getInstance().createViewer(myDocument, project);
        if (fileType != null)
            myTextViewer.setHighlighter(
                    EditorHighlighterFactory.getInstance().createEditorHighlighter(project, fileType));
    } else {
        // Setup the editor pane for rendering HTML.
        myTextViewer = null;
        jEditorPane = new JPanel(new BorderLayout(), false);
        jfxPanel = new JFXPanel(); // initializing javafx
        jEditorPane.add(jfxPanel, BorderLayout.CENTER);
        Platform.setImplicitExit(false);

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                if (project.isDisposed())
                    return;

                webView = new WebView();
                webEngine = webView.getEngine();

                anchorPane = new AnchorPane();
                AnchorPane.setTopAnchor(webView, 0.0);
                AnchorPane.setLeftAnchor(webView, 0.0);
                AnchorPane.setBottomAnchor(webView, 0.0);
                AnchorPane.setRightAnchor(webView, 0.0);
                anchorPane.getChildren().add(webView);
                jfxPanel.setScene(new Scene(anchorPane));

                webEngine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
                    @Override
                    public WebEngine call(PopupFeatures config) {
                        // return a web engine for the new browser window or null to block popups
                        return null;
                    }
                });

                addStateChangeListener();
            }
        });
    }

    checkNotifyUser();
}

From source file:org.sleuthkit.autopsy.imageanalyzer.ImageAnalyzerController.java

public void setStacks(StackPane fullUIStack, StackPane centralStack) {
    fullUIStackPane = fullUIStack;/*from  w w  w  .  j a  v  a  2 s  .c om*/
    this.centralStackPane = centralStack;
    Platform.runLater(this::checkForGroups);
}

From source file:com.github.drbookings.ui.controller.MainController.java

@FXML
private void handleButtonGoHome(final ActionEvent event) {
    Platform.runLater(() -> scrollToToday());
}

From source file:editeurpanovisu.EquiCubeDialogController.java

public Task tskTraitement() {
    return new Task() {
        @Override// w  w  w  .  j a v a  2  s .c  om
        protected Object call() throws Exception {
            apTransformations.setCursor(Cursor.WAIT);
            Platform.runLater(() -> {
                for (int ij = 0; ij < lvListeFichier.getItems().size(); ij++) {
                    String strNomFich1 = (String) lvListeFichier.getItems().get(ij);
                    lvListeFichier.getItems().set(ij, "A Traiter => " + strNomFich1);
                }
            });
            updateProgress(0.0001f, lvListeFichier.getItems().size());
            for (int i1 = 0; i1 < lvListeFichier.getItems().size(); i1++) {
                Thread.sleep(200);
                updateMessage("Traitement en cours " + (i1 + 1) + "/" + lvListeFichier.getItems().size());
                String strNomFich = ((String) lvListeFichier.getItems().get(i1)).split("> ")[1];
                final int ii = i1;
                Platform.runLater(() -> {
                    lvListeFichier.getItems().set(ii, "Traitement en cours => " + strNomFich);
                });
                traiteFichier(strNomFich, i1);
                Thread.sleep(100);

                updateProgress(i1 + 1, lvListeFichier.getItems().size());
                Platform.runLater(() -> {
                    lvListeFichier.getItems().set(ii, "Trait => " + strNomFich);
                });
                Thread.sleep(100);
            }
            apTransformations.setCursor(Cursor.DEFAULT);
            return true;
        }

        @Override
        protected void succeeded() {
            super.succeeded();
            pbBarreAvancement.progressProperty().unbind();
            lblTermine.textProperty().unbind();
            lblTermine.setText("Traitement Termin");
            pbBarreAvancement.setProgress(0.001d);
            pbBarreAvancement.setVisible(false);
            pbBarreImage.setVisible(false);
            bTraitementEffectue = true;
            lblDragDropE2C.setVisible(true);
        }

    };
}