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:ninja.eivind.hotsreplayuploader.window.HomeController.java

public void switchToUploaderView() {
    Platform.runLater(() -> {
        if (uploaderNode == null) {
            uploaderNode = (UploaderNode) builderFactory.getBuilder(UploaderNode.class).build();
        }/*ww  w .  j  a va  2s  . co m*/
        if (currentContext == uploaderNode) {
            return;
        }
        uploaderNode.activate();

        nodeHolder.getChildren().clear();
        nodeHolder.getChildren().add(uploaderNode);

    });
}

From source file:herudi.controller.productController.java

/**
 * Initializes the controller class.//  w  w  w.j  ava 2 s .  co  m
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    Platform.runLater(() -> {
        ApplicationContext ctx = config.getInstance().getApplicationContext();
        crud = ctx.getBean(interProduct.class);
        listData = FXCollections.observableArrayList();
        status = 0;
        available = "";
        config2.setModelColumn(colAvailable, "available");
        config2.setModelColumn(colDescription, "description");
        config2.setModelColumn(colManufacturerIid, "manufacturerId");
        config2.setModelColumn(colMarkup, "markup");
        config2.setModelColumn(colProductCode, "productCode");
        config2.setModelColumn(colProductId, "productId");
        config2.setModelColumn(colPurchaseCost, "formatCost");
        config2.setModelColumn(colQuantityOnHand, "quantityOnHand");
        colAction.setCellValueFactory(
                new Callback<TableColumn.CellDataFeatures<Object, Boolean>, ObservableValue<Boolean>>() {
                    @Override
                    public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<Object, Boolean> p) {
                        return new SimpleBooleanProperty(p.getValue() != null);
                    }
                });
        colAction.setCellFactory(new Callback<TableColumn<Object, Boolean>, TableCell<Object, Boolean>>() {
            @Override
            public TableCell<Object, Boolean> call(TableColumn<Object, Boolean> p) {
                return new ButtonCell(tableData);
            }
        });
        selectWithService();
        displayManufacturer();
        displayProductCode();
    });
    // TODO
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.navpanel.GroupTreeCell.java

/**
 * {@inheritDoc }/*from   ww w  .j a  v a 2 s. c o  m*/
 */
@Override
protected synchronized void updateItem(final TreeNode treeNode, boolean empty) {
    //if there was a previous group, remove the listeners
    Optional.ofNullable(getItem()).map(TreeNode::getGroup).ifPresent(group -> {
        group.fileIds().removeListener(fileCountListener);
        group.seenProperty().removeListener(seenListener);
    });

    super.updateItem(treeNode, empty);

    if (isNull(treeNode) || empty) {
        Platform.runLater(() -> {
            setTooltip(null);
            setText(null);
            setGraphic(null);
            setStyle("");
        });
    } else {

        if (isNull(treeNode.getGroup())) {
            final String groupName = getGroupName();
            //"dummy" group in file system tree <=>  a folder with no drawables
            Platform.runLater(() -> {
                setTooltip(new Tooltip(groupName));
                setText(groupName);
                setGraphic(new ImageView(EMPTY_FOLDER_ICON));
                setStyle("");
            });

        } else {
            //if number of files in this group changes (eg a file is recategorized), update counts via listener
            treeNode.getGroup().fileIds().addListener(fileCountListener);

            //if the seen state of this group changes update its style
            treeNode.getGroup().seenProperty().addListener(seenListener);

            //and use icon corresponding to group type
            final Image icon = treeNode.getGroup().groupKey.getAttribute().getIcon();
            final String text = getGroupName() + getCountsText();
            final String style = getSeenStyleClass();
            Platform.runLater(() -> {
                setTooltip(new Tooltip(text));
                setGraphic(new ImageView(icon));
                setText(text);
                setStyle(style);
            });
        }
    }
}

From source file:deincraftlauncher.start.StartMinecraft.java

private static void checkAlive(Process launch, Modpack pack) {

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override//from w  ww  .  java 2 s  .c  o m
        public void run() {
            if (!launch.isAlive()) {
                Platform.runLater(() -> {
                    System.out.println("minecraft stopped, process is dead!");
                    pack.setPackstarted(false);
                    pack.setStartState(PackViewHandler.StartState.Normal);
                    pack.setStartText("Spielen");
                });
            } else {
                checkAlive(launch, pack);
            }
        }
    }, 3000);
}

From source file:de.chaosfisch.uploader.gui.renderer.ProgressNodeRenderer.java

public void setEta(final String eta) {
    Platform.runLater(new Runnable() {

        @Override/*from   w w  w .jav  a2 s  . co m*/
        public void run() {
            progressEta.setText(eta);
        }
    });
}

From source file:org.mskcc.shenkers.view.IntervalViewNGTest.java

