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:caillou.company.clonemanager.gui.customComponent.search.SearchController.java

private void buildTransitionPopup() {
    LoadingMojo loadingMojo = SpringFxmlLoader.load(Navigation.TRANSITION_POPUP);
    transitionController = (TransitionController) loadingMojo.getController();
    transitionController.getEventBus().register(this);
    transitionFxml = loadingMojo.getParent();
    final Dialog dialogTransition = new Dialog(MainApp.getInstance().getStage(),
            SpringFxmlLoader.getResourceBundle().getString("title.processingData"));
    dialogTransition.getStylesheets().add(StyleSheet.DIALOG_CSS);
    transitionController.setWrappingDialog(dialogTransition);
    dialogTransition.setContent(transitionFxml);
    Platform.runLater(new Task<Void>() {

        @Override/*from  w  w  w . jav  a2 s.c  o  m*/
        protected Void call() throws Exception {
            transitionController.getWrappingDialog().show();
            return null;
        }
    });
}

From source file:org.pdfsam.PdfsamApp.java

@Override
public void init() {
    STOPWATCH.start();/*from w w  w  . j  av a  2  s. c o  m*/
    LOG.info("Starting PDFsam");
    notifyPreloader(new ProgressNotification(0));
    System.setProperty(Sejda.UNETHICAL_READ_PROPERTY_NAME, "true");
    System.setProperty(EventStudio.MAX_QUEUE_SIZE_PROP, "20");
    UserContext userContext = initUserContext();
    String localeString = userContext.getLocale();
    if (isNotBlank(localeString)) {
        eventStudio().broadcast(new SetLocaleEvent(localeString));
    }
    notifyPreloader(new ProgressNotification(0.1));
    String defaultworkingPath = userContext.getDefaultWorkingPath();
    if (isNotBlank(defaultworkingPath)) {
        try {
            if (Files.isDirectory(Paths.get(defaultworkingPath))) {
                eventStudio().broadcast(new SetLatestDirectoryEvent(new File(defaultworkingPath)));
            }
        } catch (InvalidPathException e) {
            LOG.warn("Unable to set initial directory, default path is invalid.", e);
        }
    }
    notifyPreloader(new ProgressNotification(0.3));
    Platform.runLater(() -> ApplicationContextHolder.getContext());
    notifyPreloader(new ProgressNotification(0.6));
    Platform.runLater(() -> initScene());
    notifyPreloader(new ProgressNotification(0.8));

}

From source file:com.jscriptive.moneyfx.ui.account.AccountFrame.java

