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:frontend.GUIController.java

public Thread processInput(Runnable rSuccess, Runnable rFail) throws Exception {
    System.out.println("Steping to next step...");
    progressBar.progressProperty().unbind();
    progressMessage.textProperty().unbind();
    next1.setDisable(true);//from   w  ww .  j a  v a2 s  .  c o  m
    final ArrayList<String> comboBoxValues = new ArrayList<String>();
    for (ComboBox<String> c : comboBoxes) {
        comboBoxValues.add(c.getValue());
    }
    Task<Boolean> t = new Task<Boolean>() {
        @Override
        protected Boolean call() throws Exception {
            updateMessage("Doing Prediction");
            updateProgress(3, 10);
            int status = at.processAfterLoadFile(comboBoxValues, predModel.getValue(), visualize.isSelected(),
                    predicted.isSelected());
            if (status > 0) {
                System.err.println("ProcessAfterLoadFile Error occured.");
                return false;
            }
            updateMessage("Finished Prediction");
            if (visualize.isSelected()) {
                updateProgress(5, 10);
                at.showVisualization();
                updateMessage("Finished Visualization");
                updateProgress(8, 10);
            }
            updateProgress(10, 10);
            updateMessage("Done");

            //webpage.getChildren().add(new Browser(url));
            //at.addTweets(at.outputDir+"/visualization/Sentiment.tsv", personData);
            return true;
        };

        @Override
        protected void succeeded() {
            super.succeeded();
            updateMessage("Done!");
        }

        @Override
        protected void cancelled() {
            super.cancelled();
            updateMessage("Cancelled!");
        }

        @Override
        protected void failed() {
            super.failed();
            updateMessage("Failed!");
        }

        @Override
        protected void done() {
            super.done();
            updateMessage("Done!");
        }
    };
    progressBar.progressProperty().bind(t.progressProperty());
    progressMessage.textProperty().bind(t.messageProperty());

    t.setOnSucceeded(new EventHandler<WorkerStateEvent>() {

        @Override
        public void handle(WorkerStateEvent event) {
            if (t.getValue()) {
                Platform.runLater(rSuccess);
            } else {
                Platform.runLater(rFail);
            }
        }
    });

    Thread mythread = new Thread(t);
    mythread.start();
    return mythread;
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.drawableviews.GroupPane.java

/**
 * called automatically during constructor by FXMLConstructor.
 *
 * checks that FXML loading went ok and performs additional setup
 *///from  w  ww .  j a  v a 2s . c om
@FXML
@NbBundle.Messages({ "GroupPane.gridViewContextMenuItem.extractFiles=Extract File(s)",
        "GroupPane.bottomLabel.displayText=Group Viewing History: ",
        "GroupPane.hederLabel.displayText=Tag Selected Files:",
        "GroupPane.catContainerLabel.displayText=Categorize Selected File:",
        "GroupPane.catHeadingLabel.displayText=Category:" })
void initialize() {
    assert cat0Toggle != null : "fx:id=\"cat0Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat1Toggle != null : "fx:id=\"cat1Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat2Toggle != null : "fx:id=\"cat2Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat3Toggle != null : "fx:id=\"cat3Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat4Toggle != null : "fx:id=\"cat4Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat5Toggle != null : "fx:id=\"cat5Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert gridView != null : "fx:id=\"tilePane\" was not injected: check your FXML file 'GroupPane.fxml'.";
    assert catSelectedSplitMenu != null : "fx:id=\"grpCatSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tagSelectedSplitMenu != null : "fx:id=\"grpTagSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert headerToolBar != null : "fx:id=\"headerToolBar\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert segButton != null : "fx:id=\"previewList\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert slideShowToggle != null : "fx:id=\"segButton\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tileToggle != null : "fx:id=\"tileToggle\" was not injected: check your FXML file 'GroupHeader.fxml'.";

    for (Category cat : Category.values()) {
        ToggleButton toggleForCategory = getToggleForCategory(cat);
        toggleForCategory.setBorder(new Border(
                new BorderStroke(cat.getColor(), BorderStrokeStyle.SOLID, CORNER_RADII_2, BORDER_WIDTHS_2)));
        toggleForCategory.getStyleClass().remove("radio-button");
        toggleForCategory.getStyleClass().add("toggle-button");
        toggleForCategory.selectedProperty().addListener((ov, wasSelected, toggleSelected) -> {
            if (toggleSelected && slideShowPane != null) {
                slideShowPane.getFileID().ifPresent(fileID -> {
                    selectionModel.clearAndSelect(fileID);
                    new CategorizeAction(controller, cat, ImmutableSet.of(fileID)).handle(null);
                });
            }
        });
    }

    //configure flashing glow animation on next unseen group button
    flashAnimation.setCycleCount(Timeline.INDEFINITE);
    flashAnimation.setAutoReverse(true);

    //configure gridView cell properties
    DoubleBinding cellSize = controller.thumbnailSizeProperty().add(75);
    gridView.cellHeightProperty().bind(cellSize);
    gridView.cellWidthProperty().bind(cellSize);
    gridView.setCellFactory((GridView<Long> param) -> new DrawableCell());

    BooleanBinding isSelectionEmpty = Bindings.isEmpty(selectionModel.getSelected());
    catSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);
    tagSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);

    Platform.runLater(() -> {
        try {
            TagSelectedFilesAction followUpSelectedACtion = new TagSelectedFilesAction(
                    controller.getTagsManager().getFollowUpTagName(), controller);
            tagSelectedSplitMenu.setText(followUpSelectedACtion.getText());
            tagSelectedSplitMenu.setGraphic(followUpSelectedACtion.getGraphic());
            tagSelectedSplitMenu.setOnAction(followUpSelectedACtion);
        } catch (TskCoreException tskCoreException) {
            LOGGER.log(Level.WARNING, "failed to load FollowUpTagName", tskCoreException); //NON-NLS
        }
        tagSelectedSplitMenu.showingProperty().addListener(showing -> {
            if (tagSelectedSplitMenu.isShowing()) {
                List<MenuItem> selTagMenues = Lists.transform(
                        controller.getTagsManager().getNonCategoryTagNames(),
                        tagName -> GuiUtils.createAutoAssigningMenuItem(tagSelectedSplitMenu,
                                new TagSelectedFilesAction(tagName, controller)));
                tagSelectedSplitMenu.getItems().setAll(selTagMenues);
            }
        });

    });

    CategorizeSelectedFilesAction cat5SelectedAction = new CategorizeSelectedFilesAction(Category.FIVE,
            controller);
    catSelectedSplitMenu.setOnAction(cat5SelectedAction);
    catSelectedSplitMenu.setText(cat5SelectedAction.getText());
    catSelectedSplitMenu.setGraphic(cat5SelectedAction.getGraphic());
    catSelectedSplitMenu.showingProperty().addListener(showing -> {
        if (catSelectedSplitMenu.isShowing()) {
            List<MenuItem> categoryMenues = Lists.transform(Arrays.asList(Category.values()),
                    cat -> GuiUtils.createAutoAssigningMenuItem(catSelectedSplitMenu,
                            new CategorizeSelectedFilesAction(cat, controller)));
            catSelectedSplitMenu.getItems().setAll(categoryMenues);
        }
    });

    slideShowToggle.getStyleClass().remove("radio-button");
    slideShowToggle.getStyleClass().add("toggle-button");
    tileToggle.getStyleClass().remove("radio-button");
    tileToggle.getStyleClass().add("toggle-button");

    bottomLabel.setText(Bundle.GroupPane_bottomLabel_displayText());
    headerLabel.setText(Bundle.GroupPane_hederLabel_displayText());
    catContainerLabel.setText(Bundle.GroupPane_catContainerLabel_displayText());
    catHeadingLabel.setText(Bundle.GroupPane_catHeadingLabel_displayText());
    //show categorization controls depending on group view mode
    headerToolBar.getItems().remove(catSegmentedContainer);
    groupViewMode.addListener((ObservableValue<? extends GroupViewMode> observable, GroupViewMode oldValue,
            GroupViewMode newValue) -> {
        if (newValue == GroupViewMode.SLIDE_SHOW) {
            headerToolBar.getItems().remove(catSplitMenuContainer);
            headerToolBar.getItems().add(catSegmentedContainer);
        } else {
            headerToolBar.getItems().remove(catSegmentedContainer);
            headerToolBar.getItems().add(catSplitMenuContainer);
        }
    });

    //listen to toggles and update view state
    slideShowToggle
            .setOnAction(onAction -> activateSlideShowViewer(selectionModel.lastSelectedProperty().get()));
    tileToggle.setOnAction(onAction -> activateTileViewer());

    controller.viewState().addListener((observable, oldViewState, newViewState) -> setViewState(newViewState));

    addEventFilter(KeyEvent.KEY_PRESSED, tileKeyboardNavigationHandler);
    gridView.addEventHandler(MouseEvent.MOUSE_CLICKED, new MouseHandler());

    ActionUtils.configureButton(undoAction, undoButton);
    ActionUtils.configureButton(redoAction, redoButton);
    ActionUtils.configureButton(forwardAction, forwardButton);
    ActionUtils.configureButton(backAction, backButton);
    ActionUtils.configureButton(nextGroupAction, nextButton);
    /*
     * the next button does stuff in the GroupPane that next action does'nt
     * know about, so do that stuff and then delegate to nextGroupAction
     */
    final EventHandler<ActionEvent> onAction = nextButton.getOnAction();
    nextButton.setOnAction(actionEvent -> {
        flashAnimation.stop();
        nextButton.setEffect(null);
        onAction.handle(actionEvent);
    });

    nextGroupAction.disabledProperty().addListener((Observable observable) -> {
        boolean newValue = nextGroupAction.isDisabled();
        nextButton.setEffect(newValue ? null : DROP_SHADOW);
        if (newValue) {//stop on disabled
            flashAnimation.stop();
        } else { //play when enabled
            flashAnimation.play();
        }
    });

    //listen to tile selection and make sure it is visible in scroll area
    selectionModel.lastSelectedProperty().addListener((observable, oldFileID, newFileId) -> {
        if (groupViewMode.get() == GroupViewMode.SLIDE_SHOW && slideShowPane != null) {
            slideShowPane.setFile(newFileId);
        } else {
            scrollToFileID(newFileId);
        }
    });

    setViewState(controller.viewState().get());
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public void runInUiThreadLater(Runnable toRun) {
    Platform.runLater(toRun);
}

