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.panemu.tiwulfx.control.LookupFieldController.java

private void close() {
    Platform.runLater(new Runnable() {
        @Override/*from w w  w.j  a  v  a2s  .c om*/
        public void run() {
            dialogStage.hide();
        }
    });
}

From source file:deincraftlauncher.start.StartMinecraft.java

private static String getJavaCommand() {

    String path = System.getProperty("java.home") + File.separator + "bin" + File.separator
            + (OS.getCURRENT() == OS.WINDOWS ? "java.exe" : "java");

    String minecraftRuntime = "C:\\Program Files (x86)\\Minecraft\\runtime\\jre-x64\\1.8.0_25\\bin\\java.exe";
    if (new File(minecraftRuntime).exists()) {
        System.out.println("using minecraft runtime!");
        return minecraftRuntime;
    }/*  w  w  w.ja  v a2  s .  co  m*/

    File x64Test = new File("C:\\Program Files\\Java");

    if (path.contains(" (x86)")) {
        if (x64Test.exists()) {
            return path.replace(" (x86)", "");
        }

        Platform.runLater(() -> {
            DesignHelpers.popupMessage(
                    "Du verwendest eine 32-Bit Java version. Dies kann evtl zu problemen fhren. Bitte lade dir die aktuelle 64-bit version herunter",
                    "http://www.chip.de/downloads/Java-Runtime-Environment-64-Bit_42224883.html");
        });
    }

    return path;
}

From source file:org.copperengine.monitoring.client.context.ApplicationContext.java

protected void connect(final String serverAddressParam, final String user, final String password) {
    boolean secureConnect = StringUtils.hasText(user) && StringUtils.hasText(password);
    String serverAddress = serverAddressParam;
    if (!serverAddress.endsWith("/")) {
        serverAddress = serverAddress + "/";
    }//from  ww w  . j a v a 2s .c o m

    final LoginService loginService;
    final CommonsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new CommonsHttpInvokerRequestExecutor();
    DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(10, false);
    httpInvokerRequestExecutor.getHttpClient().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            retryHandler);
    httpInvokerRequestExecutor.getHttpClient().getParams().setSoTimeout(1000 * 60 * 5);
    {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(LoginService.class);
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "loginService");
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        loginService = (LoginService) httpInvokerProxyFactoryBean.getObject();
    }

    final String sessionId;
    if (secureConnect) {
        try {
            sessionId = loginService.doLogin(user, password);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
    } else {
        sessionId = "";
    }

    if (sessionId == null) {
        getIssueReporterSingleton().reportWarning("Invalid user/password", null, new Runnable() {
            @Override
            public void run() {
                createLoginForm().show();
            }
        });
    } else {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(CopperMonitoringService.class);
        RemoteInvocationFactory remoteInvocationFactory = secureConnect
                ? new SecureRemoteInvocationFactory(sessionId)
                : new DefaultRemoteInvocationFactory();
        httpInvokerProxyFactoryBean.setRemoteInvocationFactory(remoteInvocationFactory);
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        final CopperMonitoringService copperMonitoringService = (CopperMonitoringService) httpInvokerProxyFactoryBean
                .getObject();

        final String serverAddressFinal = serverAddress;
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                setGuiCopperDataProvider(copperMonitoringService, serverAddressFinal, sessionId);
            }
        });
    }
}

From source file:server.PokemonRequisition.java

/**
 * Usurio tenta realizar logout//from w  w  w  .j a v a 2  s.c o m
 * 
 * @param id
 * @param verificationCode
 * @return 
 */
public String logout(long id, String verificationCode) {
    PlayerServer player = searchPlayer(id);

    if (player != null) {
        System.out.println(player.getVerificationCode());
        System.out.println(verificationCode);

        if (player.getVerificationCode().equals(verificationCode)) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    String name = player.getUsername();

                    obsPlayerOnline.remove(player);
                    //                        System.out.println(name + " removed!");
                }
            });

            return Reply.OK.toString();
        }
    }

    return Reply.FAIL.toString();
}

From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java

public void onNameDeclarationSelected(NameDeclaration declaration) {
    sourceEditorController.clearNameOccurences();

    List<NameOccurrence> occurrences = declaration.getNode().getScope().getDeclarations().get(declaration);

    if (occurrences != null) {
        sourceEditorController.highlightNameOccurrences(occurrences);
    }/*from  w w w  .j  a v a2 s  .c o m*/

    Platform.runLater(() -> onNodeItemSelected(declaration.getNode()));
}

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

@Override
protected void initializeState() {
    final Vehicle v = vtVehicle.getVehicle();
    getAppropriateImages(v);// w  w  w .ja v  a2  s . co m
    toggleChoice = this.storedToggleChoice();
    prefs.overrides.color.addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String t1) {
            getAppropriateImages(v);
        }
    });
    prefs.overrides.doColor.addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            getAppropriateImages(v);
        }
    });

    vtVehicle.vehicleState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateVehicleState();
                }
            });
        }
    });
    vtVehicle.chargeState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateChargePort();
                    updateRange();
                }
            });
        }
    });
    vtVehicle.streamState.addTracker(new Runnable() {
        @Override
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    updateOdometer();
                    updateShiftState();
                }
            });
        }
    });

    updateOdometer(); // Show at least an old reading to start
    vtData.produceStream(false); // Update it at some point

    updateWheelView(); // Make sure we display the right wheels from the get-go
    updateRoofView(); // Make sure we display the right roof from the get-go
    reflectVINOrFirmware();
    vinButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            cycleToggleChoice();
            reflectVINOrFirmware();
        }
    });
}

