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.getqube.store.BrowseCategoryController.java

private void reportConnectionProblem() {
    Platform.runLater(new Runnable() {
        @Override/*www . j  a v  a 2s  . com*/
        public void run() {
            Action response = Dialogs.create().owner((Stage) paneLoading.getScene().getWindow())
                    .style(DialogStyle.NATIVE).title("Uh Oh").masthead("Possible Connection Problem")
                    .message(
                            "Could not retrieve apps from the Qube App Store possibly due to a connection problem. Please check your Internet connection and try again.")
                    .showError();

            if (response == Dialog.Actions.OK) {
                Navigator.loadVista(Navigator.ALL_CATEGORIES);
                CategoriesController.resetBreadcrumbs();
            }
        }
    });
}

From source file:org.cryptomator.ui.UnlockController.java

@FXML
private void didClickUnlockButton(ActionEvent event) {
    setControlsDisabled(true);//from  w w  w.  j  av a 2  s .c o m
    final String masterKeyFileName = usernameBox.getValue() + Aes256Cryptor.MASTERKEY_FILE_EXT;
    final Path masterKeyPath = directory.getPath().resolve(masterKeyFileName);
    final CharSequence password = passwordField.getCharacters();
    InputStream masterKeyInputStream = null;
    try {
        progressIndicator.setVisible(true);
        masterKeyInputStream = Files.newInputStream(masterKeyPath, StandardOpenOption.READ);
        directory.setVerifyFileIntegrity(checkIntegrity.isSelected());
        directory.getCryptor().decryptMasterKey(masterKeyInputStream, password);
        if (!directory.startServer()) {
            messageLabel.setText(rb.getString("unlock.messageLabel.startServerFailed"));
            directory.getCryptor().swipeSensitiveData();
            return;
        }
        directory.setUnlocked(true);
        final Future<Boolean> futureMount = FXThreads.runOnBackgroundThread(directory::mount);
        FXThreads.runOnMainThreadWhenFinished(futureMount, this::didUnlockAndMount);
        FXThreads.runOnMainThreadWhenFinished(futureMount, (result) -> {
            setControlsDisabled(false);
        });
    } catch (DecryptFailedException | IOException ex) {
        setControlsDisabled(false);
        progressIndicator.setVisible(false);
        messageLabel.setText(rb.getString("unlock.errorMessage.decryptionFailed"));
        LOG.error("Decryption failed for technical reasons.", ex);
    } catch (WrongPasswordException e) {
        setControlsDisabled(false);
        progressIndicator.setVisible(false);
        messageLabel.setText(rb.getString("unlock.errorMessage.wrongPassword"));
        Platform.runLater(passwordField::requestFocus);
    } catch (UnsupportedKeyLengthException ex) {
        setControlsDisabled(false);
        progressIndicator.setVisible(false);
        messageLabel.setText(rb.getString("unlock.errorMessage.unsupportedKeyLengthInstallJCE"));
        LOG.warn("Unsupported Key-Length. Please install Oracle Java Cryptography Extension (JCE).", ex);
    } finally {
        passwordField.swipe();
        IOUtils.closeQuietly(masterKeyInputStream);
    }
}

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void closeNow() {
    Platform.runLater(new Runnable() {
        @Override//w  w  w.j  av a2 s .c  o  m
        public void run() {
            GuiWorkbench.getMyStage()
                    .fireEvent(new DpfCloseEvent(GuiWorkbench.getMyStage(), WindowEvent.WINDOW_CLOSE_REQUEST));
        }
    });
}

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

private void initListeners(Config config) {
    EmailServer.initEmailWriter(new SaverConfig() {
        @Override//from   w ww. ja v  a2s. co  m
        public boolean isActive() {
            return saveDirCheck.isSelected();
        }

        @Override
        public String getDirectory() {
            return dirField.getText();
        }
    });

    messagesTable.getSelectionModel().selectedItemProperty()
            .addListener((observableValue, oldValue, newValue) -> {
                if (messagesTable.getSelectionModel().getSelectedItem() != null) {
                    emailText.getEngine().loadContent(newValue.getBody(), newValue.getBodyType());
                    rawText.setText(newValue.getContent());
                } else {
                    emailText.getEngine().loadContent("");
                    rawText.setText(null);

                }
            });

    EmailServer.addObserver((o, arg) -> Platform.runLater(() -> {
        Event event = (Event) arg;

        switch (event.getType()) {
        case incoming:
            messages.add(event.getEmail());
            updateMessagesCount();

            if (config.isJumpToLast()) {
                messagesTable.getSelectionModel().selectLast();
            }
            break;
        case clear:
            messages.clear();
            updateMessagesCount();
            serverLog.clear();
            break;
        }
    }));
}

