當前位置: 首頁>>代碼示例>>Java>>正文


Java Worker類代碼示例

本文整理匯總了Java中javafx.concurrent.Worker的典型用法代碼示例。如果您正苦於以下問題:Java Worker類的具體用法?Java Worker怎麽用?Java Worker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Worker類屬於javafx.concurrent包,在下文中一共展示了Worker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: changed

import javafx.concurrent.Worker; //導入依賴的package包/類
@Override
public void changed(ObservableValue<? extends State> observable, State oldState, State newState) {
	if (newState == Worker.State.SUCCEEDED) {
		try {
			//Determine the full url
			String favIconFullURL = getHostName(webEngine.getLocation()) + "favicon.ico";
			//System.out.println(favIconFullURL)
			
			//Create HttpURLConnection 
			HttpURLConnection httpcon = (HttpURLConnection) new URL(favIconFullURL).openConnection();
			httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
			List<BufferedImage> image = ICODecoder.read(httpcon.getInputStream());
			
			//Set the favicon
			facIconImageView.setImage(SwingFXUtils.toFXImage(image.get(0), null));
			
		} catch (Exception ex) {
			//ex.printStackTrace()
			facIconImageView.setImage(null);
		}
	}
}
 
開發者ID:goxr3plus,項目名稱:JavaFX-Web-Browser,代碼行數:23,代碼來源:WebBrowserTabController.java

示例2: showSplash

import javafx.concurrent.Worker; //導入依賴的package包/類
private void showSplash(final Stage initStage, Task<?> task, InitCompletionHandler initCompletionHandler) {
    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);
            initStage.toFront();
            FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.2), splashLayout);
            fadeSplash.setFromValue(1.0);
            fadeSplash.setToValue(0.0);
            fadeSplash.setOnFinished(actionEvent -> initStage.hide());
            fadeSplash.play();

            initCompletionHandler.complete();
        }
    });

    Scene splashScene = new Scene(splashLayout);
    initStage.initStyle(StageStyle.UNDECORATED);
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    initStage.setScene(splashScene);
    initStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
    initStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
    initStage.show();
}
 
開發者ID:mhusam,項目名稱:ChessBot,代碼行數:27,代碼來源:ChessBotAppSplash.java

示例3: getListener

import javafx.concurrent.Worker; //導入依賴的package包/類
private ChangeListener<Worker.State> getListener(final DropboxManager.DropboxAccountLinkListener dropboxAccountLinkListener,
                                                 final DbxWebAuthNoRedirect webAuth, final WebEngine engine, final Stage stage) {
    return (observable, oldValue, newState) -> {
        if (newState == Worker.State.SUCCEEDED) {
            try {
                final String authCode = (String) engine.executeScript("document.getElementById('auth-code').textContent");
                LOGGER.debug("Authorization Code [{}]", authCode);
                DbxAuthFinish authFinish = webAuth.finish(authCode);

                String accessToken = authFinish.accessToken;
                final DbxAuthInfo dbxAuthInfo = new DbxAuthInfo(accessToken, DbxHost.Default);
                DbxAuthInfo.Writer.writeToFile(dbxAuthInfo, accessTokenFile);

                DbxClient client = new DbxClient(dropboxConfig, dbxAuthInfo.accessToken, dbxAuthInfo.host);

                final String displayName = client.getAccountInfo().displayName;
                LOGGER.info("Linked account [{}]", displayName);
                stage.close();
                dropboxAccountLinkListener.accountLinked(AccountInfoFactory.getAccountInfo(client.getAccountInfo()));
            } catch (Exception e) {
                // ignore
            }
        }
    };
}
 
開發者ID:adelolmo,項目名稱:biblio,代碼行數:26,代碼來源:DropboxLinkDialog.java

示例4: showHisoty

import javafx.concurrent.Worker; //導入依賴的package包/類
private void showHisoty() {
	debug = new HistorySearch(cmboHistoryMonth.getValue(), cmboFilterList.getValue());

	webEngine.getLoadWorker().stateProperty().addListener(
       	    new ChangeListener<Worker.State>() {
       	        @Override
       	        public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
       	            if (newValue == Worker.State.SUCCEEDED) {
       	                JSObject windowObject = (JSObject) webEngine.executeScript("window");
       	                windowObject.setMember("HistorySearch", debug); // insert object
       	                windowObject.call("ready"); // execute callback
       	            }
       	        }
       	    }
       	);
       URL url = getClass().getResource("/html/index.html");
       webEngine.load(url.toString());
}
 
