当前位置: 首页>>代码示例>>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;未经允许,请勿转载。