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.github.drbookings.ui.controller.MainController.java

private void updateStatusLabel() {
    Platform.runLater(() -> updateStatusLabelFX());

}

From source file:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

public void executionStarted(final long id, final String text) {
    Platform.runLater(new Runnable() {
        @Override/* w  w  w .  ja  va2s  . com*/
        public void run() {
            taskCountLock.lock();
            activeExecutionTasks.put(id, text);
            switchExecutionStateProcessIndicator();
            taskCountLock.unlock();
        }
    });
}

From source file:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

public void executionFinished(final long id, String text) {
    Platform.runLater(new Runnable() {
        @Override//ww w .  jav  a2s . c o m
        public void run() {
            taskCountLock.lock();
            activeExecutionTasks.remove(id);
            switchExecutionStateProcessIndicator();
            taskCountLock.unlock();
        }
    });
}

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

@FXML
private void importSM() {
    if (this.unrChooser.getSelectionModel().getSelectedItem() == null)
        return;//w  w w . ja va  2s .c o m

    FileChooser fileChooser = new FileChooser();
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
    fileChooser.setTitle("Open");
    File file = fileChooser.showOpenDialog(getStage());
    if (file == null)
        return;

    int xy = 18 | (20 << 8);
    try {
        xy = getXY(getMapsDir(), this.unrChooser.getSelectionModel().getSelectedItem());
    } catch (IOException e) {
        showAlert(Alert.AlertType.WARNING, "Import", null, "Couldn't read map coords, using default 18_20");
    }

    ImportExportDialog dlg = new ImportExportDialog(xy & 0xff, (xy >> 8) & 0xff);
    ButtonType response = dlg.showAndWait().orElse(null);
    if (response != ButtonType.OK)
        return;

    AffineTransform transform = AffineTransform.getRotateInstance(Math.PI * dlg.getAngle() / 180);

    ObjectMapper objectMapper = new ObjectMapper();
    try {
        L2Map map = objectMapper.readValue(file, L2Map.class);

        if (map.getStaticMeshes().isEmpty())
            return;

        longTask(progress -> {
            try (UnrealPackage up = new UnrealPackage(
                    new File(getMapsDir(), unrChooser.getSelectionModel().getSelectedItem()), false)) {
                up.addImportEntries(map.getStaticMeshes().stream().collect(
                        Collectors.toMap(Actor::getStaticMesh, a -> "Engine.StaticMesh", (o1, o2) -> o1)));

                for (int i = 0; i < map.getStaticMeshes().size(); i++) {
                    Actor actor = map.getStaticMeshes().get(i);

                    int newActorInd = StaticMeshActorUtil.addStaticMeshActor(up,
                            up.objectReferenceByName(actor.getStaticMesh(), c -> true), actor.getActorClass(),
                            true, true, oldFormat.isSelected());
                    UnrealPackage.ExportEntry newActor = (UnrealPackage.ExportEntry) up
                            .objectReference(newActorInd);

                    actor.setActorName(newActor.getObjectInnerFullName());
                    actor.setStaticMeshRef(up.objectReferenceByName(actor.getStaticMesh(), c -> true));

                    byte[] bytes = newActor.getObjectRawData();
                    Offsets offsets = StaticMeshActorUtil.getOffsets(bytes, up);

                    Point2D.Float point = new Point2D.Float(actor.getX(), actor.getY());
                    transform.transform(point, point);

                    actor.setX(dlg.getX() + point.x);
                    actor.setY(dlg.getY() + point.y);
                    actor.setZ(dlg.getZ() + actor.getZ());

                    actor.setYaw((actor.getYaw() + (int) (0xFFFF * dlg.getAngle() / 360)) & 0xFFFF);

                    StaticMeshActorUtil.setLocation(bytes, offsets, actor.getX(), actor.getY(), actor.getZ());
                    StaticMeshActorUtil.setRotation(bytes, offsets, actor.getPitch(), actor.getYaw(),
                            actor.getRoll());
                    if (actor.getScale3D() != null)
                        StaticMeshActorUtil.setDrawScale3D(bytes, offsets, actor.getScaleX(), actor.getScaleY(),
                                actor.getScaleZ());
                    if (actor.getScale() != null)
                        StaticMeshActorUtil.setDrawScale(bytes, offsets, actor.getScale());
                    if (actor.getRotationRate() != null)
                        StaticMeshActorUtil.setRotationRate(bytes, offsets, actor.getPitchRate(),
                                actor.getYawRate(), actor.getRollRate());
                    if (actor.getZoneRenderState() != null)
                        bytes = StaticMeshActorUtil.setZoneRenderState(bytes, offsets,
                                actor.getZoneRenderState());

                    newActor.setObjectRawData(bytes);

                    progress.accept((double) i / map.getStaticMeshes().size());
                }
            }

            Platform.runLater(() -> {
                String unr = unrChooser.getSelectionModel().getSelectedItem();
                Actor act = map.getStaticMeshes().get(map.getStaticMeshes().size() - 1);

                unrChooser.getSelectionModel().clearSelection();
                unrChooser.getSelectionModel().select(unr);

                table.getSelectionModel().select(act);
                table.scrollTo(act);
            });
        }, e -> onException("Import failed", e));
    } catch (IOException e) {
        onException("Import failed", e);
    }
}

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