private void loadAccountData() {
    accountData.clear();/*w  ww.ja  va2 s  .  c o m*/
    accountRepository.findAll().forEach(account -> accountData.add(new AccountItem(account)));
    Platform.runLater(() -> dataSummaryLabel
            .setText("Accounts: " + accountData.size() + ", balance: " + getAbsSum(accountData)));
}

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

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

    Platform.runLater(() -> {
        onAddNewFieldButtonClick(null);/*from www .  j  a v  a2 s  .  c  om*/
    });

    account_list = FXCollections.observableArrayList();
    filter_party_rec = FXCollections.observableArrayList();
    filter_party_pay = FXCollections.observableArrayList();

    new AutoCompleteComboBoxListener<>(select_voucher_type);
    select_voucher_type.setOnHiding((e) -> {
        VoucherType a = select_voucher_type.getSelectionModel().getSelectedItem();
        select_voucher_type.setEditable(false);
        select_voucher_type.getSelectionModel().select(a);
    });
    select_voucher_type.setOnShowing((e) -> {
        select_voucher_type.setEditable(true);
    });
    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);
    });

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

    new Thread(() -> {
        try {
            Thread.sleep(5000);
            this.button_submit.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("attempting to submit new voucher");
                        //Stop letting it do anything else
                        keyEvent.consume();
                        onSubmitButtonClick(null);
                    }
                }
            });
        } catch (InterruptedException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }).start();

    /*
    *   voucher type
    */
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "get/voucher/type").asJson();
            JSONArray type = res.getBody().getArray();
            for (int i = 0; i < type.length(); i++) {
                JSONObject obj = type.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("type_name").toString();
                String note = obj.get("details").toString();
                this.select_voucher_type.getItems().add(new VoucherType(id, name, note));
            }
        } catch (UnirestException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }).start();

    /*
    *   init locations in select_location combobox
    */
    locations = FXCollections.observableArrayList();
    new Thread(() -> {
        try {
            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/locations").asJson();
            JSONArray location_array = response.getBody().getArray();
            for (int i = 0; i < location_array.length() - 1; i++) {
                String name = location_array.getJSONObject(i).getString("name");
                String details = location_array.getJSONObject(i).getString("details");
                int id = location_array.getJSONObject(i).getInt("id");
                locations.add(new Location(id, name, details));
            }
            select_location.getItems().addAll(locations);

        } catch (UnirestException ex) {
            System.out.println("exception in UNIREST");
        }
    }).start();

    this.button_submit.setDisable(true);

    field_container.setOnKeyReleased((KeyEvent event) -> {
        validateFields();
    });

    ToggleGroup tg = new ToggleGroup();
    this.project.setToggleGroup(tg);
    this.lc.setToggleGroup(tg);
    this.cnf.setToggleGroup(tg);

    /*
    *   init account name
    */
    new Thread(() -> {
        final ComboBox<Account> a = (ComboBox<Account>) this.field_row.getChildren().get(0);
        try {

            HttpResponse<JsonNode> response = Unirest.get(MetaData.baseUrl + "get/accounts").asJson();
            JSONArray account = response.getBody().getArray();
            for (int i = 1; i < account.length(); i++) {
                JSONObject obj = account.getJSONObject(i);
                int id = Integer.parseInt(obj.get("id").toString());
                String name = obj.get("name").toString();
                String desc = obj.get("description").toString();
                int parent_id = Integer.parseInt(obj.get("parent").toString());

                account_list
                        .add(new Account(id, name, parent_id, desc, 0f, obj.get("account_type").toString()));
                if (parent_id == 21) {
                    this.filter_party_rec.add(
                            new Account(id, name, parent_id, desc, 0f, obj.get("account_type").toString()));
                }
                if (parent_id == 34) {
                    this.filter_party_pay.add(
                            new Account(id, name, parent_id, desc, 0f, obj.get("account_type").toString()));
                }
            }

            a.getItems().addAll(account_list);

        } catch (UnirestException ex) {
            Logger.getLogger(NewVoucherController.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            new AutoCompleteComboBoxListener<>(a);
            a.setOnHiding((e) -> {
                Account acc = a.getSelectionModel().getSelectedItem();
                a.setEditable(false);
                a.getSelectionModel().select(acc);
            });
            a.setOnShowing((e) -> {
                a.setEditable(true);
            });

            a.setOnAction((e) -> {
                if (!a.getSelectionModel().isEmpty() && a.getSelectionModel().getSelectedItem().getId() == 21) {
                    a.setPromptText("Select Party");
                    a.getItems().clear();
                    a.getItems().addAll(this.filter_party_rec);
                }
                if (!a.getSelectionModel().isEmpty() && a.getSelectionModel().getSelectedItem().getId() == 34) {
                    a.getItems().clear();
                    a.getItems().addAll(this.filter_party_pay);
                    a.setPromptText("Select Party");
                }
            });

        }
    }).start();

}

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

public void setSpeed(final String speed) {
    Platform.runLater(new Runnable() {

        @Override//  w ww . j a va 2  s .c o  m
        public void run() {
            progressSpeed.setText(speed);
        }
    });
}

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  ww  .  ja va2 s.  c  om
 * @param tree True if it is part of a tree (versus a list)
 */