From source file:com.github.drbookings.ui.controller.MainController.java

@FXML
private void handleMenuItemRoomDetails(final ActionEvent event) {
    Platform.runLater(() -> showRoomDetailsDialog());
}

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

private void updateTripData(Trip t) {
    WayPoint wp = t.firstWayPoint();/*from w w w  .j  a  va2  s. c o  m*/
    Date d = new Date(wp.getTime());
    String dateKey = keyFromDate(d);
    List<Trip> tripsForDay = dateToTrips.get(dateKey);
    if (tripsForDay == null) {
        tripsForDay = new ArrayList<>();
        dateToTrips.put(dateKey, tripsForDay);
    }
    tripsForDay.add(t);

    if (dateIsSelected(d)) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                updateTripSelections();
            }
        });
    }

}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventNodeBase.java

@Subscribe
public void handleTimeLineTagEvent(TagsAddedEvent event) {
    if (false == Sets.intersection(getEvent().getEventIDs(), event.getUpdatedEventIDs()).isEmpty()) {
        Platform.runLater(() -> {
            show(tagIV, true);//from  w  w  w .  ja  v  a2s .c  o m
        });
    }
}

From source file:com.github.drbookings.ui.controller.MainController.java

@FXML
private void handleMenuItemSettingsGeneral(final ActionEvent event) {
    Platform.runLater(() -> showSettingsGeneral());
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public void runInUiThreadAndWait(final Runnable toRun) throws InterruptedException, InvocationTargetException {
    if (Platform.isFxApplicationThread()) {
        toRun.run();/*from  w  w w. j a  v  a  2 s  .c  o m*/
        return;
    }

    final CountDownLatch doneLatch = new CountDownLatch(1);
    Platform.runLater(() -> {
        try {
            toRun.run();
        } finally {
            doneLatch.countDown();
        }
    });

    doneLatch.await();
}

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

void setSortBy(GroupSortBy sortBy) {
    this.sortBy = sortBy;
    Platform.runLater(() -> sortByProp.set(sortBy));
}

From source file:com.github.drbookings.ui.controller.MainController.java

@FXML
private void handleMenuItemSettingsICal(final ActionEvent event) {
    Platform.runLater(() -> showSettingsICal());
}