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:org.jevis.jeconfig.plugin.classes.ClassTree.java

public void fireEventNew(TreeItem<JEVisClass> item) {
    try {// w  w  w. ja  va 2 s. c  o  m
        NewClassDialog dia = new NewClassDialog();

        JEVisClass currentClass = null;

        if (item != null) {
            currentClass = item.getValue();
        } else if (item == null && getSelectionModel().getSelectedItem() != null) {
            currentClass = getSelectionModel().getSelectedItem().getValue();
        } else if (currentClass != null && currentClass.getName().equals("Classes")) {
            currentClass = null;
        }

        if (currentClass != null && currentClass.getName().equals("Classes")) {
            currentClass = null;
        }

        if (dia.show(JEConfig.getStage(), currentClass, _ds) == NewClassDialog.Response.YES
                && dia.getClassName() != null && !dia.getClassName().equals("")) {

            JEVisClass newClass = _ds.buildClass(dia.getClassName());

            if (dia.getInheritance() != null && newClass != null) {
                newClass.setIcon(dia.getInheritance().getIcon());
                newClass.commit();
            }

            final TreeItem<JEVisClass> treeItem = buildItem(newClass);

            if (dia.getInheritance() != null) {

                //reload workaround, loading the relationship befor creation ein will execute the getFixedRelationships() function
                newClass.getRelationships();

                JEVisClassRelationship cr = RelationshipFactory.buildInheritance(dia.getInheritance(),
                        newClass);

                //                    newClass = null;
                //                    newClass = _ds.getJEVisClass(dia.getClassName());
                //                    System.out.println("fixfix: " + newClass.getName());
                getChildrenList(getObjectTreeItem(dia.getInheritance())).add(getObjectTreeItem(newClass));
            } else {
                getChildrenList(getObjectTreeItem(getRoot().getValue())).add(getObjectTreeItem(newClass));
            }

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    getSelectionModel().select(treeItem);
                }
            });
        }

    } catch (JEVisException ex) {
        ex.printStackTrace();
        Logger.getLogger(ClassTree.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager.java

/**
 * regroup all files in the database using given {@link  DrawableAttribute}
 * see {@link ReGroupTask} for more details.
 *
 * @param groupBy/*from   w  w w . ja  va 2  s. c  o  m*/
 * @param sortBy
 * @param sortOrder
 * @param force     true to force a full db query regroup
 */
public synchronized <A extends Comparable<A>> void regroup(final DrawableAttribute<A> groupBy,
        final GroupSortBy sortBy, final SortOrder sortOrder, Boolean force) {

    if (!Case.isCaseOpen()) {
        return;
    }

    //only re-query the db if the group by attribute changed or it is forced
    if (groupBy != getGroupBy() || force == true) {
        setGroupBy(groupBy);
        setSortBy(sortBy);
        setSortOrder(sortOrder);
        if (groupByTask != null) {
            groupByTask.cancel(true);
        }

        groupByTask = new ReGroupTask<A>(groupBy, sortBy, sortOrder);
        Platform.runLater(() -> {
            regroupProgress.bind(groupByTask.progressProperty());
        });
        regroupExecutor.submit(groupByTask);
    } else {
        // resort the list of groups
        setSortBy(sortBy);
        setSortOrder(sortOrder);
        Platform.runLater(() -> {
            FXCollections.sort(analyzedGroups, applySortOrder(sortOrder, sortBy));
            FXCollections.sort(unSeenGroups, applySortOrder(sortOrder, sortBy));
        });
    }
}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectCVCamera(ActionEvent event) {

    Platform.runLater(() -> ConnectionManager.onConnectCVCamera());

}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectJavaCVCamera() {

    Platform.runLater(() -> ConnectionManager.onConnectJavaCVCamera());

}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectFileSourceCamera() {
    Platform.runLater(() -> ConnectionManager.onConnectFileSourceCamera());

}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectURLSourceCamera() {

    Platform.runLater(() -> ConnectionManager.onConnectURLSourceCamera());

}

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

/**
 * This method is invoked when the "by category" button has been toggled
 *
 * @param actionEvent//from  w ww  .  ja v  a  2s.c  o  m
 */
public void byCategoryToggled(ActionEvent actionEvent) {
    final PieChart pieChart = new PieChart();
    pieChart.setTitle("Transaction balance by categories");
    pieChart.setLegendSide(LEFT);
    chartFrame.setCenter(pieChart);
    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(),
                                yearCombo.getValue());
                        if (period.isEmpty()) {
                            return null;
                        }
                        Platform.runLater(() -> pieChart.setTitle(format("%s for transactions from %s until %s",
                                pieChart.getTitle(), period.from().format(DATE_FORMATTER),
                                period.to().format(DATE_FORMATTER))));

                        categoryRepository.findAll().stream()
                                .sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(category -> {
                                    List<Transaction> found = (accountCombo.getValue() == ALL_ACCOUNTS)
                                            ? transactionRepository.findByCategory(category)
                                            : transactionRepository.findByAccountAndCategory(
                                                    accountCombo.getValue(), category);
                                    if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                                        found = found.stream().filter(
                                                trx -> yearCombo.getValue().equals(trx.getDtOp().getYear()))
                                                .sorted((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()))
                                                .collect(toList());
                                    }
                                    List<Transaction> transactions = new ArrayList<>(found.size());
                                    transactions.addAll(found);
                                    Platform.runLater(() -> {
                                        double value = getSum(transactions);
                                        String name = format("%s [%s]", category.getName(),
                                                CurrencyFormat.getInstance().format(value));
                                        PieChart.Data data = new PieChart.Data(name, value);
                                        pieChart.getData().add(data);
                                        data.getNode().addEventHandler(MOUSE_CLICKED,
                                                event -> handleCategoryChartMouseClickEvent(
                                                        (accountCombo.getValue() == ALL_ACCOUNTS) ? null
                                                                : accountCombo.getValue(),
                                                        category, yearCombo.getValue(), event));
                                    });
                                });
                        return null;
                    }
                };
            }
        };
        service.start();
    }
}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectHokuyoURG(ActionEvent event) {
    Platform.runLater(() -> ConnectionManager.onConnectHokuyoURG());

}