void insert(String path, DrawableGroup g, Boolean tree) {
    if (tree) {
        String cleanPath = StringUtils.stripStart(path, "/");

        // get the first token
        String prefix = StringUtils.substringBefore(cleanPath, "/");

        // Are we at the end of the recursion?
        if ("".equals(prefix)) {
            getValue().setGroup(g);
        } else {
            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(StringUtils.stripStart(cleanPath, prefix), g, tree);
        }
    } else {
        GroupTreeItem treeItem = childMap.get(path);
        if (treeItem == null) {
            final GroupTreeItem newTreeItem = new GroupTreeItem(path, g, comp);
            newTreeItem.setExpanded(true);
            childMap.put(path, newTreeItem);

            Platform.runLater(() -> {
                synchronized (getChildren()) {
                    getChildren().add(newTreeItem);
                    if (comp != null) {
                        FXCollections.sort(getChildren(), comp);
                    }
                }
            });

        }
    }
}

From source file:rmblworx.tools.timey.gui.AlarmIntegrationTest.java

/**
 * Testet//from   www.j  a v  a  2  s.  c  o  m
 * <ol>
 * <li>Anlegen eines Alarms per GUI,</li>
 * <li>Senden des Ereignisses zum Auslsen des Alarms per Backend und</li>
 * <li>Reaktion der GUI auf das Ereignis.</li>
 * </ol>
 */
@Test
@Ignore("schlgt derzeit fehl") // TODO
public final void testCreateAlarmAndHandleEvent() {
    /*
     * Zeitdifferenz, die der Alarm in der Zukunft ausgelst werden soll.
     * Wert mglichst klein halten, um Test nich unntig lange dauern zu lassen, aber dennoch gro genug, um sicherzustellen, dass
     * Alarm bis zu diesem Zeitpunkt vollstndig angelegt werden kann.
     */
    final int bufferInSeconds = 2;

    final String alarmDescription = "relevanter Alarm";

    final AlarmController controller = (AlarmController) getController();
    final GuiHelper guiHelper = controller.getGuiHelper();
    final ITimey facade = guiHelper.getFacade();

    // zwei unwichtige Alarme per Fassade hinzufgen
    final LocalDateTime now = LocalDateTime.now().withNano(0);
    facade.setAlarm(AlarmDescriptorConverter
            .getAsAlarmDescriptor(new Alarm(now.minusYears(1), "alter Alarm", "", false)));
    facade.setAlarm(
            AlarmDescriptorConverter.getAsAlarmDescriptor(new Alarm(now.plusYears(1), "Zukunftsalarm")));

    // relevanten Alarm per GUI hinzufgen
    final Button alarmAddButton = (Button) stage.getScene().lookup("#alarmAddButton");
    click(alarmAddButton);
    waitForThreads();

    final Scene dialogScene = controller.getDialogStage().getScene();
    final TimePicker alarmTimePicker = (TimePicker) dialogScene.lookup("#alarmTimePicker");
    final TextField alarmDescriptionTextField = (TextField) dialogScene.lookup("#alarmDescriptionTextField");
    final Button alarmSaveButton = (Button) dialogScene.lookup("#alarmSaveButton");

    Platform.runLater(new Runnable() {
        public void run() {
            alarmTimePicker.setValue(alarmTimePicker.getValue().plusSeconds(bufferInSeconds));
            alarmDescriptionTextField.setText(alarmDescription);
        }
    });
    FXTestUtils.awaitEvents();

    final MessageHelper messageHelper = mock(MessageHelper.class);
    guiHelper.setMessageHelper(messageHelper);

    // Speichern-Schaltflche bettigen
    click(alarmSaveButton);
    waitForThreads();

    // sicherstellen, dass Ereignis genau einmal fr den korrekten Alarm eintritt und verarbeitet wird
    verify(messageHelper, timeout(WAIT_FOR_EVENT)).showTrayMessageWithFallbackToDialog(anyString(),
            eq(alarmDescription), isNull(TrayIcon.class), isA(ResourceBundle.class));
}

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

