javafx.concurrent.Worker Java Examples

The following examples show how to use javafx.concurrent.Worker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateDownloadServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceBinaryFoundNoVerification() throws Exception {
	CompletableFuture<ServiceTestResults<Path>> serviceStateDoneFuture = new CompletableFuture<>();
	UpdateDownloadService service = new UpdateDownloadService(releaseNoVerification);

	service.stateProperty().addListener((observable, oldValue, newValue) -> {
		if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
			serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
		}
	});
	
	service.start();

	ServiceTestResults<Path> result = serviceStateDoneFuture.get(1000, TimeUnit.MILLISECONDS);

	assertNull(result.exception);
	assertEquals(Worker.State.SUCCEEDED, result.state);
	assertEquals(Paths.get(System.getProperty("java.io.tmpdir"), "updatefx.xml"), result.serviceResult);
	Files.delete(result.serviceResult);
}
 
Example #2
Source File: BasicView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateProductDetails(InAppBillingService service) {
    setBottom(new HBox(10.0, new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS), new Label("Loading Products")));

    Worker<List<Product>> productDetails = service.fetchProductDetails();
    productDetails.stateProperty().addListener((obs, ov, nv) -> {
        switch (nv) {
            case CANCELLED:
                setBottom(new HBox(10.0, new Label("Loading products cancelled."), MaterialDesignIcon.REFRESH.button(e -> updateProductDetails(PlayerService.getInstance().getService().get()))));
                break;
            case SUCCEEDED:
                createProductGrid(productDetails.getValue());
                break;
            case FAILED:
                setBottom(new HBox(10.0, new Label("Failed to load products."), MaterialDesignIcon.REFRESH.button(e -> updateProductDetails(PlayerService.getInstance().getService().get()))));
                break;
        }
    });
}
 
Example #3
Source File: StepRepresentationBrowser.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void waitForBeingLoaded() {
    final Semaphore lock = new Semaphore(0);

    Platform.runLater(() -> webView.getEngine().getLoadWorker().stateProperty()
            .addListener(((observableValue, oldState, newState) -> {
                if (newState == Worker.State.SUCCEEDED) {
                    lock.release();
                }
            })));

    try {
        lock.acquire();
    } catch (InterruptedException e) {
        this.messageWaitingForResponse.sendCancelSignal();
    }
}
 
Example #4
Source File: TwitterWebEngineListener.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
public void doAction(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
    if (newValue == Worker.State.SUCCEEDED) {
        NodeList nodeList = webEngine.getDocument().getElementsByTagName("code");

        if (nodeList != null) {
            HTMLElementImpl htmlNode = (HTMLElementImpl) nodeList.item(0);

            if (htmlNode != null) {
                String authorizationCode = htmlNode.getInnerText();

                save(new AuthorizationData(authorizationCode));
            }
        }
    }
}
 
Example #5
Source File: TextEditorPane.java    From logbook-kai with MIT License 6 votes vote down vote up
@FXML
void initialize() {
    WebEngine engine = this.webview.getEngine();
    engine.load(PluginServices.getResource("logbook/gui/text_editor_pane.html").toString());
    engine.getLoadWorker().stateProperty().addListener(
            (ob, o, n) -> {
                if (n == Worker.State.SUCCEEDED) {
                    this.setting();
                }
            });

    KeyCombination copy = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN);
    KeyCombination cut = new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN);

    this.webview.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        if (copy.match(event) || cut.match(event)) {
            String text = String.valueOf(engine.executeScript("getCopyText()"));

            Platform.runLater(() -> {
                ClipboardContent content = new ClipboardContent();
                content.putString(text);
                Clipboard.getSystemClipboard().setContent(content);
            });
        }
    });
}
 
