List of usage examples for javafx.application Platform runLater
public static void runLater(Runnable runnable)
From source file:MediaControl.java
protected void updateValues() { if (playTime != null && timeSlider != null && volumeSlider != null) { Platform.runLater(new Runnable() { public void run() { Duration currentTime = mp.getCurrentTime(); playTime.setText(formatTime(currentTime, duration)); timeSlider.setDisable(duration.isUnknown()); if (!timeSlider.isDisabled() && duration.greaterThan(Duration.ZERO) && !timeSlider.isValueChanging()) { timeSlider.setValue(currentTime.divide(duration).toMillis() * 100.0); }/*from w w w . j ava 2 s. co m*/ if (!volumeSlider.isValueChanging()) { volumeSlider.setValue((int) Math.round(mp.getVolume() * 100)); } } }); } }
From source file:com.neuronrobotics.bowlerstudio.MainController.java
/** * Initializes the controller class.//www. j av a 2s . c om * * @param url * @param rb */ @Override public void initialize(URL url, ResourceBundle rb) { ScriptingEngine.setLoginManager(new IGitHubLoginManager() { @Override public String[] prompt(String username) { if (!loginWindowOpen && controller != null) controller.reset(); loginWindowOpen = true; System.err.println("Calling login from BowlerStudio"); // new RuntimeException().printStackTrace(); FXMLLoader fxmlLoader = BowlerStudioResourceFactory.getGithubLogin(); Parent root = fxmlLoader.getRoot(); if (controller == null) { controller = fxmlLoader.getController(); Platform.runLater(() -> { controller.reset(); controller.getUsername().setText(username); Stage stage = new Stage(); stage.setTitle("GitHub Login"); stage.initModality(Modality.APPLICATION_MODAL); controller.setStage(stage, root); stage.centerOnScreen(); stage.show(); }); } // setContent(root); while (!controller.isDone()) { ThreadUtil.wait(100); } String[] creds = controller.getCreds(); loginWindowOpen = false; return creds; } }); jfx3dmanager = new BowlerStudio3dEngine(); setApplication(new BowlerStudioController(jfx3dmanager, this)); Platform.runLater(() -> { editorContainer.getChildren().add(getApplication()); AnchorPane.setTopAnchor(getApplication(), 0.0); AnchorPane.setRightAnchor(getApplication(), 0.0); AnchorPane.setLeftAnchor(getApplication(), 0.0); AnchorPane.setBottomAnchor(getApplication(), 0.0); subScene = jfx3dmanager.getSubScene(); subScene.setFocusTraversable(false); subScene.setOnMouseEntered(mouseEvent -> { // System.err.println("3d window requesting focus"); Scene topScene = BowlerStudio.getScene(); normalKeyPessHandle = topScene.getOnKeyPressed(); jfx3dmanager.handleKeyboard(topScene); }); subScene.setOnMouseExited(mouseEvent -> { // System.err.println("3d window dropping focus"); Scene topScene = BowlerStudio.getScene(); topScene.setOnKeyPressed(normalKeyPessHandle); }); subScene.widthProperty().bind(viewContainer.widthProperty()); subScene.heightProperty().bind(viewContainer.heightProperty()); }); Platform.runLater(() -> { jfx3dControls.getChildren().add(jfx3dmanager.getControlsBox()); viewContainer.getChildren().add(subScene); }); System.out.println("Welcome to BowlerStudio!"); new Thread() { public void run() { setName("Load Haar Thread"); try { HaarFactory.getStream(null); } catch (Exception ex) { } } }.start(); // getAddDefaultRightArm().setOnAction(event -> { // // application.onAddDefaultRightArm(event); // }); // getAddVRCamera().setOnAction(event -> { // if(AddVRCamera.isSelected()) // application.onAddVRCamera(event); // }); FxTimer.runLater(Duration.ofMillis(100), () -> { if (ScriptingEngine.getLoginID() != null) { setToLoggedIn(ScriptingEngine.getLoginID()); } else { setToLoggedOut(); } }); ScriptingEngine.addIGithubLoginListener(new IGithubLoginListener() { @Override public void onLogout(String oldUsername) { setToLoggedOut(); } @Override public void onLogin(String newUsername) { setToLoggedIn(newUsername); } }); cmdLine = new CommandLineWidget(); Platform.runLater(() -> { // logView.resize(250, 300); // after connection manager set up, add scripting widget logViewRef = new TextArea(); logViewRef.prefWidthProperty().bind(logView.widthProperty().divide(2)); logViewRef.prefHeightProperty().bind(logView.heightProperty().subtract(40)); VBox box = new VBox(); box.getChildren().add(logViewRef); box.getChildren().add(cmdLine); VBox.setVgrow(logViewRef, Priority.ALWAYS); box.prefWidthProperty().bind(logView.widthProperty().subtract(10)); logView.getChildren().addAll(box); }); }
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
public OverlayPanel() throws IOException { super();//w w w. j a v a2 s.com FXUtilities.injectFXML(this); keyColumn.setCellValueFactory(new PropertyValueFactory("name")); valueColumn.setCellValueFactory(new PropertyValueFactory("value")); tableView.setItems(entries); entries.add(new MyEntry("nothing", 0d)); overlayNameField.setPromptText(EMPTY_FIELD); overlayNameField.textProperty().addListener(this::onOverlayNameChanged); overlayProperty.addListener(this::onOverlaySelectionChanged); chartVBox.getChildren().removeAll(areaChart, lineChart); overlayOptions = new OverlayOptions(); optionsPane = new PopOver(overlayOptions); optionsPane.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP); optionsPane.setDetachable(true); optionsPane.setAutoHide(false); optionsPane.titleProperty().setValue("Overlay settings"); optionsPane.setConsumeAutoHidingEvents(false); gearIcon = GlyphsDude.createIcon(FontAwesomeIcon.GEAR, "15"); gearIcon.setOpacity(BASAL_OPACITY); gearIcon.setOnMouseEntered(e -> gearIcon.setOpacity(1.0)); gearIcon.setOnMouseExited(e -> gearIcon.setOpacity(BASAL_OPACITY)); gearIcon.addEventHandler(MouseEvent.MOUSE_CLICKED, this::onGearClicked); gearIcon.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> { e.consume(); }); gearIcon.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> { e.consume(); }); chartTitledPane.setGraphic(gearIcon); chartTitledPane.setContentDisplay(ContentDisplay.RIGHT); chartTitledPane.graphicTextGapProperty().setValue(TEXT_GAP); // channeling all the DataViewUpdatedEvent so it updates the // current selected overlay eventBus.getStream(OverlayUpdatedEvent.class) .filter(event -> event.getObject().equals(overlayProperty.getValue())) .subscribe(event -> Platform.runLater(this::updateStats)); eventBus.getStream(DataViewUpdatedEvent.class).map(event -> event.getView()) .filter(view -> view instanceof OverlayView).cast(OverlayView.class) .filter(view -> view.isSelected()).throttleWithTimeout(1000, TimeUnit.MILLISECONDS) .subscribe(overlay -> { overlayProperty.setValue(overlay.getData()); }); eventBus.getStream(DataViewUpdatedEvent.class).filter(event -> event.getView() instanceof DatasetView) .map(event -> event.getView()).cast(DatasetView.class).map(view -> { return view; }).filter(view -> currentDisplay().contains(view)).throttleWithTimeout(100, TimeUnit.MILLISECONDS) .subscribe(event -> Platform.runLater(this::updateStats)); eventBus.getStream(DisplayUpdatedEvent.class).filter(event -> event.getDisplay() instanceof ImageDisplay) .subscribe(this::checkCurrentOverlay); }
From source file:photobooth.views.ExplorerPane.java
private BorderPane createImageView(final File imageFile) { // DEFAULT_THUMBNAIL_WIDTH is a constant you need to define // The last two arguments are: preserveRatio, and use smooth (slower) // resizing/* ww w . j a va 2 s. c o m*/ ExplorerPane explorerPane = this; ImageView imageView = null; BorderPane borderPane = new BorderPane(); try { borderPane.setMaxSize(100, 100); borderPane.setMinSize(100, 100); FileInputStream fileInputStream = new FileInputStream(imageFile); final Image image = new Image(fileInputStream, 100, 100, true, true); imageView = new ImageView(image); fileInputStream.close(); imageView.getStyleClass().add("image-view"); borderPane.setCenter(imageView); //imageView.setFitWidth(80); imageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 1) { Global.getInstance().setSceneRoot(LoadingPane.getInstance()); Platform.runLater(() -> { new Thread(new Runnable() { @Override public void run() { ImagePane.getInstance().init(explorerPane, imageFile); Global.getInstance().setSceneRoot(ImagePane.getInstance()); } }).start(); }); } } } }); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex); } return borderPane; }
From source file:com.bekwam.resignator.JarsignerConfigController.java
private void loadAliases() { if (StringUtils.isNotEmpty(tfKeystore.getText()) && StringUtils.isNotEmpty(pfStorepass.getText())) { if (logger.isDebugEnabled()) { logger.debug("[LOAD ALIASES] there are values for the keytool command"); }/*from www. j a v a2s .co m*/ hboxAliasProgress.setVisible(true); cbAlias.valueProperty().unbindBidirectional(activeProfile.jarsignerConfigAliasProperty()); cbAlias.getItems().clear(); final String ks = tfKeystore.getText(); final String sp = pfStorepass.getText(); Task<Void> t = new Task<Void>() { public Void call() { try { updateMessage("Loading..."); updateProgress(0.1d, 1.0d); final List<String> aliases = keytoolCommand .findAliases(activeConfiguration.getKeytoolCommand().toString(), ks, sp); updateMessage("Updating..."); updateProgress(0.8d, 1.0d); Platform.runLater(() -> { if (CollectionUtils.isNotEmpty(aliases)) { cbAlias.getItems().addAll(aliases); cbAlias.valueProperty() .bindBidirectional(activeProfile.jarsignerConfigAliasProperty()); } cbAlias.setDisable(false); // might be an empty list for empty keystore cbAlias.requestFocus(); // leave the PasswordField hboxAliasProgress.setVisible(false); }); } catch (CommandExecutionException exc) { if (logger.isWarnEnabled()) { logger.warn("error getting aliases", exc); } Platform.runLater(() -> { cbAlias.setDisable(true); hboxAliasProgress.setVisible(false); }); } finally { updateMessage(""); updateProgress(0.0d, 1.0d); } return null; } }; lblAliasProgress.textProperty().bind(t.messageProperty()); pbAlias.progressProperty().bind(t.progressProperty()); new Thread(t).start(); } else { cbAlias.getItems().clear(); cbAlias.setDisable(true); } }
From source file:gov.va.isaac.sync.view.SyncView.java
private void addLine(String line) { Runnable work = new Runnable() { @Override/* www .j av a 2s . c o m*/ public void run() { summary_.setText(summary_.getText() + line + "\n"); } }; if (Platform.isFxApplicationThread()) { work.run(); } else { Platform.runLater(work); } }
From source file:dpfmanager.shell.modules.messages.MessagesModule.java
private void tractExceptionMessage(ExceptionMessage em) { // Show in console service.exceptionMessage(em);/*from w ww .j av a 2 s .c om*/ // Show alert Platform.runLater(new Runnable() { @Override public void run() { Alert alert = AlertsManager.createExceptionAlert(em); alert.show(); } }); }
From source file:tachyon.view.ProjectProperties.java
public ProjectProperties(JavaProject project, Window w) { this.project = project; stage = new Stage(); stage.initOwner(w);//from w w w . ja v a2 s . co m stage.initModality(Modality.APPLICATION_MODAL); stage.setWidth(600); stage.setTitle("Project Properties - " + project.getProjectName()); stage.getIcons().add(tachyon.Tachyon.icon); stage.setResizable(false); HBox mai, libs, one, two, thr, fou; ListView<String> compileList, runtimeList; Button compileAdd, compileRemove, preview, selectIm, runtimeAdd, runtimeRemove; TextField iconField; stage.setScene(new Scene(new VBox(5, pane = new TabPane( new Tab("Library Settings", box1 = new VBox(15, libs = new HBox(10, new Label("External Libraries"), libsView = new ListView<>(), new VBox(5, addJar = new Button("Add Jar"), removeJar = new Button("Remove Jar"))))), new Tab("Program Settings", new ScrollPane(box2 = new VBox(15, one = new HBox(10, new Label("Main-Class"), mainClass = new TextField(project.getMainClassName()), select = new Button("Select")), two = new HBox(10, new Label("Compile-Time Arguments"), compileList = new ListView<>(), new VBox(5, compileAdd = new Button("Add Argument"), compileRemove = new Button("Remove Argument")))))), new Tab("Deployment Settings", box3 = new VBox(15, thr = new HBox(10, new Label("Icon File"), iconField = new TextField(project.getFileIconPath()), preview = new Button("Preview Image"), selectIm = new Button("Select Icon")), fou = new HBox(10, new Label("Runtime Arguments"), runtimeList = new ListView<>(), new VBox(5, runtimeAdd = new Button("Add Argument"), runtimeRemove = new Button("Remove Argument")))))), new VBox(15, mai = new HBox(10, cancel = new Button("Cancel"), confirm = new Button("Confirm")))))); if (applyCss.get()) { stage.getScene().getStylesheets().add(css); } for (Tab b : pane.getTabs()) { b.setClosable(false); } mainClass.setPromptText("Main-Class"); box1.setPadding(new Insets(5, 10, 5, 10)); mai.setAlignment(Pos.CENTER_RIGHT); mai.setPadding(box1.getPadding()); libs.setAlignment(Pos.CENTER); one.setAlignment(Pos.CENTER); two.setAlignment(Pos.CENTER); thr.setAlignment(Pos.CENTER); fou.setAlignment(Pos.CENTER); box1.setAlignment(Pos.CENTER); box2.setPadding(box1.getPadding()); box2.setAlignment(Pos.CENTER); box3.setPadding(box1.getPadding()); box3.setAlignment(Pos.CENTER); mainClass.setEditable(false); mainClass.setPrefWidth(200); for (JavaLibrary lib : project.getAllLibs()) { libsView.getItems().add(lib.getBinaryAbsolutePath()); } for (String sa : project.getCompileTimeArguments().keySet()) { compileList.getItems().add(sa + ":" + project.getCompileTimeArguments().get(sa)); } for (String sa : project.getRuntimeArguments()) { runtimeList.getItems().add(sa); } compileAdd.setOnAction((e) -> { Dialog<Pair<String, String>> dialog = new Dialog<>(); dialog.setTitle("Compiler Argument"); dialog.initOwner(stage); dialog.setHeaderText("Entry the argument"); ButtonType loginButtonType = new ButtonType("Done", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); TextField username = new TextField(); username.setPromptText("Key"); TextField password = new TextField(); password.setPromptText("Value"); grid.add(new Label("Key:"), 0, 0); grid.add(username, 1, 0); grid.add(new Label("Value:"), 0, 1); grid.add(password, 1, 1); Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); loginButton.setDisable(true); username.textProperty().addListener((observable, oldValue, newValue) -> { loginButton.setDisable(newValue.trim().isEmpty()); }); dialog.getDialogPane().setContent(grid); Platform.runLater(() -> username.requestFocus()); dialog.setResultConverter(dialogButton -> { if (dialogButton == loginButtonType) { return new Pair<>(username.getText(), password.getText()); } return null; }); Optional<Pair<String, String>> result = dialog.showAndWait(); if (result.isPresent()) { compileList.getItems().add(result.get().getKey() + ":" + result.get().getValue()); } }); compileRemove.setOnAction((e) -> { if (compileList.getSelectionModel().getSelectedItem() != null) { compileList.getItems().remove(compileList.getSelectionModel().getSelectedItem()); } }); runtimeAdd.setOnAction((e) -> { TextInputDialog dia = new TextInputDialog(); dia.setTitle("Add Runtime Argument"); dia.setHeaderText("Enter an argument"); dia.initOwner(stage); Optional<String> res = dia.showAndWait(); if (res.isPresent()) { runtimeList.getItems().add(res.get()); } }); runtimeRemove.setOnAction((e) -> { if (runtimeList.getSelectionModel().getSelectedItem() != null) { runtimeList.getItems().remove(runtimeList.getSelectionModel().getSelectedItem()); } }); preview.setOnAction((e) -> { if (!iconField.getText().isEmpty()) { if (iconField.getText().endsWith(".ico")) { List<BufferedImage> read = new ArrayList<>(); try { read.addAll(ICODecoder.read(new File(iconField.getText()))); } catch (IOException ex) { } if (read.size() >= 1) { Image im = SwingFXUtils.toFXImage(read.get(0), null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } else if (iconField.getText().endsWith(".icns")) { try { BufferedImage ima = Imaging.getBufferedImage(new File(iconField.getText())); if (ima != null) { Image im = SwingFXUtils.toFXImage(ima, null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } catch (ImageReadException | IOException ex) { } } else { Image im = new Image(new File(iconField.getText()).toURI().toString()); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } }); selectIm.setOnAction((e) -> { FileChooser fc = new FileChooser(); fc.setTitle("Icon File"); String OS = System.getProperty("os.name").toLowerCase(); fc.getExtensionFilters().add(new ExtensionFilter("Icon File", OS.contains("win") ? getWindowsImageExtensions() : getMacImageExtensions())); fc.setSelectedExtensionFilter(fc.getExtensionFilters().get(0)); File lf = fc.showOpenDialog(stage); if (lf != null) { iconField.setText(lf.getAbsolutePath()); } }); addJar.setOnAction((e) -> { FileChooser f = new FileChooser(); f.setTitle("External Libraries"); f.setSelectedExtensionFilter(new ExtensionFilter("Jar Files", "*.jar")); List<File> showOpenMultipleDialog = f.showOpenMultipleDialog(stage); if (showOpenMultipleDialog != null) { for (File fi : showOpenMultipleDialog) { if (!libsView.getItems().contains(fi.getAbsolutePath())) { libsView.getItems().add(fi.getAbsolutePath()); } } } }); removeJar.setOnAction((e) -> { String selected = libsView.getSelectionModel().getSelectedItem(); if (selected != null) { libsView.getItems().remove(selected); } }); select.setOnAction((e) -> { List<String> all = getAll(); ChoiceDialog<String> di = new ChoiceDialog<>(project.getMainClassName(), all); di.setTitle("Select Main Class"); di.initOwner(stage); di.setHeaderText("Select A Main Class"); Optional<String> show = di.showAndWait(); if (show.isPresent()) { mainClass.setText(show.get()); } }); cancel.setOnAction((e) -> { stage.close(); }); confirm.setOnAction((e) -> { project.setMainClassName(mainClass.getText()); project.setFileIconPath(iconField.getText()); project.setRuntimeArguments(runtimeList.getItems()); HashMap<String, String> al = new HashMap<>(); for (String s : compileList.getItems()) { String[] spl = s.split(":"); al.put(spl[0], spl[1]); } project.setCompileTimeArguments(al); project.setAllLibs(libsView.getItems()); stage.close(); }); }
From source file:com.omicronware.streamlet.Main.java
public void openDatabase() { //connect to mysql db if (DATABASE == null || (DATABASE != null && !DATABASE.isOpen())) { DATABASE = new MysqlDatabase("192.168.1.2", "makis", "j-sql", "streamlet", 3306); DATABASE.openAsync(new ConnectionListener() { @Override//from www . java 2s . c o m public void databaseConnected() { loadFactories(); DownloadManager.prepareStatements(DATABASE); try { SETTINGS = StoreObjectManager.getInstance().getStoredObject(SettingsModel.class); } catch (IOException | ClassNotFoundException ex) { SETTINGS = null; } if (SETTINGS != null) { //file exists or just downloadFolder or/and username&pass AccountManager.getInstance().setMe(SETTINGS); } else { //we initiliaze it because can be null from SETTINGS = StoreObect...getStoredObject(); SETTINGS = new SettingsModel(defaultDlFolder, null, null); } Platform.runLater(() -> { NAVIGATION.setPrimaryStage(stage); NAVIGATION.show(); }); } @Override public void databaseError(String error) { Platform.runLater(() -> { System.out.println(error); }); } }); } }
From source file:ijfx.ui.filter.DefaultNumberFilter.java
public void updateChart() { final double min; // minimum value final double max; // maximum value double range; // max - min final double binSize; int maximumBinNumber = 30; int finalBinNumber; int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue())) .collect(Collectors.toSet()).size(); if (differentValuesCount < maximumBinNumber) { finalBinNumber = differentValuesCount; } else {// www. ja v a 2 s .c o m finalBinNumber = maximumBinNumber; } EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber); double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue())) .mapToDouble(v -> v.doubleValue()).sorted().toArray(); distribution.load(values); min = values[0]; max = values[values.length - 1]; range = max - min; binSize = range / (finalBinNumber - 1); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<>(k, new Double(st.getN()))); k += binSize; } Platform.runLater(() -> { serie.getData().addAll(data); areaChart.getData().clear(); areaChart.getData().add(serie); updateSlider(min, max, finalBinNumber); }); }