開發者ID:krHasan,項目名稱:Money-Manager,代碼行數:19,代碼來源:TransactionHistoryController.java

示例5: btnGo

import javafx.concurrent.Worker; //導入依賴的package包/類
@FXML
	private void btnGo(ActionEvent event) {
		historyByDate = new HistorySearchByDate(datePicker.getValue());
		
		webEngine.getLoadWorker().stateProperty().addListener(
        	    new ChangeListener<Worker.State>() {
        	        @Override
        	        public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
        	            if (newValue == Worker.State.SUCCEEDED) {
        	                JSObject windowObject = (JSObject) webEngine.executeScript("window");
        	                windowObject.setMember("HistorySearchByDate", historyByDate); // insert object
        	                windowObject.call("searchHistoryByDate"); // execute callback
        	            }
        	        }
        	    }
        	);
		URL url = getClass().getResource("/html/index.html");
        webEngine.load(url.toString());
		
//        String url = getClass().getResource("../html/index.html").toExternalForm();
//        webEngine.load(url);
	}
 
開發者ID:krHasan,項目名稱:Money-Manager,代碼行數:23,代碼來源:TransactionHistoryController.java

示例6: styleWebView

import javafx.concurrent.Worker; //導入依賴的package包/類
private void styleWebView(){
    webEngine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
        Document doc = webEngine.getDocument();
        if (newState == Worker.State.SUCCEEDED && doc.getDocumentElement().getElementsByTagName("head").item(0) != null) {
            Node head = doc.getDocumentElement().getElementsByTagName("head").item(0);

            // Google prettify
            if(prettifyCode.get() || Settings.ALWAYS_PRETTIFY_CODE_VIEW) {
                Element scriptNode = doc.createElement("script");
                scriptNode.setAttribute("src", "https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js");
                head.appendChild(scriptNode);
            }

            // Inject css styles
            Element styleNode = doc.createElement("style");
            Text styleContent = doc.createTextNode(Utils.getWebViewCss(prettifyCode.get() || Settings.ALWAYS_PRETTIFY_CODE_VIEW ? "#f2f2f2" : "#545454"));

            styleNode.appendChild(styleContent);
            head.appendChild(styleNode);
            currentHtmlWithStyle = webEngine.executeScript("document.documentElement.innerHTML").toString();
        }
    });
}
 
開發者ID:jdesive,項目名稱:textmd,代碼行數:24,代碼來源:EditorPane.java

示例7: getDocsInBackground

import javafx.concurrent.Worker; //導入依賴的package包/類
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();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:29,代碼來源:ProxyDialog.java

示例8: initialize

import javafx.concurrent.Worker; //導入依賴的package包/類
protected void initialize(boolean sync) {
    addJavascriptInterface("console", console);
    addJavascriptInterface("NetkitGateway", gateway);

    AtomicBoolean done = new AtomicBoolean(false);
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
        @Override
        public void changed(ObservableValue<? extends Worker.State> observableValue, Worker.State oldValue, Worker.State newValue) {
            if (newValue == Worker.State.SUCCEEDED) {
                done.set(true);
            }
        }
    });

    String netkitView = IOUtils.convertStreamToString(Netkit.class.getResourceAsStream("/netkit-view.html"));
    engine.loadContent(netkitView);

    if (!done.get() && sync) {
        WebViewUtils.wait(view);
    }
}
 
開發者ID:dzikoysk,項目名稱:Netkit,代碼行數:22,代碼來源:Netkit.java

示例9: LoadingProgressDisplay

import javafx.concurrent.Worker; //導入依賴的package包/類
/**
 * Creates a UI display monitor for provided worker.
 *
 * Assumes the worker is reporting progress as work done on a scale from 0 to 100 (other values indicate indeterminate progress).
 *
 * @param worker the worker whose progress is to be monitored and displayed.
 */
