本文整理汇总了Java中javafx.concurrent.Worker.State类的典型用法代码示例。如果您正苦于以下问题:Java State类的具体用法?Java State怎么用?Java State使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
State类属于javafx.concurrent.Worker包,在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IWURLField
import javafx.concurrent.Worker.State; //导入依赖的package包/类
public IWURLField(WebView webView, boolean secured, Tab tab) {
this.webView = webView;
this.tab = tab;
this.securedHTTP = secured;
setText(IWPropertyHelper.getProperty("default_homepage"));
webView.getEngine().getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue == State.SUCCEEDED) {
tab.setText(webView.getEngine().getTitle());
}
if (newValue == State.FAILED) {
if(getText().toString().equals("")) {
webView.getEngine().loadContent("<html><title>Empty Tab</title><body></body></html>");
} else {
webView.getEngine().loadContent("<html><title>Oops!</title><body><b>Page not found!</b></body></html>");
}
}
}
});
}
示例2: changed
import javafx.concurrent.Worker.State; //导入依赖的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);
}
}
}
示例3: initComponent
import javafx.concurrent.Worker.State; //导入依赖的package包/类
private void initComponent() {
webView = new WebView();
String externalForm = ACEEditor.class.getResource("/Ace.html").toExternalForm();
WebEngine engine = webView.getEngine();
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
if (newValue != State.SUCCEEDED) {
return;
}
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("java", ACEEditor.this);
engine.executeScript("console.log = function(message)\n" + "{\n" + " java.log(message);\n" + "};");
ACEEditor.this.engine = engine;
setOptions(new JSONObject().put("showLineNumbers", showLinenumbers).put("firstLineNumber", startLineNumber)
.put("overwrite", false));
loadPreferences();
hookKeyBindings();
}
});
engine.load(externalForm);
ToolBarContainer container = ToolBarContainer.createDefaultContainer(Orientation.RIGHT);
if (withToolbar) {
ToolBarPanel toolBarPanel = container.getToolBarPanel();
createToolBars(toolBarPanel);
}
container.setContent(webView);
this.node = container;
}
示例4: UARTPanel
import javafx.concurrent.Worker.State; //导入依赖的package包/类
public UARTPanel()
{
WebView view = new WebView();
view.setContextMenuEnabled(false);
webEngine = view.getEngine();
messageQueue = new LinkedList<>();
valueDisplayOptions = new LinkedHashMap<>();
populateDisplayOptions();
ObservableValue<State> property = webEngine.getLoadWorker().stateProperty();
OnLoadListener.register(this::onLoad, property);
String content = "<html><head></head><body " + styleString() + "></body></html>";
webEngine.loadContent(content);
HBox controlPane = createControlPane();
this.setCenter(view);
this.setBottom(controlPane);
}
示例5: ConsolePane
import javafx.concurrent.Worker.State; //导入依赖的package包/类
public ConsolePane()
{
WebView view = new WebView();
view.setContextMenuEnabled(false);
webEngine = view.getEngine();
messageQueue = new LinkedList<>();
ObservableValue<State> property = webEngine.getLoadWorker().stateProperty();
OnLoadListener.register(this::onLoad, property);
String content = "<html><head></head><body></body></html>";
webEngine.loadContent(content);
ConsolePaneEventHandler eventHandler = new ConsolePaneEventHandler();
EventRegistry.getGlobalRegistry().register(eventHandler);
this.setCenter(view);
}
示例6: printURL
import javafx.concurrent.Worker.State; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void printURL(String url)
{
Platform.runLater(new Runnable() {
@Override public void run() {
try {
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.getLoadWorker().stateProperty().addListener((ChangeListener) (obsValue, oldState, newState) -> {
if (newState == State.SUCCEEDED) {
Document doc = engine.getDocument();
// don't know why, but this was necessary to get the font-size smaller for results, prints fine under Chrome but not WebView
Element extrastyle = doc.createElement("style");
extrastyle.appendChild(doc.createTextNode(".container-fluid { font-size: 0.65rem !important; } table td span { white-space: nowrap; }"));
doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(extrastyle);
PrinterJob job = PrinterJob.createPrinterJob();
if (job == null) {
log.warning("Unable to create a print job. Opening in a browser instead.");
openURL(url);
return;
}
if (job.showPrintDialog(null)) {
engine.print(job);
job.endJob();
}
}
});
engine.load(url);
} catch (Exception e) {
log.log(Level.SEVERE, "\bCould not print:" + e, e);
}
}
});
}
示例7: reload
import javafx.concurrent.Worker.State; //导入依赖的package包/类
/**
*
* JFXMasonryPane의 버그때문에 reload의 경우 - 새로 JFXMasonryPane을 만드는 작업을 처리함.
*
* @작성자 : KYJ
* @작성일 : 2016. 11. 21.
*/
protected void reload() {
if (service.isRunning()) {
return;
}
if (gargoyleThreadExecutors.isShutdown() || gargoyleThreadExecutors.isTerminated()) {
service.setExecutor(gargoyleThreadExecutors);
}
if (State.SUCCEEDED == service.getState()) {
service.restart();
} else {
service.start();
}
}
示例8: registerFunction
import javafx.concurrent.Worker.State; //导入依赖的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 );
}
}
}
);
}
} );
}
示例9: removeItem
import javafx.concurrent.Worker.State; //导入依赖的package包/类
private void removeItem(ZooKeeper zk, TreeView<ZNodeFX> treeView, TreeItem<ZNodeFX> item) {
TreeItem<ZNodeFX> parent = item.getParent();
if(parent!=null){
final ZKRemover remover = new ZKRemover(zk, item.getValue());
serviceWorker.bind(remover);
remover.stateProperty().addListener((ChangeListener<State>) (observable, oldValue, newValue) -> {
switch (newValue) {
case SUCCEEDED:
if(remover.getValue()){
parent.getChildren().remove(item);
}
break;
case FAILED:
Dialogs.showError("Error removing item " + item.getValue().getName(), "It is forbidden to remove the root item");
default:
break;
}
});
remover.start();
}else{
Dialogs.showError("Error removing item " + item.getValue().getName(), "It is forbidden to remove the root item");
}
}
示例10: connectToZK
import javafx.concurrent.Worker.State; //导入依赖的package包/类
private void connectToZK(final String conn) {
final ZKConnector connector = new ZKConnector(conn);
progress.progressProperty().bind(connector.progressProperty());
progress.visibleProperty().bind(connector.runningProperty());
connector.stateProperty().addListener((ChangeListener<State>) (observable, oldValue, newValue) -> {
switch (newValue) {
case FAILED:
Dialogs.showError("Wrong ZooKeeper connection", conn);
break;
case SUCCEEDED:
createTab(connector.getValue());
ZFXConf.getInstance().addSuccessfulConnection(connector.getValue());
break;
default:
break;
}
});
connector.start();
}
示例11: FXCanvasBrowserApp
import javafx.concurrent.Worker.State; //导入依赖的package包/类
protected FXCanvasBrowserApp() {
shell = new Shell();
shell.setText(this.getClass().getSimpleName());
shell.setLayout(new FillLayout());
FXCanvas fxCanvas = new FXCanvas(shell, SWT.BORDER);
browser = new WebView();
browser.getEngine().getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
successLabel.setText(SUCCESS_MESSAGE);
}
}
});
fxCanvas.setScene(createScene());
shell.pack();
Monitor monitor = shell.getMonitor();
Rectangle monitorRect = monitor.getClientArea();
Rectangle shellRect = shell.getBounds();
shellRect.x = Math.max(0, (monitorRect.width - shellRect.width) / 2);
shellRect.y = Math.max(0, (monitorRect.height - shellRect.height) / 2);
shell.setBounds(shellRect);
shell.open();
}
示例12: start
import javafx.concurrent.Worker.State; //导入依赖的package包/类
@Override
public void start(Stage stage) {
view = new WebView();
web = view.getEngine();
web.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
public void changed(ObservableValue<? extends State> ov, State t, State t1) {
if (t1.equals(Worker.State.SUCCEEDED)) {
currIndex.setText("Current index: " + web.getHistory().getCurrentIndex());
currHistorySize.setText("Current number of entries: " + web.getHistory().getEntries().size());
}
}
});
String url = getParameters().getRaw().get(0);
if (url != null)
web.load(url);
stage.setTitle("Launcher");
stage.setScene(new Scene(createContainer(), 800, 600));
stage.sizeToScene();
stage.show();
}
示例13: createWebView
import javafx.concurrent.Worker.State; //导入依赖的package包/类
WebView createWebView(String url) {
System.out.println("URL to load: " + url);
WebView view = new WebView();
web = view.getEngine();
web.getLoadWorker().stateProperty().addListener (
new ChangeListener <State>() {
@Override
public void changed (ObservableValue ov, State oldState, State newState) {
System.out.println ("WebEngine's state changed from " + oldState.toString() + " to " + newState.toString());
System.out.println("Location: " + web.getLocation());
if (web.getLoadWorker().getException() != null) {
System.out.println("Exception message: " + web.getLoadWorker().getException().getMessage());
}
}
});
web.load(url);
return view;
}
示例14: initialize
import javafx.concurrent.Worker.State; //导入依赖的package包/类
public final void initialize(Stage s) {
this.stage = s;
WebEngine engine = this.webBrowser.getEngine();
String userAgent = engine.getUserAgent();
engine.setUserAgent(userAgent.substring(0, userAgent.indexOf(')')) + "; rv:56.0) Gecko/20100101 Firefox/56.0");
engine.setJavaScriptEnabled(true);
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.equals(State.SUCCEEDED)) {
String location = engine.getLocation();
if (!location.contains("sh.st") && !location.contains("adf.ly") && !location.contains("krothium.com") && !location.contains("about:blank")) {
this.webBrowser.getEngine().load("about:blank");
}
if (location.contains("about:blank") && !this.toHide.isShowing()) {
this.toHide.show();
s.close();
}
}
});
}
示例15: ProgressDialog
import javafx.concurrent.Worker.State; //导入依赖的package包/类
public ProgressDialog(final Worker<?> worker)
{
if (worker == null) return;
if (worker.getState() == State.CANCELLED || worker.getState() == State.FAILED || worker.getState() == State.SUCCEEDED)
{
return;
}
this.worker = worker;
setResultConverter(dialogButton -> null);
setTitle("Progress");
getDialogPane().setHeaderText("Operation in Progress");
initModality(Modality.APPLICATION_MODAL);
createControls();
createLayout();
bindEvents();
}