public void testIntervalView() throws InterruptedException {
    System.out.println("testIntervalView");
    Pane p = new Pane();

    CountDownLatch l = new CountDownLatch(1);
    System.out.println("before");
    Platform.runLater(() -> {
        System.out.println("running");
        double[][] intervals = { { .1, .2 } };
        //                    Range r = null;
        RangeSet<Double> rs = TreeRangeSet.create();
        rs.add(Range.closed(.1, .2));/*w w  w . j  a va 2  s. com*/
        rs.add(Range.closed(.2, .3));
        rs.add(Range.closed(.32, .35));
        rs.add(Range.closed(.6, .8));

        for (Range<Double> r : rs.asRanges()) {
            System.out.println(r.lowerEndpoint() + " - " + r.upperEndpoint());
        }
        for (Range<Double> interval : rs.asRanges()) {
            Rectangle r = new Rectangle();
            r.widthProperty()
                    .bind(p.widthProperty().multiply(interval.upperEndpoint() - interval.lowerEndpoint()));
            r.heightProperty().bind(p.heightProperty());
            r.xProperty().bind(p.widthProperty().multiply(interval.lowerEndpoint()));
            p.getChildren().add(r);
        }
        //                    p.prefTileHeightProperty().bind(p.heightProperty());
        Stage stage = new Stage();
        stage.setOnHidden(e -> {
            l.countDown();
            System.out.println("count " + l.getCount());
        });
        Scene scene = new Scene(p, 300, 300, Color.GRAY);
        stage.setTitle("JavaFX Scene Graph Demo");
        stage.setScene(scene);
        stage.show();

    });
    System.out.println("after");
    l.await();
    Thread.sleep(1000);
}

From source file:net.rptools.layercontrol.LayerStackLayer.java

/**
 * Remove a layer./*from  ww  w .j ava  2s .  com*/
 * @param layer layer to remove
 */
@ThreadPolicy(ThreadPolicy.ThreadId.ANY)
public synchronized void removeLayer(final Layer layer) {
    if (!Platform.isFxApplicationThread()) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                removeLayer(layer);
            }
        });
    }
    // Now on JFX thread
    getDrawable().getChildren().remove(layer.getDrawable());
}

From source file:herudi.controller.customerController.java

/**
 * Initializes the controller class.//from   www . j  a  v  a2s.c om
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    Platform.runLater(() -> {
        ApplicationContext ctx = config.getInstance().getApplicationContext();
        crud = ctx.getBean(interCustomer.class);
        listData = FXCollections.observableArrayList();
        status = 0;
        config2.setModelColumn(colAdderss1, "addressline1");
        config2.setModelColumn(colAddress2, "addressline2");
        config2.setModelColumn(colCity, "city");
        config2.setModelColumn(colCreditLimit, "creditLimit");
        config2.setModelColumn(colCustomerId, "customerId");
        config2.setModelColumn(colDiscountCode, "discountCode");
        config2.setModelColumn(colEmail, "email");
        config2.setModelColumn(colFax, "fax");
        config2.setModelColumn(colName, "name");
        config2.setModelColumn(colPhone, "phone");
        config2.setModelColumn(colState, "state");
        config2.setModelColumn(colZip, "zip");
        colAction.setCellValueFactory(
                new Callback<TableColumn.CellDataFeatures<Object, Boolean>, ObservableValue<Boolean>>() {
                    @Override
                    public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<Object, Boolean> p) {
                        return new SimpleBooleanProperty(p.getValue() != null);
                    }
                });
        colAction.setCellFactory(new Callback<TableColumn<Object, Boolean>, TableCell<Object, Boolean>>() {
            @Override
            public TableCell<Object, Boolean> call(TableColumn<Object, Boolean> p) {
                return new ButtonCell(tableData);
            }
        });
        selectWithService();
        displayDiscountCode();
        displayZip();
    });
    // TODO
}

From source file:com.cdd.bao.editor.endpoint.BrowseEndpoint.java

public BrowseEndpoint(Stage stage) {
    this.stage = stage;

    stage.setTitle("BioAssay Schema Browser");

    treeRoot = new TreeItem<>(new Branch(this));
    treeView = new TreeView<>(treeRoot);
    treeView.setEditable(true);//from w  w w . ja  v a2s .  c om
    treeView.setCellFactory(p -> new BrowseTreeCell());
    treeView.getSelectionModel().selectedItemProperty().addListener((observable, oldval, newval) -> {
        changeValue(newval.getValue());
    });

    display = new DisplaySchema();

    StackPane sp1 = new StackPane(), sp2 = new StackPane();
    sp1.getChildren().add(treeView);
    sp2.getChildren().add(display);

    splitter = new SplitPane();
    splitter.setOrientation(Orientation.HORIZONTAL);
    splitter.getItems().addAll(sp1, sp2);
    splitter.setDividerPositions(0.4, 1.0);

    root = new BorderPane();
    root.setTop(menuBar);
    root.setCenter(splitter);

    Scene scene = new Scene(root, 700, 600, Color.WHITE);

    stage.setScene(scene);

    treeView.setShowRoot(false);

    rebuildTree();

    Platform.runLater(() -> treeView.getFocusModel().focus(treeView.getSelectionModel().getSelectedIndex())); // for some reason it defaults to not the first item

    new Thread(() -> backgroundLoadTemplates()).start();
}

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

public ProfilePanel(Profile p) {
    mProfile = p;// w  w w  .  j a va2  s .c  om
    createUI();

    mNameTextField.setText(p.getName());
    mDescTextField.setText(p.getDescription());
    mSourceChooserPane.setPath(p.getSourceDir());
    mDestChooserPane.setPath(p.getDestDir());
    mFilePatternComboBox.setValue(p.getFilePattern());
    mDateSourceComboBox.setValue(p.getDateSource());
    mDatePatternComboBox.setValue(p.getDatePattern());
    mOperationComboBox.getSelectionModel().select(p.getCommand());
    mLinksCheckBox.setSelected(p.isFollowLinks());
    mRecursiveCheckBox.setSelected(p.isRecursive());
    mReplaceCheckBox.setSelected(p.isReplaceExisting());
    mCaseBaseComboBox.setValue(p.getCaseBase());
    mCaseExtComboBox.setValue(p.getCaseExt());

    initListeners();

    Platform.runLater(() -> {
        initValidation();
        mNameTextField.requestFocus();
    });
}