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:ijfx.ui.display.image.DefaultFXImageDisplay.java

public DefaultFXImageDisplay() {
    super();//from ww w .ja v  a 2  s .c  o m

    publishSubject.observeOn(ImageJFX.getPublishSubjectScheduler()).buffer(1, TimeUnit.SECONDS)
            .subscribe(list -> Platform.runLater(() -> refreshPerSecond.setValue(list.size())));

}

From source file:com.esri.geoevent.clusterSimulator.ui.CertificateCheckerDialog.java

@Override
public boolean allowConnection(final X509Certificate[] chain) {
    if (trustedCerts.contains(chain[0])) {
        return true;
    }//w  ww  . j  a  va  2 s  . c  o  m
    final ArrayBlockingQueue<Boolean> responseQueue = new ArrayBlockingQueue<Boolean>(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                final Stage dialog = new Stage();
                dialog.initModality(Modality.APPLICATION_MODAL);
                dialog.initOwner(MainApplication.primaryStage);
                dialog.setTitle("Certificate Check");
                FXMLLoader loader = new FXMLLoader(getClass().getResource("CertificateCheckerDialog.fxml"));
                Parent parent = (Parent) loader.load();
                CertCheckController controller = (CertCheckController) loader.getController();
                controller.certText.setText(chain[0].toString());
                Scene scene = new Scene(parent);
                dialog.setScene(scene);
                dialog.showAndWait();
                responseQueue.put(Boolean.valueOf(controller.allowConnection));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    };
    if (Platform.isFxApplicationThread()) {
        runnable.run();
    } else {
        Platform.runLater(runnable);
    }

    try {
        boolean retVal = responseQueue.take();
        if (retVal) {
            trustedCerts.add(chain[0]);
        }
        return retVal;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.toyota.carservice.controller.CarMenuManagement.java

@FXML
private void aksiminimize(ActionEvent event) {
    stage = (Stage) minimize.getScene().getWindow();
    if (stage.isMaximized()) {
        w = rec2.getWidth();/*  w  ww  .  ja v a2 s .  c  o m*/
        h = rec2.getHeight();
        stage.setMaximized(false);
        stage.setHeight(h);
        stage.setWidth(w);
        stage.centerOnScreen();
        Platform.runLater(() -> {
            stage.setIconified(true);
        });
    } else {
        stage.setIconified(true);
    }
}

From source file:edu.kit.trufflehog.command.usercommand.SelectionCommand.java

private void updateNodeStatistics(Set<INode> nodes) {

    assert (nodes != null);

    //clearStatistics();

    if (nodes.size() == 1) {

        final TreeItem<StatisticsViewModel.IEntry<StringProperty, ? extends Property>> infos = nodes.iterator()
                .next().stream().collect(collector);
        logger.debug(infos);//  ww w.j ava  2 s . c o  m
        infos.setExpanded(true);
        Platform.runLater(() -> statisticsViewModel.setSelectionValues(infos));

    } else {

        //TODO calculate statistics for multiple selected nodes?

    }

}

From source file:gui.accessories.BattleSimFx.java

@Override
public void init() {
    tableModel = new SampleTableModel();
    // create javafx panel for charts
    chartFxPanel = new JFXPanel();
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //JTable/*from   w  ww  . jav a2  s.c om*/
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    BattleSimFx.DecimalFormatRenderer renderer = new BattleSimFx.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));

    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Split pane that holds both chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //          add(tablePanel, BorderLayout.CENTER);
    add(jsplitPane, BorderLayout.CENTER);

    // create JavaFX scene
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            createScene();
        }
    });
}

From source file:ijfx.service.history.HistoryService.java

public void loadWorkflow(Workflow workflow) {

    Platform.runLater(() -> {
        stepList.clear();/*from   w  w  w.  jav  a  2 s .  c om*/
        stepList.addAll(workflow.getStepList());
    });

    currentWorkflow.setName(workflow.getName());
    currentWorkflow.setDescription(workflow.getDescription());
}

