use of javafx.scene.web.WebView in project PokeGOAPI-Java by Grover-c13.
the class SolveCaptchaExample method completeCaptcha.
private static void completeCaptcha(final PokemonGo api, final String challengeURL) {
//Run this on the swing thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//Run on JFX Thread
Platform.runLater(new Runnable() {
@Override
public void run() {
JFXPanel panel = new JFXPanel();
//Create a WebView and WebEngine to display the captcha from challengeURL.
WebView view = new WebView();
WebEngine engine = view.getEngine();
//Set UserAgent so the captcha shows correctly in the WebView.
engine.setUserAgent(CaptchaSolveHelper.USER_AGENT);
engine.load(challengeURL);
final JFrame frame = new JFrame("Solve Captcha");
//Register listener to receive the token when the captcha has been solved from inside the WebView.
CaptchaSolveHelper.Listener listener = new CaptchaSolveHelper.Listener() {
@Override
public void onTokenReceived(String token) {
System.out.println("Token received: " + token + "!");
//Remove this listener as we no longer need to listen for tokens, the captcha has been solved.
CaptchaSolveHelper.removeListener(this);
try {
//Close this window, it not valid anymore.
frame.setVisible(false);
frame.dispose();
if (api.verifyChallenge(token)) {
System.out.println("Captcha was correctly solved!");
} else {
//verifyChallenge will receive a new captcha url if this one is invalid
System.out.println("Captcha was incorrectly solved! Please try again.");
}
} catch (Exception e) {
Log.e("Main", "Error while solving captcha!", e);
}
}
};
CaptchaSolveHelper.registerListener(listener);
//Applies the WebView to this panel
panel.setScene(new Scene(view));
frame.getContentPane().add(panel);
frame.setSize(500, 500);
frame.setVisible(true);
//Don't allow this window to be closed
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.out.println("Please solve the captcha before closing the window!");
}
});
}
});
}
});
}
use of javafx.scene.web.WebView in project azure-tools-for-java by Microsoft.
the class JobViewPanel method init.
private void init(final JFXPanel panel) {
String url = rootPath + "/com.microsoft.hdinsight/hdinsight/job/html/index.html";
url = url.replace("\\", "/");
final String queryString = "?projectid=" + id + "&engintype=javafx";
final String weburl = "file:///" + url + queryString;
Platform.setImplicitExit(false);
Platform.runLater(() -> {
webView = new WebView();
webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) -> {
if (newState == Worker.State.SUCCEEDED) {
JSObject win = (JSObject) webEngine.executeScript("window");
win.setMember("JobUtils", jobUtil);
}
});
panel.setScene(new Scene(webView));
if (!alreadyLoad) {
webEngine.load(weburl);
alreadyLoad = true;
}
});
}
use of javafx.scene.web.WebView in project Retrospector by NonlinearFruit.
the class Cheatsheet method start.
@Override
public void start(Stage primaryStage) {
WebView web = new WebView();
// web.getEngine().load(getClass().getResource("web/materialtable.css").toExternalForm());
String webContent = new PumpkinEater("Search Cheatsheet", new String[] { "Symbol", "Name", "Example", "Explanation" }, new String[] { ":", "and", "lord:rings", "contains 'lord' and 'rings'" }, new String[] { "|", "or", "Marvel|DC", "contains 'marvel' or 'dc'" }, new String[] { "!", "not", "!rebecca black", "contains no 'rebecca black'" }, new String[] { "`", "cmd", "[See Below]", "[See Below]" }, new String[] { "`T", "title", "`T~civil war", "title contains 'civil war'" }, new String[] { "`C", "creator", "`C=BBC", "creator equals 'bbc'" }, new String[] { "`S", "season", "`S=1", "season equals '1'" }, new String[] { "`E", "episode", "`E~13", "episode contains '13'" }, new String[] { "`A", "category", "`A~Book", "category contains 'book'" }, new String[] { "Example", "-->", "batman|superman:`A=Movie:!vs", "contains 'batman' or 'superman',<br>category equals 'movie' and<br>contains no 'vs'" }, new String[] { "Example", "-->", "sherlock:doyle:baskervilles", "contains 'sherlock',<br>contains 'doyle' and<br>contains 'baskervilles'" }).getHtml();
web.getEngine().loadContent(webContent);
StackPane root = new StackPane(web);
Scene scene = new Scene(root, 800, 600);
primaryStage.setTitle("Search Cheatsheet");
primaryStage.setScene(scene);
primaryStage.show();
}
use of javafx.scene.web.WebView in project intellij-community by JetBrains.
the class StudyBrowserWindow method initComponents.
private void initComponents() {
Platform.runLater(() -> {
myPane = new StackPane();
myWebComponent = new WebView();
myWebComponent.setOnDragDetected(event -> {
});
myEngine = myWebComponent.getEngine();
if (myShowProgress) {
myProgressBar = makeProgressBarWithListener();
myWebComponent.setVisible(false);
myPane.getChildren().addAll(myWebComponent, myProgressBar);
} else {
myPane.getChildren().add(myWebComponent);
}
if (myLinkInNewBrowser) {
initHyperlinkListener();
}
Scene scene = new Scene(myPane);
myPanel.setScene(scene);
myPanel.setVisible(true);
updateLaf(LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo);
});
add(myPanel, BorderLayout.CENTER);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
use of javafx.scene.web.WebView in project intellij-community by JetBrains.
the class IpnbJfxUtils method createHtmlPanel.
public static JComponent createHtmlPanel(@NotNull final String source, int width) {
final JFXPanel javafxPanel = new JFXPanel() {
@Override
protected void processMouseWheelEvent(MouseWheelEvent e) {
final Container parent = getParent();
final MouseEvent parentEvent = SwingUtilities.convertMouseEvent(this, e, parent);
parent.dispatchEvent(parentEvent);
}
};
javafxPanel.setBackground(IpnbEditorUtil.getBackground());
Platform.runLater(() -> {
final WebView webView = new WebView();
webView.setContextMenuEnabled(false);
webView.setOnDragDetected(event -> {
});
final WebEngine engine = webView.getEngine();
initHyperlinkListener(engine);
final boolean hasMath = source.contains("$");
if (hasMath) {
engine.setOnStatusChanged(event -> adjustHeight(webView, javafxPanel, source));
} else {
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == Worker.State.SUCCEEDED) {
adjustHeight(webView, javafxPanel, source);
}
});
}
final BorderPane pane = new BorderPane(webView);
final String prefix;
if (hasMath) {
prefix = String.format(ourMathJaxPrefix, width - 500, EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize());
} else {
prefix = String.format(ourPrefix, width - 500);
}
final String content = prefix + convertToHtml(source) + ourPostfix;
engine.loadContent(content);
final Scene scene = new Scene(pane, 0, 0);
javafxPanel.setScene(scene);
updateLaf(LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo, engine, javafxPanel);
});
return javafxPanel;
}
Aggregations