本文整理匯總了Java中javafx.concurrent.Worker.State方法的典型用法代碼示例。如果您正苦於以下問題:Java Worker.State方法的具體用法?Java Worker.State怎麽用?Java Worker.State使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.concurrent.Worker
的用法示例。
在下文中一共展示了Worker.State方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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
}
}
};
}
示例2: 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));
}
}
}
}
示例3: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (newValue.equals(Worker.State.SUCCEEDED)) {
if(webEngine.getDocument().getBaseURI().equals("about:blank")) return;
//If the page loads, let's take a snapshot of it.
WritableImage snapshot = new WritableImage((int) screenSize.getWidth(), (int) screenSize.getHeight());
browser.snapshot(null, snapshot);
BufferedImage renderedImage = SwingFXUtils.fromFXImage(snapshot, null);
//Some math to get a little better thumbnail. Starting x is at 1/4 of the totale page. Goes for a width of half of the screen size to attempt and get the 'core' of the content.
renderedImage = renderedImage.getSubimage((int)(screenSize.getWidth() /4),0,(int)( screenSize.getWidth() / 2 ),(int) screenSize.getHeight() / 2);
saveImage(padPath, fileName, renderedImage);
controller.refreshListView();
urlStage.close();
webEngine.load(null);
}
else if(newValue.equals(Worker.State.FAILED)){
//TODO: Send an error message somehow.
urlStage.close();
}
}
示例4: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
if (newState == Worker.State.SUCCEEDED) {
Document document = configuration.createDocument(engine);
configuration.onLoad(document);
Window window = configuration.createWindow(document);
DocumentLoadEvent event = new DocumentLoadEvent(window);
documentListener.onLoad(event);
if (configuration.getConfiguration().getInterceptor() != null && handler != null) {
URLConnection connection = handler.getConnection();
if (handler.getConnection() != null) {
Map<String, List<String>> headers = connection.getHeaderFields();
Response response = new Response(window.getLocation(), Collections.unmodifiableMap(new HashMap<>(headers)));
configuration.getConfiguration().getInterceptor().afterLoad(response);
}
}
}
}
示例5: loadSections
import javafx.concurrent.Worker; //導入方法依賴的package包/類
private void loadSections(Runnable nextCall) {
logger.info("Loading " + bounds.toString());
boolean includeTitle = (bounds.lowerSection == 0 && bounds.lowerOption == 0);
String source = project.getTemplate().render(project, includeTitle, bounds, ImageType.REFERENCE);
WebEngine engine = browser.getEngine();
engine.loadContent(source);
if (listener != null) {
engine.getLoadWorker().stateProperty().removeListener(listener);
}
listener = new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue,
Worker.State newValue) {
if (newValue != Worker.State.SUCCEEDED)
return;
try {
engine.executeScript("document.body.style.overflow = 'hidden'");
String heightText = engine
.executeScript("window.getComputedStyle(document.body).getPropertyValue('height')")
.toString();
height = Double.valueOf(heightText.replace("px", ""));
browser.setMinWidth(1280);
browser.setMaxWidth(browser.getMinWidth());
nextCall.run();
} catch (Exception e) {
logger.error("Error while setting up screenshot browser", e);
stage.close();
callback.accept("Error while taking screenshot");
}
}
};
engine.getLoadWorker().stateProperty().addListener(listener);
}
示例6: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
switch (newState) {
case SUCCEEDED:
setState(State.MAIN);
break;
case SCHEDULED:
setState(State.LOADING);
break;
}
}
示例7: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (newValue == Worker.State.SUCCEEDED) {
String sessionId = fetchSessionId();
if (sessionId != null) {
setSessionId(sessionId);
}
}
}
示例8: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (SUCCEEDED.equals(newValue)) {
Document document = webView.getEngine().getDocument();
NodeList anchors = document.getElementsByTagName(ANCHOR_TAG);
for (int i = 0; i < anchors.getLength(); i++) {
Node node = anchors.item(i);
EventTarget eventTarget = (EventTarget) node;
eventTarget.addEventListener(CLICK_EVENT, this, false);
}
}
}
示例9: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (!firstPageLoaded) {
firstPageLoaded = true;
return;
}
doAction(observable, oldValue, newValue);
}
示例10: doAction
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@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);
}
}
示例11: HandleWebTitleChange
import javafx.concurrent.Worker; //導入方法依賴的package包/類
private static void HandleWebTitleChange(WebEngine webEngine, JFrame frame, Worker.State newState, SyncState state )
{
if (newState == Worker.State.SUCCEEDED) {
log.info("Page refreshed: " + webEngine.getTitle());
frame.setTitle(webEngine.getTitle());
if( webEngine.getTitle().startsWith( SUCCESS_CODE ) ) {
synchronized ( lock ) {
token = webEngine.getTitle().substring( SUCCESS_CODE.length() );
state.setStatus( "Login successful.");
lock.notify();
}
log.info("Hiding login panel.");
frame.setVisible( false );
}
}
else if( newState == Worker.State.FAILED ) {
log.error("Error loading Google Auth Page!");
state.setStatus( "Unable to load Google Authentication page.");
state.cancel( true );
frame.setVisible(false);
}
}
示例12: changed
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public void changed(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) {
if (newState == Worker.State.SUCCEEDED) {
DocumentLoadEvent event = new DocumentLoadEvent(window);
listener.onLoad(event);
}
}
示例13: stateListener
import javafx.concurrent.Worker; //導入方法依賴的package包/類
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");
}
}
示例14: addChangeListener
import javafx.concurrent.Worker; //導入方法依賴的package包/類
public void addChangeListener(ChangeListener<Worker.State> changeListener) {
Platform.runLater(() -> webView.getEngine().getLoadWorker().stateProperty().addListener(changeListener));
}
示例15: stateProperty
import javafx.concurrent.Worker; //導入方法依賴的package包/類
@Override
public ObjectProperty<Worker.State> stateProperty()
{
return state;
}