public void updateCurrentPlayerLabel(boolean noAnimation, boolean setBlockedValueAfterAnimation) {
    Platform.runLater(() -> stage.setTitle(getWindowTitle()));
    if (board.getCurrentPlayer() != null) {
        if (!board.getCurrentPlayer().getLetter().equals(currentPlayerLabel.getText())) {
            if (noAnimation) {
                setCurrentPlayerValue();
            } else {
                guiAnimationQueue.submitWaitForUnlock(() -> {
                    guiAnimationQueue.setBlocked(true);

                    GaussianBlur blur = (GaussianBlur) currentPlayerLabel.getEffect();
                    if (blur == null) {
                        blur = new GaussianBlur(0);
                    }/*from www.j av  a2s  .  c  om*/

                    Calendar changeLabelTextDate = Calendar.getInstance();
                    changeLabelTextDate.add(Calendar.MILLISECOND, (int) (animationSpeed * 1000));
                    runLaterTimer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            Platform.runLater(() -> setCurrentPlayerValue());
                        }
                    }, changeLabelTextDate.getTime());

                    currentPlayerLabel.setEffect(blur);
                    Timeline timeline = new Timeline();
                    KeyValue keyValue1 = new KeyValue(blur.radiusProperty(), 20);
                    KeyFrame keyFrame1 = new KeyFrame(Duration.seconds(animationSpeed), keyValue1);

                    KeyValue keyValue2 = new KeyValue(blur.radiusProperty(), 0);
                    KeyFrame keyFrame2 = new KeyFrame(Duration.seconds(2 * animationSpeed), keyValue2);

                    timeline.getKeyFrames().addAll(keyFrame1, keyFrame2);

                    timeline.setOnFinished((event) -> {
                        currentPlayerLabel.setEffect(null);
                        guiAnimationQueue.setBlocked(false);
                        setBlockedForInput(setBlockedValueAfterAnimation);
                    });

                    timeline.play();
                });
                return;
            }
        }
    }

    guiAnimationQueue.setBlocked(false);
    setBlockedForInput(setBlockedValueAfterAnimation);
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
    log.info("Caching " + dir.getAbsolutePath());

    TreeItem<Path> root = new TreeItem<>(dir.toPath());
    root.setExpanded(false);/* w  ww.  j  a  va 2 s  .  c  om*/
    File[] files = dir.listFiles();
    final String I18N_CACHE_TEXT = I18N.getString("TokenTool.treeview.caching");

    final Task<Void> task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            for (File file : files) {
                if (loadOverlaysThread.isInterrupted())
                    break;

                if (file.isDirectory()) {
                    cacheOverlays(file, root, THUMB_SIZE);
                } else {
                    Path filePath = file.toPath();
                    TreeItem<Path> imageNode = new TreeItem<>(filePath,
                            ImageUtil.getOverlayThumb(new ImageView(), filePath));
                    root.getChildren().add(imageNode);
                    loadCount.getAndIncrement();
                    overlayTreeProgressBar.progressProperty().set(loadCount.doubleValue() / overlayCount);
                }
            }

            if (parent != null) {
                // When we show the overlay image, the TreeItem value is empty so we need to
                // sort those to the bottom for a cleaner look and keep sub dir's at the top.
                // If a node has no children then it's an overlay, otherwise it's a directory...
                root.getChildren().sort(new Comparator<TreeItem<Path>>() {
                    @Override
                    public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                        if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                            return 0;
                        else if (o1.getChildren().size() == 0)
                            return Integer.MAX_VALUE;
                        else if (o2.getChildren().size() == 0)
                            return Integer.MIN_VALUE;
                        else
                            return o1.getValue().compareTo(o2.getValue());
                    }
                });

                parent.getChildren().add(root);

                parent.getChildren().sort(new Comparator<TreeItem<Path>>() {
                    @Override
                    public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                        if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                            return 0;
                        else if (o1.getChildren().size() == 0)
                            return Integer.MAX_VALUE;
                        else if (o2.getChildren().size() == 0)
                            return Integer.MIN_VALUE;
                        else
                            return o1.getValue().compareTo(o2.getValue());
                    }
                });
            }

            return null;
        }
    };

    overlayTreeProgressBar.progressProperty().addListener(observable -> {
        Platform.runLater(() -> progressBarLabel
                .setText(I18N_CACHE_TEXT + Math.round(overlayCount - loadCount.doubleValue()) + "..."));
    });

    // Only add this listener to the parent task so it's only called once
    if (parent == null) {
        overlayTreeProgressBar.progressProperty().addListener(observable -> {
            Platform.runLater(() -> {
                if (overlayTreeProgressBar.getProgress() >= 1)
                    treeViewFinish();
            });
        });
    }

    executorService.execute(task);
    return root;
}

