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.sleuthkit.autopsy.imageanalyzer.grouping.GroupManager.java

synchronized public void clear() {

    if (groupByTask != null) {
        groupByTask.cancel(true);//from  ww  w .  ja va 2 s .c  om
    }
    sortBy = GroupSortBy.GROUP_BY_VALUE;
    groupBy = DrawableAttribute.PATH;
    sortOrder = SortOrder.ASCENDING;
    Platform.runLater(() -> {
        synchronized (unSeenGroups) {
            unSeenGroups.clear();
        }
        analyzedGroups.clear();
    });
    synchronized (groupMap) {
        groupMap.clear();
    }
    db = null;
}

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

synchronized public void clear() {

    if (groupByTask != null) {
        groupByTask.cancel(true);/*from  w w  w. j  av  a  2 s .  c  o  m*/
    }
    sortBy = GroupSortBy.GROUP_BY_VALUE;
    groupBy = DrawableAttribute.PATH;
    sortOrder = SortOrder.ASCENDING;
    Platform.runLater(() -> {
        unSeenGroups.clear();
        analyzedGroups.clear();
    });
    synchronized (groupMap) {
        groupMap.clear();
    }
    db = null;
}

From source file:Dominion.DynamicCard.ClientModelService.java

private synchronized void handleControlPackage(JSONObject obj) {
    String subject = obj.getString("subject");
    switch (subject) {
    case ("hand"): {
        String control = obj.getString("control");
        switch (control) {
        case ("clickable"): {
            ArrayList<Card> itemlist = new ArrayList<>();
            if (obj.getString("items").equals("all")) {
                for (Card c : currentHand) {
                    itemlist.add(c);/*ww w.ja v  a2 s  . c om*/
                }
            } else {
                final String[] items = obj.getString("items").split(",");
                for (Card c : currentHand) {
                    for (String name : items) {
                        if (c.getName().equals(name)) {
                            itemlist.add(c);
                            break;
                        }
                    }
                }
            }
            for (Card c : itemlist) {
                c.makeClickable();
            }

            break;
        }
        case ("unclickable"): {
            ArrayList<Card> itemlist = new ArrayList<>();
            if (obj.getString("items").equals("all")) {
                for (Card c : currentHand) {
                    itemlist.add(c);
                }
            } else {
                final String[] items = obj.getString("items").split(",");
                for (Card c : currentHand) {
                    for (String name : items) {
                        if (c.getName().equals(name)) {
                            itemlist.add(c);
                            break;
                        }
                    }
                }
            }
            for (Card c : itemlist) {
                c.makeUnclickable();
            }

            break;
        }
        default: {
            System.out.println(control + " is an unknown control for subject " + subject);
        }
        }
        break;
    }
    case ("phase"): {
        String control = obj.getString("control");
        controller.EndPhase.setDisable(control.equals("unclickable"));
        break;
    }
    case ("environment"): {
        String control = obj.getString("control");
        switch (control) {
        case ("init"): {
            if (obj.getString("stack").equals("Treasure")) {
                init_treasure();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.initializeTreasureStack(environment.get("copper"), environment.get("silver"),
                                environment.get("gold"));
                    }

                });
                return;
            } else if (obj.getString("stack").equals("Victory")) {
                init_victory();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.initializeVictoryStack(environment.get("estate"), environment.get("duchy"),
                                environment.get("province"));
                    }

                });
                return;
            } else if (obj.getString("stack").equals("deck_and_discard")) {

                final Card disc_back = new Card("back", controller, "MEDIUM");
                Stack discardpile;
                discardpile = new Stack(disc_back, 0);
                environment.put("discardpile", discardpile);

                final Card deck_back = new Card("back", controller, "MEDIUM");
                Stack deck;
                deck = new Stack(deck_back, 10);
                environment.put("deck", deck);

                final Card trash_back = new Card("trash", controller, "MEDIUM");
                Stack trash;
                trash = new Stack(trash_back, 0);
                environment.put("trashpile", trash);

                final Card curse_back = new Card("curse", controller, "MEDIUM");
                Stack curses;
                curses = new Stack(curse_back, 10);
                environment.put("cursepile", curses);

                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.initialize_myenvironment(environment.get("deck"),
                                environment.get("discardpile"), environment.get("trashpile"),
                                environment.get("cursepile"));
                    }

                });

                return;
            }
            // Initialize actioncards in environment
            // Does not make use of "count" yet -> TODO!
            final Card actionStack = new Card(obj.getString("stack"), controller, "MEDIUM");
            final Stack realStack = new Stack(actionStack, 10);
            environment.put(obj.getString("stack"), realStack);

            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    controller.initializeActionStack(realStack);
                }

            });
            break;
        }
        case ("updatecount"): {
            // Update count of environment cardstacks
            final Stack st = environment.get(obj.getString("stack"));
            final int count = Integer.parseInt(obj.getString("update"));
            if (st == null) {
                System.out.println("NULL UPDATE CAUGHT AND THROWN");
                break;
            }
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    st.update(count);
                }

            });
            // If count == 0 -> should show the back.jpg of the card instead of the front. 
            break;
        }
        case ("clickable"): {
            String names = obj.getString("items");
            String[] namelist = names.split(",");
            for (String cardname : namelist) {
                //environment.get(cardname).makeClickable();
                // CAUSES BUG -> Imageviews cannot be made clickable, 
                // Because the imageview does not link the view of the card. 
                // Changing the cardview therefore will not have affected the glow
                // And so the client crashes. 
            }
            break;
        }
        case ("unclickable"): {
            if (obj.getString("items").equals("all")) {
                for (String s : environment.keySet()) {
                    //environment.get(s).makeUnclickable();
                    // See above bug.
                }
            } else {
                System.err.println("NOT IMPLEMENTED YET -> unclickable environment specified cards");
            }
            break;
        }
        case ("updateview"): {
            String stackname = obj.getString("stack");
            // Should be only used with discardpile atm 
            if (stackname == null) {
                System.out.println("UPDATE NULL VIEW DISCARDED");
                break;
            }
            if (stackname.equals("discardpile")) {
                Stack s = environment.get(stackname);
                String cardname = obj.getString("update");
                Card medium_print = new Card(cardname, controller, "MEDIUM");
                Stack replace = new Stack(medium_print, s.count);
                environment.put(stackname, replace);
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.reinitialize_disc(environment.get("discardpile"));
                    }

                });
            } else if (stackname.equals("trashpile")) {
                Stack s = environment.get(stackname);
                String cardname = obj.getString("update");
                Card medium_print = new Card(cardname, controller, "MEDIUM");
                Stack replace = new Stack(medium_print, s.count);
                environment.put(stackname, replace);
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.reinitialize_trash(environment.get("trashpile"));
                    }

                });
            } else if (stackname.equals("cursepile")) {
                Stack s = environment.get(stackname);
                String cardname = obj.getString("update");
                Card medium_print = new Card(cardname, controller, "MEDIUM");
                Stack replace = new Stack(medium_print, s.count);
                environment.put(stackname, replace);
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        controller.reinitialize_curse(environment.get("cursepile"));
                    }

                });
            } else {
                System.err.println(
                        "updateview on environment is only implemented (and only used) for discardpile.");
            }

        }
        }
        break;
    }
    case ("table"): {
        String control = obj.getString("control");
        switch (control) {
        case ("add"): {
            String cardname = obj.getString("cardname");
            final Card c = new Card(cardname);
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    controller.addCardToTable(c.getView());
                }

            });
            break;
        }
        case ("clear"): {
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    controller.refreshTableCardView();
                }

            });
            break;
        }
        }
        break;
    }
    default: {
        System.err.println("Subject [" + subject + "] not implemented");
    }
    }
}