From source file:org.noroomattheinn.visibletesla.LocationController.java

private void doUpdateLater(final StreamState state) {
    Platform.runLater(new Runnable() {
        @Override/*from  ww  w . j  av a  2 s  . co m*/
        public void run() {
            reflectInternal(state);
        }
    });
}

From source file:gui.accessories.BattleSimFx.java

private BarChart createBarChart() {
    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);/*w ww .  ja v a 2s.  c o  m*/
    yAxis.setLabel("Units Sold");

    final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    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:org.pdfsam.ui.selection.multiple.SelectionTable.java

private void initContextMenu() {
    MenuItem infoItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Document properties"),
            AwesomeIcon.INFO);//from  w w  w  .ja v a  2  s . c  o m
    infoItem.setOnAction(e -> Platform.runLater(() -> {
        eventStudio().broadcast(
                new ShowPdfDescriptorRequest(getSelectionModel().getSelectedItem().getPdfDocumentDescriptor()));
    }));
    MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set output"),
            AwesomeIcon.PENCIL_SQUARE_ALT);

    setDestinationItem.setOnAction(e -> {
        File outFile = new File(
                getSelectionModel().getSelectedItem().getPdfDocumentDescriptor().getFile().getParent(),
                "out.pdf");
        eventStudio().broadcast(new SetDestinationRequest(outFile), getOwnerModule());
    });

    MenuItem removeSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Remove"),
            AwesomeIcon.MINUS_SQUARE_ALT);

    removeSelected.setOnAction(e -> eventStudio().broadcast(new RemoveSelectedEvent(), getOwnerModule()));

    MenuItem moveTopSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Move to Top"),
            AwesomeIcon.ANGLE_DOUBLE_UP);
    moveTopSelected
            .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.TOP), getOwnerModule()));

    MenuItem moveUpSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Move Up"),
            AwesomeIcon.ANGLE_UP);
    moveUpSelected
            .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.UP), getOwnerModule()));

    MenuItem moveDownSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Move Down"),
            AwesomeIcon.ANGLE_DOWN);
    moveDownSelected
            .setOnAction(e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.DOWN), getOwnerModule()));

    MenuItem moveBottomSelected = createMenuItem(DefaultI18nContext.getInstance().i18n("Move to Bottom"),
            AwesomeIcon.ANGLE_DOUBLE_DOWN);
    moveBottomSelected.setOnAction(
            e -> eventStudio().broadcast(new MoveSelectedEvent(MoveType.BOTTOM), getOwnerModule()));

    MenuItem openFileItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open"), AwesomeIcon.FILE_ALT);
    openFileItem.setOnAction(e -> {
        eventStudio().broadcast(new OpenFileRequest(
                getSelectionModel().getSelectedItem().getPdfDocumentDescriptor().getFile()));
    });

    MenuItem openFolderItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Open Folder"),
            AwesomeIcon.FOLDER_OPEN);
    openFolderItem.setOnAction(e -> {
        eventStudio().broadcast(new OpenFileRequest(
                getSelectionModel().getSelectedItem().getPdfDocumentDescriptor().getFile().getParentFile()));
    });
    // https://javafx-jira.kenai.com/browse/RT-28136
    // infoItem.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.ALT_DOWN));
    // setDestinationItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.ALT_DOWN));
    // removeSelected.setAccelerator(new KeyCodeCombination(KeyCode.CANCEL));
    // moveBottomSelected.setAccelerator(new KeyCodeCombination(KeyCode.END, KeyCombination.ALT_DOWN));
    // moveDownSelected.setAccelerator(new KeyCodeCombination(KeyCode.DOWN, KeyCombination.ALT_DOWN));
    // moveUpSelected.setAccelerator(new KeyCodeCombination(KeyCode.UP, KeyCombination.ALT_DOWN));
    // moveTopSelected.setAccelerator(new KeyCodeCombination(KeyCode.HOME, KeyCombination.ALT_DOWN));

    eventStudio().add(SelectionChangedEvent.class, (SelectionChangedEvent e) -> {
        setDestinationItem.setDisable(!e.isSingleSelection());
        infoItem.setDisable(!e.isSingleSelection());
        openFileItem.setDisable(!e.isSingleSelection());
        openFolderItem.setDisable(!e.isSingleSelection());
        removeSelected.setDisable(e.isClearSelection());
        moveTopSelected.setDisable(!e.canMove(MoveType.TOP));
        moveUpSelected.setDisable(!e.canMove(MoveType.UP));
        moveDownSelected.setDisable(!e.canMove(MoveType.DOWN));
        moveBottomSelected.setDisable(!e.canMove(MoveType.BOTTOM));

    }, getOwnerModule());
    setContextMenu(new ContextMenu(setDestinationItem, new SeparatorMenuItem(), removeSelected, moveTopSelected,
            moveUpSelected, moveDownSelected, moveBottomSelected, new SeparatorMenuItem(), infoItem,
            openFileItem, openFolderItem));
}