From source file:se.trixon.filebydate.ui.MainApp.java

private void setRunningState(RunState runState) {
    ArrayList<Action> actions = new ArrayList<>();

    switch (runState) {
    case STARTABLE:
        actions.addAll(Arrays.asList(mLogAction, ActionUtils.ACTION_SPAN, mAddAction));
        mOptionsAction.setDisabled(false);
        break;//from w  w  w . j a  v a2s  .co  m

    case CANCELABLE:
        actions.addAll(Arrays.asList(mHomeAction, ActionUtils.ACTION_SPAN, mCancelAction));
        mHomeAction.setDisabled(true);
        mOptionsAction.setDisabled(true);
        break;

    case CLOSEABLE:
        actions.addAll(Arrays.asList(mHomeAction, ActionUtils.ACTION_SPAN, mRunAction));
        mHomeAction.setDisabled(false);
        mOptionsAction.setDisabled(false);
        break;

    default:
        throw new AssertionError();
    }

    actions.addAll(Arrays.asList(mOptionsAction,
            new ActionGroup(Dict.HELP.toString(),
                    mFontAwesome.create(FontAwesome.Glyph.QUESTION).size(ICON_SIZE_TOOLBAR).color(mIconColor),
                    mHelpAction, mAboutDateFormatAction, ActionUtils.ACTION_SEPARATOR, mAboutAction)));

    Platform.runLater(() -> {
        if (mToolBar == null) {
            mToolBar = ActionUtils.createToolBar(actions, ActionUtils.ActionTextBehavior.HIDE);
            mRoot.setTop(mToolBar);
        } else {
            mToolBar = ActionUtils.updateToolBar(mToolBar, actions, ActionUtils.ActionTextBehavior.HIDE);
            mToolBar.getItems().add(1, mIndicator);
            mIndicator.setVisible(runState != RunState.STARTABLE);
        }

        FxHelper.adjustButtonWidth(mToolBar.getItems().stream(), ICON_SIZE_TOOLBAR * 1.5);
        mToolBar.getItems().stream().filter((item) -> (item instanceof ButtonBase))
                .map((item) -> (ButtonBase) item).forEachOrdered((buttonBase) -> {
                    FxHelper.undecorateButton(buttonBase);
                });
    });
}

From source file:com.neuronrobotics.bowlerstudio.MainController.java

@FXML
public void onConnectGamePad(ActionEvent event) {
    Platform.runLater(() -> ConnectionManager.onConnectGamePad("gamepad"));

}