Search in sources :

Example 1 with LocaleObject

use of jgnash.util.LocaleObject in project jgnash by ccavanaugh.

the class DefaultLocaleAction method showAndWait.

public static void showAndWait() {
    final Task<LocaleObject[]> task = new Task<LocaleObject[]>() {

        final ResourceBundle resources = ResourceUtils.getBundle();

        private LocaleObject[] localeObjects;

        @Override
        protected LocaleObject[] call() throws Exception {
            localeObjects = LocaleObject.getLocaleObjects();
            return localeObjects;
        }

        @Override
        protected void succeeded() {
            super.succeeded();
            Platform.runLater(() -> {
                final ChoiceDialog<LocaleObject> dialog = new ChoiceDialog<>(new LocaleObject(Locale.getDefault()), localeObjects);
                dialog.setTitle(resources.getString("Title.SelDefLocale"));
                dialog.getDialogPane().getStylesheets().addAll(MainView.DEFAULT_CSS);
                dialog.getDialogPane().getScene().getRoot().styleProperty().bind(ThemeManager.styleProperty());
                dialog.getDialogPane().getStyleClass().addAll("form", "dialog");
                dialog.setHeaderText(resources.getString("Title.SelDefLocale"));
                final Optional<LocaleObject> optional = dialog.showAndWait();
                optional.ifPresent(localeObject -> {
                    ResourceUtils.setLocale(localeObject.getLocale());
                    StaticUIMethods.displayMessage(localeObject + "\n" + resources.getString("Message.RestartLocale"));
                });
            });
        }
    };
    new Thread(task).start();
}
Also used : ChoiceDialog(javafx.scene.control.ChoiceDialog) Task(javafx.concurrent.Task) ResourceBundle(java.util.ResourceBundle) LocaleObject(jgnash.util.LocaleObject)

Aggregations

ResourceBundle (java.util.ResourceBundle)1 Task (javafx.concurrent.Task)1 ChoiceDialog (javafx.scene.control.ChoiceDialog)1 LocaleObject (jgnash.util.LocaleObject)1