Search in sources :

Example 1 with WebEngine

use of javafx.scene.web.WebEngine in project azure-tools-for-java by Microsoft.

the class JobViewFxUtil method startFx.

public static Object startFx(Object composite, final String webUrl, Object jobUtils) {
    try {
        Class compositeClass = Class.forName("org.eclipse.swt.widgets.Composite");
        Class[] paramTypes = { compositeClass, int.class };
        Constructor con = FXCanvas.class.getConstructor(paramTypes);
        Object[] parames = { composite, 1 << 16 };
        final FXCanvas canvas = (FXCanvas) con.newInstance(parames);
        Platform.setImplicitExit(false);
        Platform.runLater(new Runnable() {

            @Override
            public void run() {
                final WebView webView = new WebView();
                Scene scene = new Scene(webView);
                canvas.setScene(scene);
                WebEngine webEngine = webView.getEngine();
                webEngine.load(webUrl);
                webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {

                    @Override
                    public void changed(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", new JobUtilsForEclipse());
                        }
                    }
                });
            }
        });
        return canvas;
    } catch (Exception e) {
        return e;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) ObservableValue(javafx.beans.value.ObservableValue) JSObject(netscape.javascript.JSObject) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Worker(javafx.concurrent.Worker) JSObject(netscape.javascript.JSObject) ChangeListener(javafx.beans.value.ChangeListener) FXCanvas(javafx.embed.swt.FXCanvas) WebView(javafx.scene.web.WebView)

Example 2 with WebEngine

use of javafx.scene.web.WebEngine in project Gargoyle by callakrsos.

the class WebViewExam method start.

/***********************************************************************************/
/* 이벤트 구현 */
@Override
public void start(Stage primaryStage) throws Exception {
    WebView view = new WebView();
    WebEngine engine = view.getEngine();
    engine.setJavaScriptEnabled(true);
    engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {

        @Override
        public WebEngine call(PopupFeatures p) {
            Stage stage = new Stage(StageStyle.UTILITY);
            WebView wv2 = new WebView();
            VBox vBox = new VBox(5);
            vBox.getChildren().add(wv2);
            vBox.getChildren().add(new Button("업로딩"));
            wv2.getEngine().setJavaScriptEnabled(true);
            stage.setScene(new Scene(vBox));
            stage.show();
            return wv2.getEngine();
        }
    });
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == Worker.State.SUCCEEDED) {
                primaryStage.setTitle(engine.getLocation());
            }
        }
    });
    engine.setConfirmHandler(new Callback<String, Boolean>() {

        @Override
        public Boolean call(String param) {
            System.out.println("confirm handler : " + param);
            return true;
        }
    });
    engine.setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });
    engine.load("http://localhost:15501/MemoWebapp/SmartEditor2.html");
    primaryStage.setScene(new Scene(new BorderPane(view), 1200, 700));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) PopupFeatures(javafx.scene.web.PopupFeatures) ObservableValue(javafx.beans.value.ObservableValue) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Button(javafx.scene.control.Button) State(javafx.concurrent.Worker.State) Stage(javafx.stage.Stage) WebView(javafx.scene.web.WebView) WebEvent(javafx.scene.web.WebEvent) VBox(javafx.scene.layout.VBox)

Example 3 with WebEngine

use of javafx.scene.web.WebEngine in project Gargoyle by callakrsos.

the class WebViewConsole method exec.

private void exec() {
    try {
        WebEngine engine = wb.getEngine();
        Object obj = engine.executeScript(txtCommand.getText());
        //			 JSObject obj = (JSObject)
        if (obj instanceof String) {
            txtResult.appendText(obj.toString());
        } else if (obj instanceof HTMLDocument) {
            txtResult.appendText(toHtmlElement((HTMLDocument) obj));
        } else if (obj instanceof Node) {
            Node n = (Node) obj;
            txtResult.appendText(toNodeInfo(n));
        } else {
            txtResult.appendText(obj.toString());
        }
        txtResult.appendText("\n");
    } catch (NullPointerException e) {
        txtResult.appendText("undefinded");
        txtResult.appendText("\n");
    } catch (Exception e) {
        txtResult.appendText(e.getMessage());
        txtResult.appendText("\n");
    }
}
Also used : HTMLDocument(org.w3c.dom.html.HTMLDocument) Node(org.w3c.dom.Node) WebEngine(javafx.scene.web.WebEngine)

Example 4 with WebEngine

use of javafx.scene.web.WebEngine 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 5 with WebEngine

use of javafx.scene.web.WebEngine in project intellij-community by JetBrains.

the class IpnbJfxUtils method adjustHeight.

private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source) {
    final WebEngine engine = webView.getEngine();
    final Document document = engine.getDocument();
    if (document != null) {
        final Element mydiv = document.getElementById("mydiv");
        if (mydiv != null) {
            final WebPage webPage = Accessor.getPageFor(engine);
            final WCSize wcsize = webPage.getContentSize(webPage.getMainFrame());
            final int height = wcsize.getIntHeight();
            int width = wcsize.getIntWidth();
            if (width < javafxPanel.getWidth())
                width = javafxPanel.getWidth();
            if (height <= 0 || width <= 0)
                return;
            webView.setPrefWidth(wcsize.getWidth());
            webView.setMinWidth(wcsize.getWidth());
            int count = 1;
            if (source.contains("```")) {
                count += 1;
            }
            boolean inMath = false;
            if (source.contains("\\frac")) {
                count += 1;
            }
            while (source.contains("$$")) {
                if (inMath) {
                    final String substring = source.substring(0, source.indexOf("$$") + 2);
                    count += StringUtil.countNewLines(substring);
                    for (int i = 0, len = substring.length(); i < len; ++i) {
                        if (substring.charAt(i) == '\\' && i + 1 < substring.length() && substring.charAt(i + 1) == '\\') {
                            count++;
                            i += 1;
                        }
                    }
                }
                inMath = !inMath;
                source = source.substring(source.indexOf("$$") + 2);
            }
            int finalHeight = height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
            int finalWidth = width;
            UIUtil.invokeLaterIfNeeded(() -> {
                final Dimension size = new Dimension(finalWidth, finalHeight);
                javafxPanel.setPreferredSize(size);
                javafxPanel.setMinimumSize(size);
                javafxPanel.revalidate();
            });
        }
    }
}
Also used : WCSize(com.sun.webkit.graphics.WCSize) WebPage(com.sun.webkit.WebPage) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) WebEngine(javafx.scene.web.WebEngine)

Aggregations

WebEngine (javafx.scene.web.WebEngine)9 Scene (javafx.scene.Scene)7 WebView (javafx.scene.web.WebView)7 BorderPane (javafx.scene.layout.BorderPane)4 ObservableValue (javafx.beans.value.ObservableValue)2 State (javafx.concurrent.Worker.State)2 JFXPanel (javafx.embed.swing.JFXPanel)2 Button (javafx.scene.control.Button)2 VBox (javafx.scene.layout.VBox)2 PopupFeatures (javafx.scene.web.PopupFeatures)2 WebEvent (javafx.scene.web.WebEvent)2 DarculaLookAndFeelInfo (com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo)1 WebViewConsole (com.kyj.fx.voeditor.visual.component.console.WebViewConsole)1 LoginListener (com.pokegoapi.api.listener.LoginListener)1 CaptchaSolveHelper (com.pokegoapi.util.CaptchaSolveHelper)1 WebPage (com.sun.webkit.WebPage)1 WCSize (com.sun.webkit.graphics.WCSize)1 MouseEvent (java.awt.event.MouseEvent)1 MouseWheelEvent (java.awt.event.MouseWheelEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1