From source file:com.chart.SwingChart.java

/**
 * /*from  w ww  .ja  va 2 s .  com*/
 * @param axis Axis name to wich the new series belongs
 * @param cs Series Coinfiguration
 */
@Override
public final void addSeries(String axis, SimpleSeriesConfiguration cs) {
    for (int i = 0; i < axes.size(); i++) {
        if (axes.get(i).getName().equals(axis)) {
            String strColor;
            javafx.scene.paint.Color color;
            int indice = seriesList.size();
            if (cs.getColor() == null) {
                color = getColor(indice);
            } else {
                color = cs.getColor();
            }
            strColor = color.toString();

            XYSeriesCollection dataset = datasetList.get(i);
            Series series = new Series(cs.getName(), "color: " + strColor + ";width: "
                    + String.valueOf(cs.getLineWidth()) + ";shape: " + cs.getShapeName() + ";", i,
                    dataset.getSeriesCount());
            dataset.addSeries(series);

            XYItemRenderer renderer = plot.getRenderer(i);
            renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color));

            SeriesShape simb = new SeriesShape(cs.getShapeName(),
                    javafx.scene.paint.Color.web(strColor.replace("#", "0x")));

            if (cs.getLineWidth() > 0) {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, true);
                renderer.setSeriesStroke(dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth()));
            } else {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, false);
            }

            if (cs.getShapeName().equals("null")) {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, null);
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, false);
            } else {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT());
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, true);
                if (cs.getShapeName().contains("empty")) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            false);
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            true);
                }
            }

            if (i == 0) {
                plot.setRenderer(renderer);
            } else {
                plot.setRenderer(i, renderer);
            }

            seriesList.add(series);

            final LegendAxis le = getLegendAxis(axis);
            final Label label = new Label(cs.toString());
            Platform.runLater(() -> {
                label.setStyle("fondo: " + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize) + "px");
            });

            label.setOnMouseClicked((MouseEvent t) -> {
                if (t.getClickCount() == 2) {
                    for (int i1 = 0; i1 < seriesList.size(); i1++) {
                        if (seriesList.get(i1).getKey().toString().equals(label.getText())) {
                            editSeries(seriesList.get(i1));
                            break;
                        }
                    }
                }
            });
            label.setOnMouseExited((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: blue", "-fx-background-color: fondo"));
            });
            label.setOnMouseEntered((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: fondo", "-fx-background-color: blue"));
                for (Node le1 : legendFrame.getChildren()) {
                    if (le1 instanceof LegendAxis) {
                        le1.setStyle("-fx-background-color:" + strBackgroundColor);
                        ((LegendAxis) le1).selected = false;
                    }
                }
            });
            label.setStyle("fondo: " + strChartBackgroundColor
                    + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                    + String.valueOf(fontSize) + "px");

            le.getChildren().add(label);
            label.setGraphic(simb.getShapeGraphic());

            break;
        }
    }
}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private void handleComponentEvent(ComponentEvent e) {
    try {/*from   w ww .j  ava  2 s  .c o m*/
        Component c = this;
        if (this.getParent() != null)
            c = this.getParent();

        final int w = c.getWidth();
        final int h = c.getHeight() - 35;
        Dimension d = new Dimension(w, h);

        if (this.getParent() != null) {
            this.setPreferredSize(d);
            this.setMinimumSize(d);
            this.setMaximumSize(d);
        }

        if (webView != null && w > 1 && h > 1) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    webView.setMinSize(w, h);
                    webView.setMaxSize(w, h);
                    webView.setPrefSize(w, h);
                }
            });
        }
        revalidate();
        repaint();
    } catch (Exception ex) {
    }
}

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

