List of usage examples for javafx.concurrent Task progressProperty
@Override public final ReadOnlyDoubleProperty progressProperty()
From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java
/** * Reload a record (no calculations)/* w w w.j a v a 2 s . c om*/ * @param pRecord */ private void internalReloadRecord(final int pRecord) { gLogger.trace("Reloading record: " + pRecord); Task<Integer> task = new Task<Integer>() { @Override protected Integer call() throws Exception { int max = 2; int count = 0; Platform.runLater(new Runnable() { //@Override public void run() { internalBeforeGUIThread(); imageLeft.setImage(null); imageRight.setImage(null); imageLeftLabel.setText(gResults.get(pRecord).getFileOne().getName()); imageRightLabel.setText(gResults.get(pRecord).getFileTwo().getName()); psnrLabelValue.setText(gResults.get(pRecord).getPsnr() + ""); ssimLabelValue.setText(gResults.get(pRecord).getSsimMean() + ""); internalSetSSIMVariance(gResults.get(pRecord).getSsimVariance()); ssimMinValue.setText(gResults.get(pRecord).getSsimMin() + ""); internalUpdateManualCheckLabel(pRecord); } }); final BufferedImage one = internalLoadImage(gResults.get(pRecord).getFileOne()); Platform.runLater(new Runnable() { //@Override public void run() { imageLeft.setImage(SwingFXUtils.toFXImage(one, null)); } }); updateProgress(++count, max); final BufferedImage two = internalLoadImage(gResults.get(pRecord).getFileTwo()); Platform.runLater(new Runnable() { //@Override public void run() { imageRight.setImage(SwingFXUtils.toFXImage(two, null)); internalImageZoomToFit(); } }); updateProgress(++count, max); internalAfterGUIThread(); return null; } }; progressIndicator.progressProperty().bind(task.progressProperty()); Thread loader = new Thread(task); loader.setDaemon(true); loader.start(); internalDisableInterface(false); }
From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java
/** * overlay heatmap on image/*w w w . j av a 2 s.c o m*/ */ private void internalOverlayHeatmap() { gRightImageSave = imageRight.getImage(); if (!gHeatmapGenerated) { internalBeforeGUIThread(); //threaded load so GUI doesn't hang Task<Integer> task = new Task<Integer>() { @Override protected Integer call() throws Exception { BufferedImage image = SwingFXUtils.fromFXImage(imageRight.getImage(), null); if (gHeatmap == null) { //re-generate heatmap (must be on a re-load) try { gHeatmap = Imaging.getBufferedImage(gResults.get(gCurrentRecord).getHeatmapTemp()); } catch (IOException | ImageReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } } for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int rgb = image.getRGB(x, y); Color heatmapColor = new Color(gHeatmap.getRGB((x / DissimilarV2.SSIMWINDOWSIZE), (y / DissimilarV2.SSIMWINDOWSIZE))); int heatmapPixel = heatmapColor.getGreen();//&maxPixelValue; if (heatmapColor.getGreen() != heatmapColor.getBlue() && heatmapColor.getBlue() != heatmapColor.getRed()) { gLogger.error("Heatmap error (should not happen)"); } double factor = 1 - (((double) heatmapPixel / 255)); Color col = new Color(rgb); int red = (int) (factor * col.getRed()); int green = (int) (factor * col.getGreen()); int blue = (int) (factor * col.getBlue()); if (red < 0) red = 0; if (green < 0) green = 0; if (blue < 0) blue = 0; col = new Color(red, green, blue); image.setRGB(x, y, col.getRGB()); } } gHeatmapImage = SwingFXUtils.toFXImage(image, null); gHeatmapGenerated = true; Platform.runLater(new Runnable() { //@Override public void run() { imageRight.setImage(gHeatmapImage); } }); internalAfterGUIThread(); return 1; } }; progressIndicator.progressProperty().bind(task.progressProperty()); Thread loader = new Thread(task); loader.setDaemon(true); loader.start(); } else { imageRight.setImage(gHeatmapImage); } }
From source file:utilitybasedfx.MainGUIController.java
private void enableWorking(Task task) { btnImportSource.setDisable(true);// ww w .jav a 2 s .co m btnImportCompiled.setDisable(true); btnCompileFromSource.setDisable(true); btnGenerate.setDisable(true); lblWorking.setVisible(true); barWorking.setVisible(true); lblWorkingTask.setVisible(true); lblWorkingTask.textProperty().bind(task.messageProperty()); barWorking.progressProperty().bind(task.progressProperty()); task.stateProperty().addListener(new ChangeListener<Worker.State>() { @Override public void changed(ObservableValue<? extends Worker.State> observableValue, Worker.State oldState, Worker.State newState) { if (newState == Worker.State.SUCCEEDED) { disableWorking(); } else if (newState == Worker.State.FAILED) { disableWorking(); //Utils.stackErrorDialog((Exception)task.getException()); task.getException().printStackTrace(); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("There was an error"); alert.setHeaderText("There was some kind of error while trying to do the current task"); alert.setContentText(task.getException().toString()); alert.showAndWait(); } } }); new Thread(task).start(); }
From source file:view.FXApplicationController.java
public void classify() { final long startTime = System.nanoTime(); Task<Void> task = new Task<Void>() { @Override/*from w ww . j a v a 2 s. c o m*/ protected Void call() throws Exception { updateProgress(-1, featureModel.getNumberOfEpochs()); computeFeatures(); ClassificationController.classify(classifier, featureModel); Platform.runLater(new Runnable() { @Override public void run() { progressBar.setVisible(false); hypnogram.updateAll(); updateWindows(); } }); System.out.println("Elapsed time: " + (System.nanoTime() - startTime) / 1e6); return null; } }; progressBar.progressProperty().bind(task.progressProperty()); Thread thread = new Thread(task); thread.setDaemon(true); thread.start(); }