Example #6
Source File: PlayerService.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onQueryResultReceived(InAppBillingQueryResult result) {
    for (ProductOrder productOrder : result.getProductOrders()) {
        if (productOrder.getProduct().getType() == Product.Type.CONSUMABLE &&
                productOrder.getProduct().getDetails().getState() == ProductDetails.State.APPROVED) {
            Worker<Product> finish = service.finish(productOrder);
            finish.stateProperty().addListener((obs, ov, nv) -> {
                if (nv == Worker.State.SUCCEEDED) {
                    if (productOrder.getProduct().equals(InAppProduct.HEALTH_POTION.getProduct())) {
                        player.boughtHealthPotion();
                    }
                } else if (nv == Worker.State.FAILED) {
                    finish.getException().printStackTrace();
                }
            });
        } else if (productOrder.getProduct().equals(InAppProduct.WOODEN_SHIELD.getProduct())) {
            player.setWoodenShieldOwned(true);
        }
    }
}
 
Example #7
Source File: Program.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
public void initEditor(WebView editor, File sourceFile, boolean isBlank) {
    this.editor = editor;
    targetFile = sourceFile;
    if (targetFile != null) {
        filename = targetFile.getName();
    }

    editor.getEngine().getLoadWorker().stateProperty().addListener(
            (value, old, newState) -> {
                if (newState == Worker.State.SUCCEEDED) {
                    JSObject document = (JSObject) editor.getEngine().executeScript("window");
                    document.setMember("java", this);
                    Platform.runLater(()->createEditor(isBlank));
                }
            });

    editor.getEngine().setPromptHandler((PromptData prompt) -> {
        TextInputDialog dialog = new TextInputDialog(prompt.getDefaultValue());
        dialog.setTitle("Jace IDE");
        dialog.setHeaderText("Respond and press OK, or Cancel to abort");
        dialog.setContentText(prompt.getMessage());
        return dialog.showAndWait().orElse(null);
    });

    editor.getEngine().load(getClass().getResource(CODEMIRROR_EDITOR).toExternalForm());
}
 
Example #8
Source File: AsyncImageProperty.java    From neural-style-gui with GNU General Public License v3.0 6 votes vote down vote up
public AsyncImageProperty(int width, int height) {
    imageLoadService.setSize(width, height);

    imageLoadService.stateProperty().addListener((observable, oldValue, value) -> {
        if (value == Worker.State.SUCCEEDED)
            set(imageLoadService.getValue());
        if (value == Worker.State.FAILED)
            set(null);

        if (value == Worker.State.SUCCEEDED || value == Worker.State.CANCELLED || value == Worker.State.FAILED) {
            File handle = imageFile.get();
            if (handle != null && !handle.equals(imageLoadService.imageFile))
                loadImageInBackground(handle);
        }
    });

    imageFile.addListener((observable, oldValue, value) -> {
        if(!imageLoadService.isRunning()) {
            loadImageInBackground(imageFile.getValue());
        }
    });
}
 
Example #9
Source File: UpdateFinderServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceUpdateWithSameLicense() throws Exception {
	CompletableFuture<ServiceTestResults<Release>> serviceStateDoneFuture = new CompletableFuture<>();
	UpdateFinderService service = new UpdateFinderService(app, 10001, 1);

	service.stateProperty().addListener((observable, oldValue, newValue) -> {
		if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
			serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
		}
	});

	service.start();

	ServiceTestResults<Release> result = serviceStateDoneFuture.get(200, TimeUnit.MILLISECONDS);

	assertNull(result.exception);
	assertEquals(Worker.State.SUCCEEDED, result.state);
	assertEquals(release10002SameLicense, result.serviceResult);
}
 
Example #10
Source File: UpdateFinderServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceUpdateWithNewLicense() throws Exception {
	CompletableFuture<ServiceTestResults<Release>> serviceStateDoneFuture = new CompletableFuture<>();
	UpdateFinderService service = new UpdateFinderService(app, 10002, 1);

	service.stateProperty().addListener((observable, oldValue, newValue) -> {
		if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
			serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
		}
	});

	service.start();

	ServiceTestResults<Release> result = serviceStateDoneFuture.get(200, TimeUnit.MILLISECONDS);

	assertNull(result.exception);
	assertEquals(Worker.State.SUCCEEDED, result.state);
	assertEquals(releaseNewerLicense, result.serviceResult);
}
 