private void onException(String text, Throwable ex) {
    ex.printStackTrace();//from w  w  w . jav a2  s.c  o m

    Platform.runLater(() -> {
        if (SHOW_STACKTRACE) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText(null);
            alert.setContentText(text);

            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            String exceptionText = sw.toString();

            Label label = new Label("Exception stacktrace:");

            TextArea textArea = new TextArea(exceptionText);
            textArea.setEditable(false);
            textArea.setWrapText(true);

            textArea.setMaxWidth(Double.MAX_VALUE);
            textArea.setMaxHeight(Double.MAX_VALUE);
            GridPane.setVgrow(textArea, Priority.ALWAYS);
            GridPane.setHgrow(textArea, Priority.ALWAYS);

            GridPane expContent = new GridPane();
            expContent.setMaxWidth(Double.MAX_VALUE);
            expContent.add(label, 0, 0);
            expContent.add(textArea, 0, 1);

            alert.getDialogPane().setExpandableContent(expContent);

            alert.showAndWait();
        } else {
            //noinspection ThrowableResultOfMethodCallIgnored
            Throwable t = getTop(ex);

            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle(t.getClass().getSimpleName());
            alert.setHeaderText(text);
            alert.setContentText(t.getMessage());

            alert.showAndWait();
        }
    });
}

From source file:dsfixgui.view.DSFGraphicsPane.java

private void setDOFOverrideEventHandler() {
    dofOverridePicker.setOnAction(e -> {
        if (dofOverridePicker.getItems()
                .indexOf(dofOverridePicker.getValue()) == (dofOverridePicker.getItems().size() - 1)) {
            //No DOF
            ContinueDialog cD = new ContinueDialog(300.0, 80.0, DIALOG_TITLE_NOT_RECOMMENDED,
                    DIALOG_MSG_TRY_ALTERNATE_NO_DOF, DIALOG_BUTTON_TEXTS[2], DIALOG_BUTTON_TEXTS[3]);

            if (cD.show()) {
                config.disableDOF();//from w  w w. java2s.  c  om
                dofScalingEnabled.setDisable(true);
                dofScalingDisabled.setDisable(true);
                dofAddPicker.setDisable(true);
                presentWidthField.setDisable(true);
                presentHeightField.setDisable(true);
                setWindowsPresentRes.setDisable(true);
                usePresentRes.setDisable(true);
                dontUsePresentRes.setDisable(true);
                dofScalingDisabled.setSelected(true);
                dofAddPicker.setValue(dofAddPicker.getItems().get(0));
                if (usePresentRes.isSelected()) {
                    presentRes[0] = presentWidthField.getText();
                    presentRes[1] = presentHeightField.getText();
                }
                presentWidthField.setText("0");
                presentHeightField.setText("0");
                recheckTextInput(presentWidthField);
                recheckTextInput(presentHeightField);
                recheckTextInput(renderWidthField);
                recheckTextInput(renderHeightField);
            } else {

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException ex) {

                        }
                        for (int i = 0; i < DOF_OVERRIDE_OPTIONS.length; i++) {
                            if (config.getDOFOverride() == DOF_OVERRIDE_OPTIONS[i]) {
                                dofOverridePicker.setValue(DOFOVERRIDERESOLUTIONS[i]);
                            }
                        }
                    }
                });
            }
        } else {
            config.disableDOF = false;
            dofScalingEnabled.setDisable(false);
            dofScalingDisabled.setDisable(false);
            dofAddPicker.setDisable(false);
            if (usePresentRes.isDisabled()) {
                if (usePresentRes.isSelected()) {
                    presentWidthField.setDisable(false);
                    presentHeightField.setDisable(false);
                    setWindowsPresentRes.setDisable(false);
                    presentWidthField.setText("");
                    presentWidthField.appendText(presentRes[0] + "");
                    presentHeightField.setText("");
                    presentHeightField.appendText(presentRes[1] + "");
                }
                usePresentRes.setDisable(false);
                dontUsePresentRes.setDisable(false);
                recheckTextInput(presentWidthField);
                recheckTextInput(presentHeightField);
                recheckTextInput(renderWidthField);
                recheckTextInput(renderHeightField);
            }
            config.setDOFOverride(
                    DOF_OVERRIDE_OPTIONS[dofOverridePicker.getItems().indexOf(dofOverridePicker.getValue())]);
        }
    });
}