List of usage examples for javafx.application Platform runLater
public static void runLater(Runnable runnable)
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java
private void handleUpdatePhotos(List<Photo> photos) { LOGGER.debug("updating {} photos in grid", photos.size()); Platform.runLater(() -> { grid.updatePhotos(photos);// w ww . j a va 2 s . com // update the inspector selection Collection<Photo> entities = inspector.getEntities(); boolean updated = false; for (Photo photo : photos) { Optional<Photo> entity = entities.stream().filter(p -> p.getId().equals(photo.getId())).findFirst(); if (entity.isPresent()) { entities.remove(entity.get()); entities.add(photo); updated = true; } } if (updated) { inspector.setEntities(entities); } }); }
From source file:net.rptools.tokentool.client.TokenTool.java
@Override public void start(Stage primaryStage) throws IOException { stage = primaryStage;//from w w w. j av a 2 s .c om setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML), ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE)); root = fxmlLoader.load(); tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController(); Scene scene = new Scene(root); primaryStage.setTitle(I18N.getString("TokenTool.stage.title")); primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON))); primaryStage.setScene(scene); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaX += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaX > 1 || deltaX < -1) { if (deltaX % 2 == 0) { tokentool_Controller.updatePortraitLocation(deltaX, 0); deltaX = 0; } else { tokentool_Controller.updatePortraitLocation(deltaX - 1, 0); deltaX = 1; } } }); primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> { if (Double.isNaN(oldVal.doubleValue())) return; deltaY += newVal.doubleValue() - oldVal.doubleValue(); // Only adjust on even width adjustments if (deltaY > 1 || deltaY < -1) { if (deltaY % 2 == 0) { tokentool_Controller.updatePortraitLocation(0, deltaY); deltaY = 0; } else { tokentool_Controller.updatePortraitLocation(0, deltaY - 1); deltaY = 1; } } }); primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { tokentool_Controller.exitApplication(); } }); // Load all the overlays into the treeview tokentool_Controller.updateOverlayTreeview(overlayTreeItems); // Restore saved settings AppPreferences.restorePreferences(tokentool_Controller); // Add recent list to treeview tokentool_Controller.updateOverlayTreeViewRecentFolder(true); // Set the Overlay Options accordion to be default open view tokentool_Controller.expandOverlayOptionsPane(true); primaryStage.show(); // Finally, update token preview image after everything is done loading Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView()); }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.HighlightsViewControllerImpl.java
private void handlePhotosAdded(List<Photo> photos) { Platform.runLater(() -> { Journey journey = journeyPlaceList.getSelectedJourney(); if (journey == null) { return; }//from w w w. j a v a 2 s. c o m // add photos which belong to the current journey to the list this.photos.addAll(photos.stream().filter(p -> journey.equals(p.getData().getJourney())) .collect(Collectors.toList())); // reload the photos in the grid view setGoodPhotos(journeyPlaceList.getSelectedPlace()); setMostUsedTagsWithPhotos(journeyPlaceList.getSelectedPlace()); }); }
From source file:com.github.drbookings.ui.controller.MainController.java
private void addBooking() { final List<RoomBean> dates = RoomBeanSelectionManager.getInstance().selectionProperty(); Platform.runLater(() -> showAddBookingDialog(dates.get(0).getDate(), dates.get(0).getName())); }
From source file:SampleTableModel.java
@Override public void init() { tableModel = new SampleTableModel(); // create javafx panel for charts chartFxPanel = new JFXPanel(); chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT)); //JTable/*from w w w.j a va 2 s . c o m*/ JTable table = new JTable(tableModel); table.setAutoCreateRowSorter(true); table.setGridColor(Color.DARK_GRAY); SwingInterop.DecimalFormatRenderer renderer = new SwingInterop.DecimalFormatRenderer(); renderer.setHorizontalAlignment(JLabel.RIGHT); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(renderer); } JScrollPane tablePanel = new JScrollPane(table); tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT)); JPanel chartTablePanel = new JPanel(); chartTablePanel.setLayout(new BorderLayout()); //Split pane that holds both chart and table JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsplitPane.setTopComponent(chartTablePanel); jsplitPane.setBottomComponent(tablePanel); jsplitPane.setDividerLocation(410); chartTablePanel.add(chartFxPanel, BorderLayout.CENTER); // add(tablePanel, BorderLayout.CENTER); add(jsplitPane, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }
From source file:edu.wustl.lookingglass.issue.ExceptionPane.java
public final void submit() { assert javafx.application.Platform.isFxApplicationThread(); javafx.scene.control.ProgressIndicator indicator = new javafx.scene.control.ProgressIndicator( javafx.scene.control.ProgressIndicator.INDETERMINATE_PROGRESS); indicator.setPrefSize(100, 100);//from w w w . ja v a 2 s .c o m indicator.setMinSize(javafx.scene.control.Control.USE_PREF_SIZE, javafx.scene.control.Control.USE_PREF_SIZE); indicator.setMaxSize(javafx.scene.control.Control.USE_PREF_SIZE, javafx.scene.control.Control.USE_PREF_SIZE); indicator.setStyle("-fx-progress-color: black;"); getDialog().setAndShowOverlay(indicator); final BugReport report = this.generateReport(); this.attachProject(report); // Do not use SwingWorker in Java FX. new Thread(() -> { try { uploadToRedmine(report); } catch (Throwable t) { Logger.throwable(t, report); } Platform.runLater(() -> { getDialog().close(); }); }).start(); }
From source file:ca.wumbo.doommanager.client.controller.ConsoleController.java
/** * Takes whatever is in the text field and submits it. *//* w w w. ja v a 2 s. co m*/ private void submitLineToConsole() { // Trim the string before using, also nulls shouldn't happen (but just in case). String text = textField.getText().trim().replace('\0', '?'); // Ignore empty lines. if (text.isEmpty()) return; // Remember what we submitted, most recent goes first. commandBuffer.add(text); // Reset due to submission of text. commandBufferIndex = commandBuffer.size(); // Handle commands. switch (text.toLowerCase()) { case "clear": textArea.clear(); break; case "connect": // Note: Debugging only. textArea.appendText("Starting connection to local host..." + System.lineSeparator()); Optional<SelectionKey> key = clientSelector.openTCPConnection( new InetSocketAddress("localhost", Server.DEFAULT_LISTEN_PORT), new NetworkReceiver() { @Override public void signalConnectionTerminated() { System.out.println("Test connection killed."); } @Override public void receiveData(byte[] data) { System.out.println("Got data: " + data.length + " = " + Arrays.toString(data)); } }); if (key.isPresent()) { SelectionKey k = key.get(); Platform.runLater(() -> { try { Thread.sleep(2000); clientSelector.writeData(k, new byte[] { 1, 2 }); System.out.println("Go forth..."); } catch (Exception e) { System.err.println("UGH"); e.printStackTrace(); } }); } textArea.appendText("Connection made = " + key.isPresent() + System.lineSeparator()); break; case "copy": try { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection(textArea.getText()); clipboard.setContents(stringSelection, stringSelection); textArea.appendText("Copied to clipboard." + System.lineSeparator()); } catch (Exception e) { textArea.appendText("Error: Unable to get system clipboard." + System.lineSeparator()); } break; case "exit": coreController.exit(); break; case "getconnections": int numKeys = clientSelector.getNumConnections(); textArea.appendText("There " + (numKeys != 1 ? "are " : "is ") + numKeys + " key" + (numKeys != 1 ? "s." : ".") + System.lineSeparator()); break; case "help": textArea.appendText("Commands:" + System.lineSeparator()); textArea.appendText(" clear - Clears the console" + System.lineSeparator()); textArea.appendText(" copy - Copies all the content to your clipboard" + System.lineSeparator()); textArea.appendText(" exit - Exits the program" + System.lineSeparator()); textArea.appendText(" getconnections - Lists the connections available" + System.lineSeparator()); textArea.appendText(" help - Shows this help" + System.lineSeparator()); textArea.appendText(" history - Prints command history for " + MAX_COMMANDS_REMEMBERED + " entries" + System.lineSeparator()); textArea.appendText(" memory - Get current memory statistics" + System.lineSeparator()); textArea.appendText(" version - Gets the version information" + System.lineSeparator()); break; case "history": if (commandBuffer.size() <= 1) { textArea.appendText("No history to display" + System.lineSeparator()); break; } textArea.appendText("History:" + System.lineSeparator()); for (int i = 0; i < commandBuffer.size() - 1; i++) textArea.appendText(" " + commandBuffer.get(i) + System.lineSeparator()); // Print everything but the last command (which was this). break; case "memory": NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); long totalMem = Runtime.getRuntime().totalMemory(); long usedMem = totalMem - Runtime.getRuntime().freeMemory(); long maxMem = Runtime.getRuntime().maxMemory(); double megabyte = 1024.0 * 1024.0; textArea.appendText("Memory statistics:" + System.lineSeparator()); textArea.appendText( " Memory used: " + nf.format(Math.abs(((double) usedMem / (double) maxMem)) * 100.0) + "%" + System.lineSeparator()); textArea.appendText( " " + nf.format(usedMem / megabyte) + " mb (used memory)" + System.lineSeparator()); textArea.appendText( " " + nf.format(maxMem / megabyte) + " mb (max memory)" + System.lineSeparator()); break; // DEBUG case "startserver": if (Start.getParsedRuntimeArgs().isClientServer()) { if (!serverManager.isInitialized()) { try { textArea.appendText("Starting server on port " + Server.DEFAULT_LISTEN_PORT + "." + System.lineSeparator()); serverManager.initialize(); } catch (Exception e) { textArea.appendText("Unable to initialize server." + System.lineSeparator()); textArea.appendText(" " + e.getMessage() + System.lineSeparator()); } } if (serverManager.isInitialized()) { if (!serverManager.isRunning()) { textArea.appendText("Running server on port " + Server.DEFAULT_LISTEN_PORT + "." + System.lineSeparator()); try { new Thread(serverManager, "ClientConsoleServer").start(); textArea.appendText("Successfully set up server." + System.lineSeparator()); } catch (Exception e) { textArea.appendText("Error setting up server:" + System.lineSeparator()); textArea.appendText(" " + e.getMessage() + System.lineSeparator()); } } else { textArea.appendText("Server is already running." + System.lineSeparator()); } } else { textArea.appendText("Server not initialized, cannot run." + System.lineSeparator()); } } break; // DEBUG case "stopserver": if (Start.getParsedRuntimeArgs().isClientServer()) { if (serverManager.isInitialized() && serverManager.isRunning()) { serverManager.requestServerTermination(); textArea.appendText("Requested server termination." + System.lineSeparator()); } else { textArea.appendText( "Cannot stop server, it has not been initialized or started." + System.lineSeparator()); } } break; case "version": textArea.appendText(applicationTitle + " version: " + applicationVersion + System.lineSeparator()); break; default: textArea.appendText("Unknown command: " + text + System.lineSeparator()); textArea.appendText("Type 'help' for commands" + System.lineSeparator()); break; } textField.clear(); }
From source file:com.playonlinux.ui.impl.javafx.mainwindow.center.ViewApps.java
@Override public void update(Observable o, Object arg) { RemoteAvailableInstallers remoteAvailableInstallers = (RemoteAvailableInstallers) o; Platform.runLater(() -> update(remoteAvailableInstallers)); }
From source file:com.github.vatbub.tictactoe.view.AnimationThreadPoolExecutor.java
@SuppressWarnings("unused") public <T> Future<T> submitWaitForUnlock(Callable<T> task) { Callable<T> effectiveTask = () -> { // PrintStreams magically don't make the wait loop hang PrintStream nullStream = new PrintStream(new OutputStream() { public void write(int b) { //DO NOTHING }//from ww w. j a va2s . c o m }); while (isBlocked()) { nullStream.println("Waiting..."); } // run FutureTask<T> effectiveCall = new FutureTask<>(task); Platform.runLater(effectiveCall); return effectiveCall.get(); }; return super.schedule(effectiveTask, 0, NANOSECONDS); }
From source file:acmi.l2.clientmod.l2smr.Controller.java
protected void longTask(Task task, Consumer<Throwable> exceptionHandler) { executor.execute(() -> {/*w w w.ja v a 2 s . com*/ Platform.runLater(() -> { progress.setProgress(-1); progress.setVisible(true); }); try { task.run(value -> Platform.runLater(() -> progress.setProgress(value))); } catch (Throwable t) { exceptionHandler.accept(t); } finally { Platform.runLater(() -> progress.setVisible(false)); } }); }