Example #11
Source File: UpdateFinderServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceUpdateNoUpdate() throws Exception {
	CompletableFuture<ServiceTestResults<Release>> serviceStateDoneFuture = new CompletableFuture<>();
	UpdateFinderService service = new UpdateFinderService(app, 20000, 2);

	service.stateProperty().addListener((observable, oldValue, newValue) -> {
		if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
			serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
		}
	});

	service.start();

	ServiceTestResults<Release> result = serviceStateDoneFuture.get(200, TimeUnit.MILLISECONDS);

	assertThat(result.exception, instanceOf(NoUpdateException.class));
	assertEquals(Worker.State.FAILED, result.state);
	assertNull(result.serviceResult);
}
 
Example #12
Source File: UpdateDownloadServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceBinaryNotFound() throws Exception {
	CompletableFuture<ServiceTestResults<Path>> serviceStateDoneFuture = new CompletableFuture<>();
	UpdateDownloadService service = new UpdateDownloadService(emptyRelease);

	service.stateProperty().addListener((observable, oldValue, newValue) -> {
		if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
			serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
		}
	});
	
	service.start();

	ServiceTestResults<Path> result = serviceStateDoneFuture.get(1000, TimeUnit.MILLISECONDS);

	assertThat(result.exception, instanceOf(IllegalArgumentException.class));
	assertEquals(Worker.State.FAILED, result.state);
	assertNull(result.serviceResult);
}
 
Example #13
Source File: XMLRetrieverServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testService() throws Throwable {
	CompletableFuture<ServiceTestResults<Application>> serviceStateDoneFuture = new CompletableFuture<>();
	
	XMLRetrieverService service = new XMLRetrieverService(getClass().getResource("updatefx.xml"));
	service.stateProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
				serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
			}
	});
	
	service.start();
	
	ServiceTestResults<Application> result = serviceStateDoneFuture.get(1000, TimeUnit.MILLISECONDS); 

	assertNull(result.exception);
	assertEquals(Worker.State.SUCCEEDED, result.state);
	assertNotNull(result.serviceResult);
	assertEquals("Example App", result.serviceResult.getName());
	assertEquals(2, result.serviceResult.getReleases().size());
	
	for (Release release : result.serviceResult.getReleases()) {
		assertEquals(result.serviceResult, release.getApplication());
	}
}
 
Example #14
Source File: IOSInAppBillingService.java    From attach with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Worker<Product> finish(ProductOrder productOrder) {
    if (!isReady()) {
        return null;
    }
    Task<Product> task = new Task<Product>() {

        @Override
        protected Product call() throws Exception {
            if (productOrder != null && productOrder.getProduct() != null) {
                Product product = productOrder.getProduct();
                product.getDetails().setState(ProductDetails.State.FINISHED);
                return product;
            }
            return null;
        }
    };
    Thread thread = new Thread(task);
    thread.start();
    return task;
}
 
Example #15
Source File: XMLRetrieverServiceTest.java    From updatefx with MIT License 6 votes vote down vote up
@Test
public void testServiceMissingXML() throws Throwable {
	CompletableFuture<ServiceTestResults<Application>> serviceStateDoneFuture = new CompletableFuture<>();
	
	XMLRetrieverService service = new XMLRetrieverService(new URL("file:///i_really_hope_this_file_is_missing.xml"));
	service.stateProperty().addListener((observable, oldValue, newValue) -> {
			if (newValue == Worker.State.FAILED || newValue == Worker.State.SUCCEEDED) {
				serviceStateDoneFuture.complete(new ServiceTestResults<>(service.getState(), service.getValue(), service.getException()));
			}
	});
	
	service.start();
	
	ServiceTestResults<Application> result = serviceStateDoneFuture.get(1000, TimeUnit.MILLISECONDS); 

	assertNotNull(result.exception);
	assertEquals(Worker.State.FAILED, result.state);
	assertNull(result.serviceResult);
}
 