From source file:org.sleuthkit.autopsy.imageanalyzer.ImageAnalyzerController.java

private ImageAnalyzerController() {

    listeningEnabled.addListener(/*from w w w  . j  a  v a2 s . co  m*/
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && !oldValue && Case.existsCurrentCase()
                        && ImageAnalyzerModule.isCaseStale(Case.getCurrentCase())) {
                    queueDBWorkerTask(new CopyAnalyzedFiles());
                }
            });

    groupManager.getAnalyzedGroups().addListener((Observable o) -> {
        checkForGroups();
    });

    groupManager.getUnSeenGroups().addListener((Observable observable) -> {
        //if there are unseen groups and none being viewed
        if (groupManager.getUnSeenGroups().size() > 0
                && (getViewState() == null || getViewState().getGroup() == null)) {
            advance(GroupViewState.tile(groupManager.getUnSeenGroups().get(0)));
        }
    });

    viewState().addListener((Observable observable) -> {
        selectionModel.clearSelection();
    });

    regroupDisabled.addListener((Observable observable) -> {
        checkForGroups();
    });

    IngestManager.getInstance().addIngestModuleEventListener((PropertyChangeEvent evt) -> {
        Platform.runLater(this::updateRegroupDisabled);
    });
    IngestManager.getInstance().addIngestJobEventListener((PropertyChangeEvent evt) -> {
        Platform.runLater(this::updateRegroupDisabled);
    });
    //        metaDataCollapsed.bind(Toolbar.getDefault().showMetaDataProperty());
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.GroupTreeItem.java