@FXML
private void onLoginButtonClick(ActionEvent event) {
    try {// w w w  .j a va 2 s  .c om

        String username = this.username.getText();
        String password = this.password.getText();

        User.username = username;

        this.login_btn.setDisable(true);
        this.login_btn.setText("Loading...");
        Thread t = new Thread(() -> {
            try {
                HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "login")
                        .queryString("username", username).queryString("password", password).asJson();
                JSONArray array = res.getBody().getArray();
                JSONObject obj = array.getJSONObject(0);
                if (obj.getInt("inventory") == 1)
                    User.inventory = true;
                if (obj.getInt("project") == 1)
                    User.project = true;
                if (obj.getInt("lc") == 1)
                    User.lc = true;
                if (obj.getInt("cnf") == 1)
                    User.cnf = true;
                if (obj.getInt("deposit_voucher") == 1)
                    User.deposit_voucher = true;
                if (obj.getInt("expense_voucher") == 1)
                    User.expense_voucher = true;
                if (obj.getInt("sell") == 1)
                    User.sell = true;
                if (obj.getInt("purchase") == 1)
                    User.purchase = true;
                if (obj.getInt("party_create") == 1)
                    User.party_create = true;
                if (obj.getInt("ledger_create") == 1)
                    User.ledger = true;
                if (obj.getInt("voucher") == 1)
                    User.voucher = true;
                if (obj.getInt("bank") == 1)
                    User.bank = true;
                if (obj.getInt("inventory_report") == 1)
                    User.inventory_report = true;
                if (obj.getInt("trial_balance") == 1)
                    User.trial_balance = true;
                if (obj.getInt("balance_sheet") == 1)
                    User.balance_sheet = true;
                if (obj.getInt("financial_statement") == 1)
                    User.financial_statement = true;
                if (obj.getInt("database_maintanance") == 1)
                    User.database_maintanance = true;

                Platform.runLater(() -> {
                    try {
                        this.login_btn.getScene().getWindow().hide();
                        Parent root;
                        root = FXMLLoader.load(getClass().getResource(MetaData.viewPath + "home1.fxml"));
                        Scene scene = new Scene(root);
                        scene.getStylesheets().add("/style.css");
                        Stage stage = new Stage();
                        scene.setRoot(root);
                        stage.setResizable(true);
                        stage.setTitle("Home");
                        stage.setScene(scene);
                        stage.showAndWait();
                    } catch (IOException ex) {
                        Logger.getLogger(loginController.class.getName()).log(Level.SEVERE, null, ex);
                    }
                });

            } catch (Exception ex) {
                Platform.runLater(() -> {
                    Msg.showError("Username or password is incorrect");
                });
            } finally {
                login_btn.setDisable(false);
                Platform.runLater(() -> {
                    login_btn.setText("Login");

                });

            }
        });
        t.start();

    } catch (Exception e) {
        Msg.showError("Sorry. There is an error. Please try again");
    }
}

From source file:mercury.core.AngularDeferred.java

private void runLater(Runnable r) {
    Platform.runLater(r);
}

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

private void addProperties(Properties properties, Locale locale, PropertiesFile file) {
    Platform.runLater(new Runnable() {
        @Override//from w ww . java2s . c  o  m
        public void run() {
            logger.info("Add a propertie file for the locale '" + locale + "'");
            mapPropertiesByLocale.put(locale, properties);
            mapPropertiesFileByLocale.put(locale, file);
            Set<String> stringPropertyNames = properties.stringPropertyNames();

            // use of a set to prevent duplicated values into the list
            Set<String> setPropertyTotal = new HashSet<>(listMessageKey);
            setPropertyTotal.addAll(stringPropertyNames);
            listMessageKey.clear();
            listMessageKey.addAll(setPropertyTotal);
            baseName.set(file.getBaseName());
            parentDirectoryPath.set(file.getParent() + File.separator);
            isLoaded.set(true);
            logger.info(listMessageKey.size() + " keys are loaded for locale '" + locale + "'");
        }
    });

}