Example #16
Source File: MathJaxService.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
private void initialize(Runnable... runnable) {

        webEngine().getLoadWorker().stateProperty().addListener((observableValue1, state, state2) -> {
            if (state2 == Worker.State.SUCCEEDED) {
                JSObject window = getWindow();
                if (window.getMember("afx").equals("undefined"))
                    window.setMember("afx", controller);

                if (!initialized) {
                    for (Runnable run : runnable) {
                        run.run();
                    }
                }

                initialized = true;
            }
        });

        this.load();
    }
 
Example #17
Source File: SlidePane.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void afterInit() {
    threadService.runActionLater(() -> {
        getWindow().setMember("afx", controller);
        ReadOnlyObjectProperty<Worker.State> stateProperty = webEngine().getLoadWorker().stateProperty();
        WebView popupView = new WebView();
        Stage stage = new Stage();
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setScene(new Scene(popupView));
        stage.setTitle("AsciidocFX");
        InputStream logoStream = SlidePane.class.getResourceAsStream("/logo.png");
        stage.getIcons().add(new Image(logoStream));
        webEngine().setCreatePopupHandler(param -> {
            if (!stage.isShowing()) {
                stage.show();
                popupView.requestFocus();
            }
            return popupView.getEngine();
        });
        stateProperty.addListener(this::stateListener);
    });
}
 
Example #18
Source File: StepRepresentationBrowser.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void waitForUrl(String urlMatch) {
    final Semaphore lock = new Semaphore(0);

    Platform.runLater(() -> webView.getEngine().getLoadWorker().stateProperty()
            .addListener(((observableValue, oldState, newState) -> {
                if (newState == Worker.State.SUCCEEDED && urlMatches(getCurrentUrl(), urlMatch)) {
                    lock.release();
                }
            })));

    try {
        lock.acquire();
    } catch (InterruptedException e) {
        this.messageWaitingForResponse.sendCancelSignal();
    }

}
 
Example #19
Source File: TwitterWebEngineListener.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
public void doAction(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
    if (newValue == Worker.State.SUCCEEDED) {
        NodeList nodeList = webEngine.getDocument().getElementsByTagName("code");

        if (nodeList != null) {
            HTMLElementImpl htmlNode = (HTMLElementImpl) nodeList.item(0);

            if (htmlNode != null) {
                String authorizationCode = htmlNode.getInnerText();

                save(new AuthorizationData(authorizationCode));
            }
        }
    }
}
 
Example #20
Source File: YfitonWebEngineListener.java    From yfiton with Apache License 2.0 5 votes vote down vote up
@Override
public void doAction(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
    String location = webEngine.getLocation();

    if (newValue == Worker.State.SUCCEEDED
            && location.startsWith(OAuthNotifier.YFITON_OAUTH_CALLBACK_URL)) {

        AuthorizationData transformed = getParameters(location);

        save(transformed);
    }
}
 
Example #21
Source File: TimingRenderer.java    From Sword_emulator with GNU General Public License v3.0 5 votes vote down vote up
private static void start() {
    if (scheduledService.getState() != Worker.State.READY) {
        scheduledService.restart();
    } else {
        scheduledService.start();
    }
}
 