From source file:photobooth.views.ExplorerPane.java

private void init(String dir, int offset, int limit, int directoryLevel) {

    this.getChildren().removeAll(this.getChildren());
    this.dir = dir;
    this.offset = offset;
    this.limit = limit;
    this.directoryLevel = directoryLevel;

    try {/*from  w  w  w.j  ava  2s  .c om*/
        addXButton();
    } catch (IOException ex) {
        Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (directoryLevel > 0) {
        try {
            addUpButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    addLabel();

    TilePane tile = new TilePane();
    tile.setHgap(12);
    tile.setVgap(12);

    File folder = new File(dir);
    File[] listOfDirs = folder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });
    File[] allFileAndDiresctoies = new File[0];
    if (listOfDirs != null) {
        Arrays.sort(listOfDirs);

        File[] listOfImages = folder.listFiles(new FileFilter() {

            @Override
            public boolean accept(File file) {
                String ext = FilenameUtils.getExtension(file.getAbsolutePath());
                return ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("png");
            }
        });
        Arrays.sort(listOfImages);
        allFileAndDiresctoies = new File[listOfDirs.length + listOfImages.length];
        System.arraycopy(listOfDirs, 0, allFileAndDiresctoies, 0, listOfDirs.length);
        System.arraycopy(listOfImages, 0, allFileAndDiresctoies, listOfDirs.length, listOfImages.length);

        File[] subArray = new File[limit];
        int countToCopy = limit;
        if (offset + limit > allFileAndDiresctoies.length) {
            countToCopy -= offset + limit - allFileAndDiresctoies.length;
        }
        System.arraycopy(allFileAndDiresctoies, offset, subArray, 0, countToCopy);

        for (final File file : subArray) {
            if (file == null) {
                break;
            }
            if (file.isFile()) {
                tile.getChildren().add(createImageView(file));
            } else {
                Button button = new Button(file.getName());
                button.setMaxSize(100, 100);
                button.setMinSize(100, 100);
                button.setWrapText(true);
                button.getStyleClass().add("folderButton");

                button.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {

                        Global.getInstance().setSceneRoot(LoadingPane.getInstance());

                        Platform.runLater(() -> {
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    ExplorerPane.getInstance().setDir(file.getAbsolutePath(), 0, limit,
                                            directoryLevel + 1);
                                    Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                                }
                            }).start();
                        });

                    }
                });
                tile.getChildren().add(button);

            }
        }
    }
    this.getChildren().add(tile);
    tile.setMinWidth(670);
    tile.setMaxWidth(670);
    tile.setLayoutX(65);
    tile.setLayoutY(70);
    tile.setMaxHeight(390);

    if (allFileAndDiresctoies.length > offset + limit) {
        try {
            addNextButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (offset > 0) {
        try {
            addPrevButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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

/**
 * @throws RejectedExecutionException {@inheritDoc}
 * @throws NullPointerException       {@inheritDoc}
 */// w  w  w  .j  av a 2 s . c o  m
@NotNull
@Override
public <T> Future<T> submit(Runnable task, T result) {
    Runnable effectiveTask = () -> Platform.runLater(task);
    return super.schedule(Executors.callable(effectiveTask, result), 0, NANOSECONDS);
}

From source file:org.cryptomator.ui.MainApplication.java

void handleCommandLineArg(final MainController ctrl, String arg) {
    Path file = FileSystems.getDefault().getPath(arg);
    if (!Files.exists(file)) {
        try {/* w w  w .j a va  2 s  .c  om*/
            if (!Files.isDirectory(Files.createDirectories(file))) {
                return;
            }
        } catch (IOException e) {
            return;
        }
        // directory created.
    } else if (Files.isRegularFile(file)) {
        if (StringUtils.endsWithIgnoreCase(file.getFileName().toString(), Aes256Cryptor.MASTERKEY_FILE_EXT)) {
            file = file.getParent();
        } else {
            // is a file, but not a masterkey file
            return;
        }
    }
    Path f = file;
    Platform.runLater(() -> {
        ctrl.addDirectory(f);
        ctrl.toFront();
    });
}