public LoadingProgressDisplay(Worker worker) {
    setMaxWidth(Double.MAX_VALUE);

    ColorAdjust bleach = new ColorAdjust();
    bleach.setSaturation(-0.6);
    setEffect(bleach);

    HBox.setHgrow(this, Priority.ALWAYS);

    visibleProperty().bind(worker.runningProperty());

    // as the webview load progresses update progress.
    worker.workDoneProperty().addListener((observableValue, oldNumber, newNumber) -> {
        if (newNumber == null) newNumber = -1.0;
        final double newValue = newNumber.doubleValue();
        if (newValue < 0.0 || newValue > 100.0) {
            setProgress(ProgressBar.INDETERMINATE_PROGRESS);
        }
        setProgress(newValue / 100.0);
    });
}
 
開發者ID:proofy,項目名稱:willow-browser,代碼行數:29,代碼來源:LoadingProgressDisplay.java

示例10: registerFunction

import javafx.concurrent.Worker; //導入依賴的package包/類
public void registerFunction( String namespace, Object theClass ) {
	log.debug( "Registering Java class whose methods can be called from javascript. Namespace: "
			+ namespace + ", Java class: " + theClass );

	Platform.runLater( new Runnable() {
		@Override
		public void run() {
			engine.getLoadWorker().stateProperty().addListener(
					new ChangeListener<State>() {
						@Override
						public void changed( ObservableValue<? extends Worker.State> ov,
								State oldState, State newState ) {
							if ( newState == Worker.State.SUCCEEDED ) {
								JSObject jsobj = (JSObject) engine.executeScript( "window" );
								jsobj.setMember( namespace, theClass );
							}
						}
					}
			);
		}
	} );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:23,代碼來源:BrowserPlaySheet2.java

示例11: AsyncImageProperty

import javafx.concurrent.Worker; //導入依賴的package包/類
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());
        }
    });
}
 
開發者ID:cameronleger,項目名稱:neural-style-gui,代碼行數:23,代碼來源:AsyncImageProperty.java

示例12: doAction

import javafx.concurrent.Worker; //導入依賴的package包/類
@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));
            }
        }
    }
}
 
開發者ID:yfiton,項目名稱:yfiton,代碼行數:17,代碼來源:TwitterWebEngineListener.java

示例13: test

import javafx.concurrent.Worker; //導入依賴的package包/類
@Test
public void test() {
    AtomicBoolean passed = new AtomicBoolean(false);
    Platform.runLater(() -> {
        initViewWithEngine();
        engine.getLoadWorker().stateProperty().addListener(
                (ov, old, now) -> {
                    if (now == Worker.State.SUCCEEDED) {
                        ((HTMLIFrameElement) engine.getDocument()
                        .getElementsByTagName("iframe").item(0)).getId();
                        passed.set(true);
                    }
                });
        engine.loadContent("<html><body>"
                + "<iframe id='123' src='resource/example1.html'/>"
                + "</body></html>");
    });
    doWait(passed::get);
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:20,代碼來源:IFrameUnsatisfiedLinkTest.java

示例14: test1

import javafx.concurrent.Worker; //導入依賴的package包/類
/**
 * Test for javafx.scene.web.WebView.getLoadTask() method. Checks that a valid Task
 * is returned by WebEngine.getLoadTask() method while WebEngine is loading page.
 */
@Test(timeout=10000)
public void test1() {
    gotException = null;
    Platform.runLater(new Runnable() {
        public void run() {
            try {
                initWebEngine(url1);
                Worker w = engine.getLoadWorker();
                Assert.assertNotNull(w);
            } catch (Exception e) {
                gotException = Boolean.TRUE;
            }
            if (gotException == null)
                gotException = Boolean.FALSE;
        }
    });
    doWait(exceptionOcurred);
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:23,代碼來源:getLoadWorkerTest.java

示例15: doWaitPageLoading

import javafx.concurrent.Worker; //導入依賴的package包/類
protected void doWaitPageLoading() {
    doWait(engineReady);
    loadWorker = engine.getLoadWorker();
    final boolean[] b = new boolean[]{false};
    while (!b[0]) {
        Platform.runLater(new Runnable() {
            public void run() {
                if ((loadWorker.getState() == Worker.State.SUCCEEDED)
                        || (loadWorker.getState() == Worker.State.FAILED)
                        || (loadWorker.getState() == Worker.State.CANCELLED)) {
                    b[0] = true;
                }
            }
        });
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
            Logger.getLogger(GenericTestClass.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
開發者ID:teamfx,項目名稱:openjfx-8u-dev-tests,代碼行數:22,代碼來源:GenericTestClass.java


注:本文中的javafx.concurrent.Worker類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。