Search in sources :

Example 6 with WebView

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!");
                        }
                    });
                }
            });
        }
    });
}
Also used : CaptchaSolveHelper(com.pokegoapi.util.CaptchaSolveHelper) JFXPanel(javafx.embed.swing.JFXPanel) LoginListener(com.pokegoapi.api.listener.LoginListener) WindowAdapter(java.awt.event.WindowAdapter) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WebView(javafx.scene.web.WebView)

Example 7 with WebView

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;
        }
    });
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) JSObject(netscape.javascript.JSObject) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene)

Example 8 with WebView

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();
}
Also used : PumpkinEater(retrospector.util.PumpkinEater) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 9 with WebView

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);
}
Also used : DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 10 with WebView

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;
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) BorderPane(javafx.scene.layout.BorderPane) MouseEvent(java.awt.event.MouseEvent) MouseWheelEvent(java.awt.event.MouseWheelEvent) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine)

Aggregations

WebView (javafx.scene.web.WebView)19 Scene (javafx.scene.Scene)13 WebEngine (javafx.scene.web.WebEngine)8 ObservableValue (javafx.beans.value.ObservableValue)4 BorderPane (javafx.scene.layout.BorderPane)4 StackPane (javafx.scene.layout.StackPane)4 DarculaLookAndFeelInfo (com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo)3 State (javafx.concurrent.Worker.State)3 JFXPanel (javafx.embed.swing.JFXPanel)3 Button (javafx.scene.control.Button)3 VBox (javafx.scene.layout.VBox)3 URL (java.net.URL)2 ChangeListener (javafx.beans.value.ChangeListener)2 FXML (javafx.fxml.FXML)2 Group (javafx.scene.Group)2 Label (javafx.scene.control.Label)2 ScrollPane (javafx.scene.control.ScrollPane)2 PopupFeatures (javafx.scene.web.PopupFeatures)2 WebEvent (javafx.scene.web.WebEvent)2 JSObject (netscape.javascript.JSObject)2