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:gisintegration.SimpleSwingBrowser.java

private void createScene() {
    Platform.runLater(new Runnable() {
        @Override//  w ww  .  j av a 2s. c o m
        public void run() {

            WebView view = new WebView();
            engine = view.getEngine();

            //                engine.titleProperty().addListener(new ChangeListener<String>() {
            //                    @Override
            //                    public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
            //                        SwingUtilities.invokeLater(new Runnable() {
            //                            @Override
            //                            public void run() {
            //                                SimpleSwingBrowser.this.setTitle(newValue);
            //                            }
            //                        });
            //                    }
            //                });

            engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() {
                @Override
                public void handle(final WebEvent<String> event) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            lblStatus.setText(event.getData());
                        }
                    });
                }
            });

            //                engine.locationProperty().addListener(new ChangeListener<String>() {
            //                    @Override
            //                    public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) {
            //                        SwingUtilities.invokeLater(new Runnable() {
            //                            @Override
            //                            public void run() {
            //                                txtURL.setText(newValue);
            //                            }
            //                        });
            //                    }
            //                });

            engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number oldValue,
                        final Number newValue) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setValue(newValue.intValue());
                        }
                    });
                }
            });

            engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {

                public void changed(ObservableValue<? extends Throwable> o, Throwable old,
                        final Throwable value) {
                    if (engine.getLoadWorker().getState() == FAILED) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(panel,
                                        (value != null) ? engine.getLocation() + "\n" + value.getMessage()
                                                : engine.getLocation() + "\nUnexpected error.",
                                        "Loading error...", JOptionPane.ERROR_MESSAGE);
                            }
                        });
                    }
                }
            });

            jfxPanel.setScene(new Scene(view));
        }
    });
}

From source file:gmailclientfx.controllers.InboxController.java

public void fetchInbox() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacPosiljatelj.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    Platform.runLater(() -> {
        inboxTable.setItems(data);/*from   ww  w  .ja  v a2  s  . c  o  m*/
    });
    inboxTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = inboxTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                    stage.show();
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });

    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        int getSeenCount = inbox.getMessageCount();
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.ENVELOPE);
        fp.add(FetchProfileItem.FLAGS);
        fp.add(FetchProfileItem.CONTENT_INFO);
        fp.add("X-mailer");

        MimeMessage[] seenMessages = (MimeMessage[]) inbox
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "INBOX");
            data.add(msg);
        }

        MimeMessage[] unseenMessages = (MimeMessage[]) inbox
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "INBOX");
            data.add(msg);
        }

        inbox.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

private void createLogPanelAppender() {
    WriterAppender appender = new WriterAppender() {
        @Override/*from  w ww  . ja v a 2s . c om*/
        public void append(LoggingEvent event) {
            Platform.runLater(() -> serverLog.appendText(layout.format(event)));
        }
    };
    appender.setName("GuiLogger");
    appender.setLayout(new PatternLayout("%d{HH:mm:ss.SSS} - %m%n"));

    org.apache.log4j.Logger.getRootLogger().addAppender(appender);
}

From source file:deincraftlauncher.IO.download.FTPSync.java

