Search in sources :

Example 26 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class DefaultOpenPopupCallback method on.

@Override
public Response on(Params params) {
    Browser browser = params.popupBrowser();
    invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                invokeLater(browser::close);
            }
        });
        updateBounds(frame, params.initialBounds());
        browser.on(TitleChanged.class, event -> invokeLater(() -> frame.setTitle(event.title())));
        browser.on(BrowserClosed.class, event -> invokeLater(() -> {
            frame.setVisible(false);
            frame.dispose();
        }));
        browser.on(UpdateBoundsRequested.class, event -> invokeLater(() -> updateBounds(frame, event.bounds())));
        frame.setVisible(true);
    });
    return Response.proceed();
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 27 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SwingBrowserView method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Swing BrowserView");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.google.com");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 28 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class XPath method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(OFF_SCREEN);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Evaluate XPath");
        frame.getContentPane().add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    Navigation navigation = browser.navigation();
    navigation.on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> {
        try {
            XPathResult result = element.evaluate("count(//div)");
            if (result.isNumber()) {
                System.out.println("Result: " + result.asNumber());
            }
        } catch (XPathException e) {
            System.out.println(e.getMessage());
        }
    }));
    navigation.loadUrl("https://www.teamdev.com/jxbrowser");
}
Also used : XPathResult(com.teamdev.jxbrowser.dom.XPathResult) Navigation(com.teamdev.jxbrowser.navigation.Navigation) SwingUtilities(javax.swing.SwingUtilities) FrameLoadFinished(com.teamdev.jxbrowser.navigation.event.FrameLoadFinished) Document(com.teamdev.jxbrowser.dom.Document) OFF_SCREEN(com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN) Browser(com.teamdev.jxbrowser.browser.Browser) XPathException(com.teamdev.jxbrowser.dom.XPathException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Navigation(com.teamdev.jxbrowser.navigation.Navigation) JFrame(javax.swing.JFrame) XPathException(com.teamdev.jxbrowser.dom.XPathException) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) XPathResult(com.teamdev.jxbrowser.dom.XPathResult) Document(com.teamdev.jxbrowser.dom.Document) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 29 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class ZoomLevel method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Change Zoom Level");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    // Listen to the zoom changed events.
    ZoomLevels levels = engine.zoomLevels();
    levels.on(ZoomLevelChanged.class, event -> System.out.println("Url: " + event.host() + "\n" + "Zoom level: " + event.level()));
    Navigation navigation = browser.navigation();
    navigation.on(FrameLoadFinished.class, event -> {
        if (event.frame().isMain()) {
            browser.zoom().level(com.teamdev.jxbrowser.zoom.ZoomLevel.P_200);
        }
    });
    navigation.loadUrl("https://www.google.com");
}
Also used : Navigation(com.teamdev.jxbrowser.navigation.Navigation) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) ZoomLevels(com.teamdev.jxbrowser.zoom.ZoomLevels) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 30 with BrowserView

use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SslCertificateError method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).build());
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Ignore SSL Certificate Errors");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.set(CertificateErrorCallback.class, (params, tell) -> {
        System.out.println("Request URL: " + params.url() + "\n" + "Reason of the certificate error: " + params.error().getValueDescriptor() + "(" + params.error().getNumber() + ")" + "\n" + "Invalid SSL certificate.: " + params.certificate() + "\n");
        tell.allow();
    });
    // Load HTTPS website with invalid SSL certificate.
    browser.navigation().loadUrl("https://self-signed.badssl.com/");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)49 Browser (com.teamdev.jxbrowser.browser.Browser)47 JFrame (javax.swing.JFrame)47 Engine (com.teamdev.jxbrowser.engine.Engine)46 BorderLayout (java.awt.BorderLayout)8 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 SwingUtilities (javax.swing.SwingUtilities)7 WindowConstants (javax.swing.WindowConstants)7 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)5 Document (com.teamdev.jxbrowser.dom.Document)4 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3 JButton (javax.swing.JButton)3 Frame (com.teamdev.jxbrowser.frame.Frame)2 Path (java.nio.file.Path)2 Content (com.intellij.ui.content.Content)1 UnsupportedRenderingModeException (com.teamdev.jxbrowser.browser.UnsupportedRenderingModeException)1 SpellCheckCompleted (com.teamdev.jxbrowser.browser.event.SpellCheckCompleted)1