From source file:account.management.controller.CreateAccountController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    try {// ww w .  j a va  2s.c om
        String res = Unirest.get(MetaData.baseUrl + "get/nextAccountId").asString().getBody();
        this.id.setText("LN" + String.format("%03d", Integer.parseInt(res)));
    } catch (UnirestException ex) {
        Logger.getLogger(CreateAccountController.class.getName()).log(Level.SEVERE, null, ex);
    }

    location = FXCollections.observableArrayList();

    new AutoCompleteComboBoxListener<>(select_location);
    select_location.setOnHiding((e) -> {
        Location a = select_location.getSelectionModel().getSelectedItem();
        select_location.setEditable(false);
        select_location.getSelectionModel().select(a);
    });
    select_location.setOnShowing((e) -> {
        select_location.setEditable(true);
    });

    // account type
    new Thread(() -> {
        this.select_account_type.getItems().add(new AccountType("0", "None"));
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/account_type").asJson();
            JSONArray account_type = response.getBody().getArray();
            for (int i = 0; i < account_type.length(); i++) {
                JSONObject obj = account_type.getJSONObject(i);
                select_account_type.getItems()
                        .add(new AccountType(obj.get("id").toString(), obj.getString("name")));
            }
        } catch (UnirestException ex) {

        } finally {
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.select_account_type);
                this.select_account_type.setOnHiding((e) -> {
                    AccountType a = this.select_account_type.getSelectionModel().getSelectedItem();
                    this.select_account_type.setEditable(false);
                    this.select_account_type.getSelectionModel().select(a);
                });
                this.select_account_type.setOnShowing((e) -> {
                    this.select_account_type.setEditable(true);
                });
                this.select_account_type.getSelectionModel().select(0);
            });
        }
    }).start();

    /*
    *   add location to combo box
    */
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
            JSONArray locationArray = response.getBody().getArray();
            for (int i = 0; i < locationArray.length(); i++) {
                JSONObject obj = locationArray.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                String details = obj.get("details").toString();
                location.add(new Location(id, name, details));
            }
            select_location.getItems().addAll(location);
        } catch (UnirestException ex) {

        } finally {
            Platform.runLater(() -> {
                this.select_location.getSelectionModel().select(0);
            });
        }
    }).start();

    new Thread(() -> {
        try {
            account = FXCollections.observableArrayList();
            /*
            *   add dr/cr options in select_dr_cr combobox
            */
            select_dr_cr.setItems(FXCollections.observableArrayList("Dr", "Cr"));
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();

            JSONArray array = response.getBody().getArray();
            for (int i = 6; i < array.length(); i++) {

                JSONObject obj = array.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                int parent = Integer.parseInt(obj.get("parent").toString());
                String desc = obj.get("description").toString();

                account.add(new Account(id, name, parent, desc, 0f));
            }

            select_parent.getItems().addAll(account);
        } catch (UnirestException ex) {
            Logger.getLogger(CreateAccountController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.select_parent);
                this.select_parent.setOnHiding((e) -> {
                    Account a = this.select_parent.getSelectionModel().getSelectedItem();
                    this.select_parent.setEditable(false);
                    this.select_parent.getSelectionModel().select(a);
                });
                this.select_parent.setOnShowing((e) -> {
                    this.select_parent.setEditable(true);
                });
            });
        }
    }).start();

    this.input_opening_balance.setText("0");
    this.select_dr_cr.getSelectionModel().select("Dr");

}

From source file:account.management.controller.EditAccountController.java