From source file:de.micromata.mgc.javafx.logging.LoggingController.java

public void refreshLogConfiguration() {
    loggingAdapter.refreshLogConfiguration();
    Platform.runLater(() -> {
        WebEngine engine = htmlView.getEngine();
        engine.executeScript("logViewer.refreshForm();");
    });//w ww. ja  v  a 2 s . c  o m

}

From source file:de.thomasbolz.renamer.RenamerGUI.java

/**
 * Action handler for the rename button// ww w .ja v a2s. com
 *
 * @param event
 */
@FXML
void rename(ActionEvent event) {
    if (!checkDirectories(getSrcDirectory(), getTargetDirectory())) {
        return;
    }
    if (isSimulationMode()) {
        txtOut.clear();
        btnRename.setDisable(true);
        renamer = new Renamer(getSrcDirectory().toPath(), getTargetDirectory().toPath());
        FileTreeAnalysisTask task = new FileTreeAnalysisTask(renamer);
        task.messageProperty()
                .addListener((observableValue, s, s2) -> txtOut.appendText(task.getMessage() + "\n"));
        EventHandler<WorkerStateEvent> enableButtonRename = (workerStateEvent) -> btnRename.setDisable(false);
        task.setOnSucceeded(enableButtonRename);
        task.setOnFailed(enableButtonRename);
        //            progressDirs.progressProperty().bind(task.progressProperty());
        new Thread(task).start();
        //            Runnable myTask = new Runnable() {
        //                @Override
        //                public void run() {
        //                    renamer = new Renamer(getSrcDirectory().toPath(), getTargetDirectory().toPath());
        ////                    renamer.addProgressListener(RenamerGUI.this);
        //                    renamer.prepareCopyTasks();
        //                    final SortedMap<Path, List<CopyTask>> copyTasks = renamer.getCopyTasks();
        //                    StringBuilder sb = new StringBuilder();
        //                    copyTasks.forEach((path, tasks) -> {
        //                        sb.append(path);
        //                        sb.append("\n");
        //                        tasks.forEach(task -> {
        //                            sb.append(task.toFormattedString());
        //                            sb.append("\n");
        //                        });
        //                    });
        //                    Platform.runLater(new Runnable() {
        //                        @Override
        //                        public void run() {
        //                            txtOut.setText(sb.toString());
        //                        }
        //                    });
        //                }
        //            };
        //            final Thread taskRunner = new Thread(myTask);
        //        taskRunner.setName("TaskRunner");
        //        taskRunner.setDaemon(true);
        //            taskRunner.start();

        setSimulationMode(false);
    } else {
        //            Action confirm = Dialogs.create()
        //                    .title("Confirm renaming")
        //                    .masthead("Do you want to execute the renaming?")
        //                    .message("The author of this software is not liable for any damage that might occur to your files.")
        //                    .showConfirm();
        //
        //            if (confirm == Dialog.Actions.YES) {
        txtOut.clear();
        btnRename.setDisable(true);
        ExecuteCopyTask task = new ExecuteCopyTask(renamer);
        EventHandler<WorkerStateEvent> enableButtonRename = (workerStateEvent) -> btnRename.setDisable(false);
        task.setOnSucceeded(enableButtonRename);
        task.setOnFailed(enableButtonRename);
        progressDirs.progressProperty().bind(task.dirProgressProperty());
        progressFiles.progressProperty().bind(task.fileProgressProperty());
        task.progressMessageProperty()
                .addListener((observableValue, s, s2) -> Platform.runLater(() -> txtOut.appendText(s2)));

        Thread th = new Thread(task);
        th.setDaemon(true);
        th.start();
        setSimulationMode(true);
    }

}

From source file:photobooth.views.ExplorerPane.java

private void addUpButton() throws IOException {
    Button button = new Button();
    button.setGraphic(/*from w ww. ja  v a 2  s  .com*/
            new ImageView(new Image(getClass().getResource("/photobooth/images/up.png").openStream())));
    button.setStyle("-fx-background-color: transparent;");
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    button.setLayoutX(120);
    button.setLayoutY(10);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());

            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(new File(dir).getParentFile().getAbsolutePath(), 0,
                                limit, directoryLevel - 1);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });

        }
    });

}

From source file:qupath.lib.gui.panels.survival.KaplanMeierDisplay.java

@Override
public void hierarchyChanged(PathObjectHierarchyEvent event) {
    if (!Platform.isFxApplicationThread())
        Platform.runLater(() -> hierarchyChanged(event));
    else//from  ww w  . j a  v a2 s . co  m
        generatePlot();
}