List of usage examples for javafx.application Platform runLater
public static void runLater(Runnable runnable)
From source file:de.perdoctus.ebikeconnect.gui.MainWindowController.java
public void initialize() throws Exception { initUserTab(); initActivitiesTab(); Platform.runLater(this::requestLogin); }
From source file:Main.java
@Override public void start(Stage primaryStage) { final Label markerText = new Label(); StackPane.setAlignment(markerText, Pos.TOP_CENTER); String workingDir = System.getProperty("user.dir"); final File f = new File(workingDir, "../media/omgrobots.flv"); final Media m = new Media(f.toURI().toString()); final ObservableMap<String, Duration> markers = m.getMarkers(); markers.put("Robot Finds Wall", Duration.millis(3100)); markers.put("Then Finds the Green Line", Duration.millis(5600)); markers.put("Robot Grabs Sled", Duration.millis(8000)); markers.put("And Heads for Home", Duration.millis(11500)); final MediaPlayer mp = new MediaPlayer(m); mp.setOnMarker(new EventHandler<MediaMarkerEvent>() { @Override/*w w w. j a va 2 s . co m*/ public void handle(final MediaMarkerEvent event) { Platform.runLater(new Runnable() { @Override public void run() { markerText.setText(event.getMarker().getKey()); } }); } }); final MediaView mv = new MediaView(mp); final StackPane root = new StackPane(); root.getChildren().addAll(mv, markerText); root.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { mp.seek(Duration.ZERO); markerText.setText(""); } }); final Scene scene = new Scene(root, 960, 540); final URL stylesheet = getClass().getResource("media.css"); scene.getStylesheets().add(stylesheet.toString()); primaryStage.setScene(scene); primaryStage.setTitle("Video Player 2"); primaryStage.show(); mp.play(); }
From source file:ijfx.ui.utils.ChartUpdater.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 {/*from ww w . j a v a2s . c o m*/ finalBinNumber = maximumBinNumber; } EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber); Double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue())) .map(v -> v.doubleValue()).sorted() //.toArray(); .toArray(size -> new Double[size]); distribution.load(ArrayUtils.toPrimitive(values)); min = values[0]; max = values[values.length - 1]; range = max - min; binSize = range / (finalBinNumber - 1); //System.out.println(String.format("min = %.0f, max = %.0f, range = %.0f, bin size = %.0f, bin number = %d", min, max, range, binSize, finalBinNumber)); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<XYChart.Data<Double, Double>> data = new ArrayList<>(); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new XYChart.Data<>(k, new Double(st.getN()))); k += binSize; } Platform.runLater(() -> { serie.getData().addAll(data); areaChart.getData().clear(); areaChart.getData().add(serie); }); }
From source file:com.fishbeans.stream.StreamReceiver.java
public final void addOutput(byte[] data, int offset, int length) { String rawData = new String(data, offset, length); if (rawData.contains(ADB_ERRORS.FAIL_ERROR.getErrorKey())) { if (rawData.contains(ADB_ERRORS.OFFLINE_ERROR.getErrorKey())) { DeviceOffLineAlert alert = new DeviceOffLineAlert(); Optional<Boolean> result = alert.showAndWait(); if ((result.isPresent()) && result.get()) { Platform.runLater(() -> Platform.exit()); }//from w w w.j a v a 2 s .co m } } // ok we've got a string // if we had an unfinished line we add it. if (mUnfinishedLine != null) { rawData = mUnfinishedLine + rawData; mUnfinishedLine = null; } // now we split the lines internalStringDataBuffer.clear(); int start = 0; do { int index = rawData.indexOf('\n', start); // if \n was not found, this is an unfinished line // and we store it to be processed for the next packet if (index == -1) { mUnfinishedLine = rawData.substring(start); break; } // we found a \n, in older devices, this is preceded by a \r int newlineLength = 1; if (index > 0 && rawData.charAt(index - 1) == '\r') { index--; newlineLength = 2; } // extract the line String line = rawData.substring(start, index); if (mTrimLines) { line = line.trim(); } internalStringDataBuffer.add(line); // move start to after the \r\n we found start = index + newlineLength; } while (true); if (!internalStringDataBuffer.isEmpty()) { // at this point we've split all the lines. // make the array String[] lines = internalStringDataBuffer.toArray(new String[internalStringDataBuffer.size()]); // send for final processing for (String line : lines) { processNewLine(line); } } }
From source file:org.pdfsam.ui.module.BaseTaskExecutionModule.java
@EventListener public final void restoreState(LoadWorkspaceEvent event) { Platform.runLater(() -> onLoadWorkspace(event.getData(id()))); }
From source file:com.playonlinux.javafx.mainwindow.console.ConsoleTab.java
public ConsoleTab(CommandLineInterpreterFactory commandLineInterpreterFactory) { final VBox content = new VBox(); commandInterpreter = commandLineInterpreterFactory.createInstance(); this.setText(translate("Console")); this.setContent(content); final TextField command = new TextField(); command.getStyleClass().add("consoleCommandType"); final TextFlow console = new TextFlow(); final ScrollPane consolePane = new ScrollPane(console); content.getStyleClass().add("rightPane"); consolePane.getStyleClass().add("console"); consolePane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); content.getChildren().addAll(consolePane, command); command.requestFocus();//from w w w . j a v a 2 s . c o m command.setOnKeyPressed(event -> { if (event.getCode() == KeyCode.ENTER) { final String commandToSend = command.getText(); final int cursorPosition = command.getCaretPosition(); command.setDisable(true); commandHistory.add(new CommandHistory.Item(commandToSend, cursorPosition)); Text commandText = new Text(nextSymbol + commandToSend + "\n"); commandText.getStyleClass().add("commandText"); console.getChildren().add(commandText); command.setText(""); if (commandInterpreter.sendLine(commandToSend, message -> { Platform.runLater(() -> { if (!StringUtils.isBlank(message)) { Text resultText = new Text(message); resultText.getStyleClass().add("resultText"); console.getChildren().add(resultText); } command.setDisable(false); command.requestFocus(); consolePane.setVvalue(consolePane.getVmax()); }); })) { nextSymbol = NOT_INSIDE_BLOCK; } else { nextSymbol = INSIDE_BLOCK; } } }); command.setOnKeyReleased(event -> { if (event.getCode() == KeyCode.UP) { CommandHistory.Item historyItem = commandHistory.up(); command.setText(historyItem.getCommand()); command.positionCaret(historyItem.getCursorPosition()); } else if (event.getCode() == KeyCode.DOWN) { CommandHistory.Item historyItem = commandHistory.down(); command.setText(historyItem.getCommand()); command.positionCaret(historyItem.getCursorPosition()); } }); this.setOnCloseRequest(event -> commandInterpreter.close()); }
From source file:jnetention.Core.java
protected void broadcastSelf() { if (myself != null) Platform.runLater(new Runnable() { @Override/*from w w w . ja va2 s. c o m*/ public void run() { broadcast(myself); } }); }
From source file:org.pdfsam.ui.log.TextAreaAppender.java
private void appendStackIfAvailable(ILoggingEvent event) { IThrowableProxy throwable = event.getThrowableProxy(); if (throwable != null) { Platform.runLater(() -> logListView.appendLog(LogLevel.toLogLevel(event.getLevel().toInt()), String.format("%s: %s", throwable.getClassName(), throwable.getMessage()))); Arrays.stream(throwable.getStackTraceElementProxyArray()).limit(MAX_STACK_DEPTH) .forEach(i -> Platform.runLater(() -> logListView .appendLog(LogLevel.toLogLevel(event.getLevel().toInt()), i.toString()))); int left = throwable.getStackTraceElementProxyArray().length - MAX_STACK_DEPTH; if (left > 0) { Platform.runLater(() -> logListView.appendLog(LogLevel.toLogLevel(event.getLevel().toInt()), DefaultI18nContext.getInstance().i18n("...and other {0}.", Integer.toString(left)))); }//from w w w .jav a2 s .co m } }
From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.GroupTreeItem.java
/** * Recursive method to add a grouping at a given path. * * @param path Full path (or subset not yet added) to add * @param g Group to add/*w w w .j a v a 2 s . c o m*/ * @param tree True if it is part of a tree (versus a list) */ void insert(String path, DrawableGroup g, Boolean tree) { if (tree) { String cleanPath = StringUtils.stripStart(path, "/"); // get the first token String prefix = StringUtils.substringBefore(cleanPath, "/"); // Are we at the end of the recursion? if ("".equals(prefix)) { getValue().setGroup(g); } else { GroupTreeItem prefixTreeItem = childMap.get(prefix); if (prefixTreeItem == null) { final GroupTreeItem newTreeItem = new GroupTreeItem(prefix, null, comp); prefixTreeItem = newTreeItem; childMap.put(prefix, prefixTreeItem); Platform.runLater(new Runnable() { @Override public void run() { synchronized (getChildren()) { getChildren().add(newTreeItem); } } }); } // recursively go into the path prefixTreeItem.insert(StringUtils.stripStart(cleanPath, prefix), g, tree); } } else { GroupTreeItem treeItem = childMap.get(path); if (treeItem == null) { final GroupTreeItem newTreeItem = new GroupTreeItem(path, g, comp); newTreeItem.setExpanded(true); childMap.put(path, newTreeItem); Platform.runLater(new Runnable() { @Override public void run() { synchronized (getChildren()) { getChildren().add(newTreeItem); if (comp != null) { FXCollections.sort(getChildren(), comp); } } } }); } } }