/**
 * Initializes the controller class./*from  w  w  w.  j a va  2  s. c  o m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    new AutoCompleteComboBoxListener<>(parent);
    parent.setOnHiding((e) -> {
        Account a = parent.getSelectionModel().getSelectedItem();
        parent.setEditable(false);
        parent.getSelectionModel().select(a);
    });
    parent.setOnShowing((e) -> {
        parent.setEditable(true);
    });

    new AutoCompleteComboBoxListener<>(account_type);
    account_type.setOnHiding((e) -> {
        AccountType a = account_type.getSelectionModel().getSelectedItem();
        account_type.setEditable(false);
        account_type.getSelectionModel().select(a);
    });
    account_type.setOnShowing((e) -> {
        account_type.setEditable(true);
    });

    accountList = FXCollections.observableArrayList();
    accounTypetList = FXCollections.observableArrayList();
    new Thread(() -> {

        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();
            JSONArray array = res.getBody().getArray();
            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);

                String id = obj.get("id").toString();
                String name = obj.getString("name");
                String parent = obj.get("parent").toString();
                String desc = obj.getString("description");
                String account_type = obj.get("account_type").toString();
                accountList.add(new Account(id, name, parent, desc, account_type));
            }
        } catch (UnirestException ex) {

        } finally {
            this.account.getItems().addAll(accountList);
            this.parent.getItems().addAll(accountList);
            Platform.runLater(() -> {
                new AutoCompleteComboBoxListener<>(this.account);
                this.account.setOnHiding((e) -> {
                    Account a = this.account.getSelectionModel().getSelectedItem();
                    this.account.setEditable(false);
                    this.account.getSelectionModel().select(a);
                });
                this.account.setOnShowing((e) -> {
                    this.account.setEditable(true);
                });
            });

        }

    }).start();

    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/account/type").asJson();
            JSONArray array = res.getBody().getArray();
            accounTypetList.add(new AccountType("0", "None"));
            for (int i = 0; i < array.length(); i++) {
                JSONObject obj = array.getJSONObject(i);
                String id = obj.getString("id");
                String name = obj.getString("name");
                accounTypetList.add(new AccountType(id, name));
            }

        } catch (UnirestException ex) {
            Logger.getLogger(EditAccountController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            this.account_type.getItems().addAll(accounTypetList);
        }
    }).start();

}

From source file:br.com.OCTur.view.GraficoController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    fornecedor = new FornecedorDAO().pegarPorEmpresa(Sessao.pessoa.getEmpresa());
    snCategoriasMaisVendida = new SwingNode();
    snInteressePorArtesanato = new SwingNode();
    snProdutosMaisAntigos = new SwingNode();
    spCategoriaMaisVendida.setContent(snCategoriasMaisVendida);
    spInteressePorArtesanato.setContent(snInteressePorArtesanato);
    spProdutosMaisAntigos.setContent(snProdutosMaisAntigos);
    DefaultPieDataset dpdDados = new DefaultPieDataset();
    for (CategoriaProduto categoriaProduto : new CategoriaProdutoDAO().pegarTodos()) {
        List<CompraItem> compraitem = new CompraItemDAO().pegarPorFonecedorCategoria(fornecedor,
                categoriaProduto);//from  w  w  w . j  a  v a  2  s  . c  o  m
        dpdDados.setValue(categoriaProduto.toString(), compraitem.size());
    }
    JFreeChart jFreeChart = ChartFactory.createPieChart3D(
            ControlTranducao.traduzirPalavra("CATEGORIASMAISVENDIDAS"), dpdDados, false, false, Locale.ROOT);
    PiePlot3D piePlot3D = (PiePlot3D) jFreeChart.getPlot();
    piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}\n{2}"));
    ChartPanel categoriaMaisVendida = new ChartPanel(jFreeChart);
    Platform.runLater(() -> {
        snCategoriasMaisVendida.setContent(categoriaMaisVendida);
    });
    DefaultCategoryDataset dcdDados = new DefaultCategoryDataset();
    for (int i = Calendar.getInstance().get(Calendar.YEAR) - 10; i < Calendar.getInstance()
            .get(Calendar.YEAR); i++) {
        dcdDados.addValue(new Random().nextDouble() * 100000, "Interesse", String.valueOf(i));
    }
    jFreeChart = ChartFactory.createLineChart(
            ControlTranducao.traduzirPalavra("interesse") + " "
                    + ControlTranducao.traduzirPalavra("artesanato"),
            "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel interesseArtesanato = new ChartPanel(jFreeChart);
    Platform.runLater(() -> {
        snInteressePorArtesanato.setContent(interesseArtesanato);
    });
    produto = new ArrayList<>();
    for (Produto produto : new ProdutoDAO().pegarPorFornecedor(fornecedor)) {
        if (new CompraItemDAO().pegarPorProduto(produto).isEmpty()) {
            List<Item> itens = new ItemDAO().pegarPorProduto(produto);
            if (!itens.isEmpty()) {
                Item item = itens.get(0);
                long quantidade = (new Date().getTime() - item.getDatacadastro().getTime()) / 1000 / 60 / 60
                        / 24;
                this.produto.add(new EntidadeGrafico<>(produto, quantidade));
            }
        }
    }
    slMeta.setMax(produto.stream().mapToDouble(EntidadeGrafico::getValue).max().orElse(0));
    slMeta.valueProperty()
            .addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
                produtosMaisAntigos();
            });
    Platform.runLater(() -> {
        produtosMaisAntigos();
    });
}

From source file:bzh.terrevirtuelle.navisu.instruments.gps.plotter.impl.controller.GpsPlotterController.java

protected void addPanelController() {
    Platform.runLater(() -> {
        targetPanel = new TargetPanel(guiAgentServices, KeyCode.B, KeyCombination.CONTROL_DOWN);
        guiAgentServices.getScene().addEventFilter(KeyEvent.KEY_RELEASED, targetPanel);
        guiAgentServices.getRoot().getChildren().add(targetPanel);
        targetPanel.setScale(1.0);/*w ww .  j av  a 2  s .c  om*/
        targetPanel.setVisible(false);
    });
}