private void downloadServerFiles() {

    FTPConnection.connect();//  ww w.  ja va  2 s . c  om
    FTPConnection.changeDir(FTPDir);

    for (String elem : OnlineFiles) {
        if (!ClientFiles.contains(elem)) {
            if (!elem.contains(".") && !elem.contains(".jar") && !elem.contains(".zip")) {
            } else {
                DownloadFiles.add(elem);
            }
        }
    }
    for (String elem : OnlineFiles) {
        if (!ClientFiles.contains(elem)) {
            try {
                //System.out.println("downloading online file: " + elem);
                downloadFTPFile(elem);
            } catch (IOException ex) {
                Logger.getLogger(FTPSync.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    DownloadHandler.setStartBlocked(false);
    Platform.runLater(() -> {
        pack.setStartState(StartState.Locked);
        pack.setStartText("aktualisiere");
    });
    Platform.runLater(DownloadHandler::start);
}

From source file:com.adobe.ags.curly.model.ActionResult.java

private void setStatus(String key, int responseCode, String statusMessage) {
    Platform.runLater(() -> {
        ((StringProperty) reportRow().get(1)).set(ApplicationState.getMessage(key));
        ((IntegerProperty) reportRow().get(2)).set(responseCode);
        ((StringProperty) reportRow().get(3)).set(statusMessage);
    });//from w  w w.java  2 s.com
}

From source file:pe.edu.system.jcmr.controlador.LoguinController.java

@Override
public void initialize(URL location, ResourceBundle resources) {

    //        dialogFx.show(DialogTransition.RIGHT);

    //       txtUsuario.textProperty().addListener(new ChangeListener<String>() {
    ////  w w  w  .  j  a  va  2  s  . c o m
    //         @Override
    //         public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
    //            
    //            if(newValue.contains(ConstansDomios.COM+" ") || newValue.contains(ConstansDomios.NET+" ") 
    //                  || newValue.contains(ConstansDomios.BIZ+" ")|| newValue.contains(ConstansDomios.ORG+" ")
    //                  || newValue.contains(ConstansDomios.EDU+" ") || newValue.contains(ConstansDomios.INFO+" ")
    //                  || newValue.contains(ConstansDomios.MIL+" ") || newValue.contains(ConstansDomios.GOV+" ")){
    //               txtUsuario.setText(oldValue+";");
    //      
    //            }
    //            
    //         }
    //          
    //       });

    closeLoguin();
    loadIdiomas();
    blockTextField();
    clearMessage();
    Platform.runLater(() -> {
        //               new FadeInRightTransition(lblUserLogin).play();
        new FadeInLeftTransition(lblWelcome).play();
        //               new FadeInLeftTransition1(lblPassword).play();
        new FadeInLeftTransition1(cboIdioma).play();
        new FadeInLeftTransition1(txtUsuario).play();
        new FadeInLeftTransition1(txtPassword).play();
        new FadeInRightTransition(btnSingIn).play();

    });
}

From source file:gui.accessories.GraphPopup.java

private BarChart createBarChartDynamic() {
    SampleTableModel tableModel = new SampleTableModel();
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);/*from   w ww  .  jav a  2s  .  com*/
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    aChart.setAnimated(true);
    tableModel.addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData()
                                .get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return aChart;
}

From source file:de.chaosfisch.uploader.gui.renderer.ProgressNodeRenderer.java

public void setProgress(final double progress) {
    Platform.runLater(new Runnable() {

        @Override//from   w w  w .  j  a v  a  2  s  .  co  m
        public void run() {
            progressBar.setProgress(progress);
        }
    });
}

From source file:net.rptools.image.listeners.TransformHandler.java

/**
 * Resize the selection. When scaling, the drag point difference to before
 * determines the new scale. When snapping,
 * @param phase one of "start", "continue", "end"
 * @param fix fixed point// w w  w .j av a2s. c  o  m
 * @param transformType one of "rotate", "scalex", "scaley", or "scalexy"
 * @param constraints one of "iso", or "free"
 * @param drag drag point
 */
@ThreadPolicy(ThreadPolicy.ThreadId.ANY)
public void transform(final String phase, final Point2D fix, final String transformType,
        final String constraints, final Point2D drag) {
    if (!Platform.isFxApplicationThread()) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                resizeIntern(phase, fix, transformType, constraints, drag);
            }
        });
    } else {
        resizeIntern(phase, fix, transformType, constraints, drag);
    }
}

From source file:org.kordamp.javatrove.example04.view.AppView.java

public Scene createScene() {
    String basename = getClass().getPackage().getName().replace('.', '/') + "/app";
    URL fxml = getClass().getClassLoader().getResource(basename + ".fxml");
    FXMLLoader fxmlLoader = new FXMLLoader(fxml);
    fxmlLoader.setControllerFactory(param -> AppView.this);
    Parent root = null;/* w w  w  . j  a v a  2  s .c  o m*/
    try {
        root = (Parent) fxmlLoader.load();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    organization.textProperty().addListener((observable, oldValue, newValue) -> {
        model.setState(isBlank(newValue) ? DISABLED : READY);
    });

    model.stateProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> {
        switch (newValue) {
        case DISABLED:
            enabled.setValue(false);
            running.setValue(false);
            break;
        case READY:
            enabled.setValue(true);
            running.setValue(false);
            break;
        case RUNNING:
            enabled.setValue(false);
            running.setValue(true);
            break;
        }
    }));

    ObservableList<Repository> items = createJavaFXThreadProxyList(model.getRepositories().sorted());

    repositories.setItems(items);
    EventStreams.sizeOf(items).subscribe(v -> total.setText(String.valueOf(v)));
    organization.textProperty().bindBidirectional(model.organizationProperty());
    bindBidirectional(limit.textProperty(), model.limitProperty(), new NumberStringConverter());
    loadButton.disableProperty().bind(Bindings.not(enabled));
    cancelButton.disableProperty().bind(Bindings.not(running));
    progress.visibleProperty().bind(running);

    Scene scene = new Scene(root);
    scene.getStylesheets().addAll(basename + ".css", "bootstrapfx.css");
    return scene;
}