Example #22
Source File: AbstractTopsoilPlot.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
public List<Node> toolbarControlsFactory() {
    List<Node> controls = new ArrayList<>();

    JavaScriptPlot javaScriptPlot = (JavaScriptPlot) plot;

    Text loadingIndicator = new Text("Loading...");
    javaScriptPlot.getLoadFuture().thenRunAsync(() -> {
        loadingIndicator.visibleProperty().bind(
                javaScriptPlot.getWebEngine().getLoadWorker()
                        .stateProperty().isEqualTo(Worker.State.RUNNING));
    },
            Platform::runLater
    );

    Button saveToSVGButton = new Button("Save as SVG");
    saveToSVGButton.setOnAction(mouseEvent -> {
        new SVGSaver().save(javaScriptPlot.displayAsSVGDocument());
    });

    Button recenterButton = new Button("Re-center");
    recenterButton.setOnAction(mouseEvent -> {
        javaScriptPlot.recenter();
    });

    controls.add(loadingIndicator);
    controls.add(saveToSVGButton);
    controls.add(recenterButton);

    return controls;
}
 
Example #23
Source File: ArrayTester.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Stage stage) throws Exception {
    
    webview = new WebView();
    webengine = new JavaFxWebEngine(webview.getEngine());
    JavascriptRuntime.setDefaultWebEngine( webengine );
    
    BorderPane bp = new BorderPane();
    bp.setCenter(webview);
    
    webengine.getLoadWorker().stateProperty().addListener(
            new ChangeListener<Worker.State>() {
                public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
                    if (newState == Worker.State.SUCCEEDED) {
                        runTests();
                        //Platform.exit();
                    }
                }
            });
    webengine.load(getClass().getResource("/com/lynden/gmapsfx/html/arrays.html").toExternalForm());
    
    Scene scene = new Scene(bp, 600, 600);
    
    stage.setScene(scene);
    stage.show();
    
}
 
Example #24
Source File: SlidePane.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
private void stateListener(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
    if (newValue == Worker.State.SUCCEEDED) {
        getWindow().setMember("afx", controller);
        if ("revealjs".equals(backend))
            this.loadJs("/afx/worker/js/?p=js/jquery.js", "/afx/worker/js/?p=js/reveal-extensions.js");
        if ("deckjs".equals(backend))
            this.loadJs("/afx/worker/js/?p=js/deck-extensions.js");
    }
}
 
Example #25
Source File: ViewPanel.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public void setOnSuccess(Runnable runnable) {
    threadService.runActionLater(() -> {
        getWindow().setMember("afx", controller);
        Worker<Void> loadWorker = webEngine().getLoadWorker();
        ReadOnlyObjectProperty<Worker.State> stateProperty = loadWorker.stateProperty();
        stateProperty.addListener((observable, oldValue, newValue) -> {
            if (newValue == Worker.State.SUCCEEDED) {
                threadService.runActionLater(runnable);
            }
        });
    });
}
 
Example #26
Source File: TerasologyLauncher.java    From TerasologyLauncher with Apache License 2.0 5 votes vote down vote up
private void showSplashStage(final Stage initialStage, final Task<LauncherConfiguration> task) {
    progressText.textProperty().bind(task.messageProperty());
    loadProgress.progressProperty().bind(task.progressProperty());
    task.stateProperty().addListener((observableValue, oldState, newState) -> {
        if (newState == Worker.State.SUCCEEDED) {
            loadProgress.progressProperty().unbind();
            loadProgress.setProgress(1);
            if (mainStage != null) {
                mainStage.setIconified(false);
            }
            initialStage.toFront();
            FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.2), splashLayout);
            fadeSplash.setFromValue(1.0);
            fadeSplash.setToValue(0.0);
            fadeSplash.setOnFinished(actionEvent -> initialStage.hide());
            fadeSplash.play();
        } // todo add code to gracefully handle other task states.
    });

    decorateStage(initialStage);

    Scene splashScene = new Scene(splashLayout);
    initialStage.initStyle(StageStyle.UNDECORATED);
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    initialStage.setScene(splashScene);
    initialStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
    initialStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
    initialStage.show();
}
 