void removeFromParent() {
    final GroupTreeItem parent = (GroupTreeItem) getParent();
    if (parent != null) {
        parent.childMap.remove(getValue().getPath());

        Platform.runLater(() -> {
            synchronized (parent.getChildren()) {
                parent.getChildren().removeAll(Collections.singleton(GroupTreeItem.this));
            }//from   w  w  w  .j  av  a 2 s.  c  om
        });

        if (parent.childMap.isEmpty()) {
            parent.removeFromParent();
        }
    }
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.NavPanel.java

/**
 * Set the tree to the passed in group/*from  ww w  .j  a  v  a2 s .  c o  m*/
 *
 * @param grouping
 */
public void setFocusedGroup(DrawableGroup grouping) {

    List<String> path = groupingToPath(grouping);

    final GroupTreeItem treeItemForGroup = ((GroupTreeItem) activeTreeProperty.get().getRoot())
            .getTreeItemForPath(path);

    if (treeItemForGroup != null) {
        Platform.runLater(() -> {
            TreeItem<TreeNode> ti = treeItemForGroup;
            while (ti != null) {
                ti.setExpanded(true);
                ti = ti.getParent();
            }
            int row = activeTreeProperty.get().getRow(treeItemForGroup);
            if (row != -1) {
                activeTreeProperty.get().getSelectionModel().select(treeItemForGroup);
                activeTreeProperty.get().scrollTo(row);
            }
        });
    }
}

From source file:com.panemu.tiwulfx.control.LookupFieldController.java

/**
 * Show lookup dialog./*from w ww .  j  a v a  2s. c o m*/
 *
 * @param stage parent
 * @param initialValue this value will be returned if user clik the close
 * button instead of double clicking a row or click Select button
 * @param propertyName propertyName corresponds to searchCriteria
 * @param searchCriteria searchCriteria (nullable)
 * @return selected object or the initialValue
 */
public T show(final Window stage, T initialValue, String propertyName, String searchCriteria) {
    if (dialogStage == null) {
        PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(recordClass);
        lookupWindow = new LookupWindow();
        for (String clm : getColumns()) {
            for (PropertyDescriptor prop : props) {
                if (prop.getName().equals(clm)) {
                    Class type = prop.getPropertyType();
                    if (type.equals(Boolean.class)) {
                        lookupWindow.table.addColumn(new CheckBoxColumn<T>(clm));
                    } else if (type.equals(String.class)) {
                        lookupWindow.table.addColumn(new TextColumn<T>(clm));
                    } else if (type.equals(Date.class)) {
                        lookupWindow.table.addColumn(new LocalDateColumn<T>(clm));
                    } else if (Number.class.isAssignableFrom(type)) {

                        if (Long.class.isAssignableFrom(type)) {
                            lookupWindow.table.addColumn(new NumberColumn<T, Long>(clm, type));
                        } else {
                            lookupWindow.table.addColumn(new NumberColumn<T, Double>(clm, type));
                        }
                    } else {
                        TableColumn column = new TableColumn();
                        column.setCellValueFactory(new PropertyValueFactory(clm));
                        lookupWindow.table.addColumn(column);
                    }
                    break;
                }
            }

        }
        dialogStage = new Stage();
        if (stage instanceof Stage) {
            dialogStage.initOwner(stage);
            dialogStage.initModality(Modality.WINDOW_MODAL);
        } else {
            dialogStage.initOwner(null);
            dialogStage.initModality(Modality.APPLICATION_MODAL);
        }
        dialogStage.initStyle(StageStyle.UTILITY);
        dialogStage.setResizable(true);
        dialogStage.setScene(new Scene(lookupWindow));
        dialogStage.getIcons().add(new Image(
                LookupFieldController.class.getResourceAsStream("/com/panemu/tiwulfx/res/image/lookup.png")));
        dialogStage.setTitle(getWindowTitle());
        dialogStage.getScene().getStylesheets()
                .add(getClass().getResource("/com/panemu/tiwulfx/res/tiwulfx.css").toExternalForm());
        initCallback(lookupWindow, lookupWindow.table);
    }

    for (TableColumn column : lookupWindow.table.getTableView().getColumns()) {
        if (column instanceof BaseColumn && ((BaseColumn) column).getPropertyName().equals(propertyName)) {
            if (searchCriteria != null && !searchCriteria.isEmpty()) {
                TableCriteria tc = new TableCriteria(propertyName, TableCriteria.Operator.ilike_anywhere,
                        searchCriteria);
                ((BaseColumn) column).setTableCriteria(tc);
            } else {
                ((BaseColumn) column).setTableCriteria(null);
            }

            break;
        }
    }
    selectedValue = initialValue;
    beforeShowCallback(lookupWindow.table);
    lookupWindow.table.reloadFirstPage();

    if (stage != null) {
        /**
         * Since we support multiple monitors, ensure that the stage is
         * located in the center of parent stage. But we don't know the
         * dimension of the stage for the calculation, so we defer the
         * relocation after the stage is actually displayed.
         */
        Runnable runnable = new Runnable() {
            public void run() {
                dialogStage.setX(stage.getX() + stage.getWidth() / 2 - dialogStage.getWidth() / 2);
                dialogStage.setY(stage.getY() + stage.getHeight() / 2 - dialogStage.getHeight() / 2);

                //set the opacity back to fully opaque
                dialogStage.setOpacity(1);
            }
        };

        Platform.runLater(runnable);

        //set the opacity to 0 to minimize flicker effect
        dialogStage.setOpacity(0);
    }

    dialogStage.showAndWait();
    return selectedValue;
}

From source file:ijfx.ui.plugin.panel.OverlayPanel.java

@EventHandler
public void onOverlayUpdated(OverlayUpdatedEvent event) {
    Platform.runLater(() -> updateChart(event.getObject()));
}

From source file:acmi.l2.clientmod.xdat.Controller.java

public void registerVersion(String name, String xdatClass) {
    RadioMenuItem menuItem = new RadioMenuItem(name);
    menuItem.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            editor.execute(() -> {//from  w w  w  . j  av a 2 s  .co m
                Class<? extends IOEntity> clazz = Class
                        .forName(xdatClass, true, new GroovyClassLoader(getClass().getClassLoader()))
                        .asSubclass(IOEntity.class);
                Platform.runLater(() -> editor.setXdatClass(clazz));
                return null;
            }, e -> {
                log.log(Level.WARNING, String.format("%s: XDAT class load error", name), e);
                Platform.runLater(() -> {
                    version.getToggles().remove(menuItem);
                    versionMenu.getItems().remove(menuItem);

                    Dialogs.show(Alert.AlertType.ERROR, name + ": XDAT class load error", null,
                            e.getClass().getSimpleName() + ": " + e.getMessage());
                });
            });
        }
    });
    version.getToggles().add(menuItem);
    versionMenu.getItems().add(menuItem);
}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

void addChromatogram(Chromatogram chromatogram, String title) {

    if (!Platform.isFxApplicationThread()) {
        throw new IllegalStateException(
                "Not on FX application thread; currentThread = " + Thread.currentThread().getName());
    }// w w w. j a v  a 2 s . c  o m

    final int datasetIndex = numberOfDataSets;
    numberOfDataSets++;

    ChromatogramDataSet newDataSet = new ChromatogramDataSet(chromatogram, title);

    datasets.add(newDataSet);

    final XYPlot plot = chartNode.getChart().getXYPlot();

    final Color newColor = plotColors[datasetIndex % plotColors.length];
    newDataSet.setColor(newColor);

    configureRenderer(newDataSet, datasetIndex);

    newDataSet.colorProperty().addListener(e -> {
        Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex));
    });

    newDataSet.lineThicknessProperty().addListener(e -> {
        Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex));
    });
    newDataSet.showDataPointsProperty().addListener(e -> {
        Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex));
    });

    // Once everything is configured, add the dataset to the plot
    plot.setDataset(datasetIndex, newDataSet);
}