Example #27
Source File: ProxyDialog.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getDocsInBackground(final boolean showProxyDialogOnFail, final Runnable callBackOnSuccess) {
    final FetchDocListTask task = new FetchDocListTask(Ensemble2.getEnsemble2().getDocsUrl());
    task.stateProperty().addListener(new ChangeListener<Worker.State>() {
        public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State newState) {
            try {
                Thread.sleep(5); //timing problem
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
            if (newState == Worker.State.SUCCEEDED) {
                // extract all the docs pages from the all classes page
                DocsHelper.extractDocsPagesFromAllClassesPage(
                        (CategoryPage)Ensemble2.getEnsemble2().getPages().getDocs(),
                        task.getValue(), 
                        Ensemble2.getEnsemble2().getDocsUrl());
                // update docs pages cross links to samples
                DocsHelper.syncDocPagesAndSamplePages(
                        (CategoryPage)Ensemble2.getEnsemble2().getPages().getSamples());
                if (callBackOnSuccess != null) callBackOnSuccess.run();
            } else if (newState == Worker.State.FAILED) {
                if (showProxyDialogOnFail) {
                    Ensemble2.getEnsemble2().showProxyDialog();
                }
            }
        }
    });
    new Thread(task).start();
}
 
Example #28
Source File: CheckForUpdateAction.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void show() {
	Task<ReleaseInfo> task = new Task<ReleaseInfo>() {
		@Override
		protected ReleaseInfo call() throws Exception {
			return AdcVersionCheckTask.getLatestRelease();
		}
	};
	task.stateProperty().addListener((observable, oldValue, state) -> {
		if (state == Worker.State.CANCELLED || state == Worker.State.FAILED || state == Worker.State.SUCCEEDED) {
			releaseInfo = task.getValue();
			if (releaseInfo == null || releaseInfo.getTagName().equals(Lang.Application.VERSION)) {
				if (task.getState() == Worker.State.FAILED) {
					lblStatus.setText(bundle.getString("Popups.CheckForUpdate.failed-to-get-info"));
				} else {
					lblStatus.setText(bundle.getString("Popups.CheckForUpdate.no-update"));
				}
			} else {
				updateAvailable = true;
				lblStatus.setText(
						String.format(
								bundle.getString("Popups.CheckForUpdate.update-available-f"),
								releaseInfo.getTagName()
						)
				);
			}
			footer.getBtnCancel().setDisable(false);
			footer.getBtnOk().setDisable(false);
		}
	});
	Thread thread = new Thread(task);
	thread.setName("Arma Dialog Creator - Check For Update Task");
	thread.setDaemon(true);
	thread.start();

	//place super.show() at bottom or the dialog will freeze the current thread until dialog is closed
	super.show();
}
 
Example #29
Source File: WebEngineListener.java    From yfiton with Apache License 2.0 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
    if (!firstPageLoaded) {
        firstPageLoaded = true;
        return;
    }

    doAction(observable, oldValue, newValue);
}
 
Example #30
Source File: Browser.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Stage startWebTool() {

	    Stage webStage = new Stage();
	    webStage.setTitle("Mars Simulation Project - Online Tool");
	    webStage.initModality(Modality.APPLICATION_MODAL);

	    final WebView webView = new WebView();
	    final WebEngine webEngine = webView.getEngine();

	    ScrollPane scrollPane = new ScrollPane();
	    scrollPane.setFitToWidth(true);
	    scrollPane.setContent(webView);

	    webEngine.getLoadWorker().stateProperty()
	        .addListener(new ChangeListener<State>() {
	          //@Override
	          public void changed(@SuppressWarnings("rawtypes") ObservableValue ov, State oldState, State newState) {
	            if (newState == Worker.State.SUCCEEDED) {
	            	webStage.setTitle(webEngine.getLocation());
	            }
	          }
	        });

	    webEngine.load("http://mars-sim.sourceforge.net/#development");
	    //webEngine.load("http://jquerymy.com/");

	    Scene webScene = new Scene(scrollPane);
	    webStage.setScene(webScene);

	    return webStage;
	}