Search in sources :

Example 1 with BrowserView

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

the class RedirectLoggingToFile method main.

public static void main(String[] args) {
    Path loggingDir;
    try {
        loggingDir = Files.createTempDirectory("jxbrowser-logs");
    } catch (IOException e) {
        throw new RuntimeException("Failed to create a temporary directory", e);
    }
    Path loggingFile = loggingDir.resolve("jxbrowser.log");
    System.setProperty("jxbrowser.logging.file", loggingFile.toAbsolutePath().toString());
    System.out.println("Log file path: " + loggingFile.toAbsolutePath());
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Redirect Logging To File");
        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 : Path(java.nio.file.Path) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) IOException(java.io.IOException) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 2 with BrowserView

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

the class SelectionAsHtml 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);
        JButton button = new JButton("Get Selected HTML");
        button.addActionListener(e -> browser.mainFrame().ifPresent(frame -> SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(view, frame.selectionAsHtml(), "Selected HTML", JOptionPane.PLAIN_MESSAGE))));
        JFrame frame = new JFrame("Get Selected HTML");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(button, BorderLayout.NORTH);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().loadUrl("https://www.teamdev.com/jxbrowser#features");
}
Also used : SwingUtilities(javax.swing.SwingUtilities) JButton(javax.swing.JButton) Browser(com.teamdev.jxbrowser.browser.Browser) HARDWARE_ACCELERATED(com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JOptionPane(javax.swing.JOptionPane) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) WindowConstants(javax.swing.WindowConstants) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 3 with BrowserView

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

the class SpellCheckEvents 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("Spell Check Events");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.on(SpellCheckCompleted.class, event -> event.results().forEach(checkResult -> {
        System.out.println("Error start index: " + checkResult.location());
        System.out.println("Error length: " + checkResult.length());
    }));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body>" + "<textarea autofocus rows='20' cols='30'>Smple text with mitake.</textarea>" + "</body></html>");
    });
}
Also used : SwingUtilities(javax.swing.SwingUtilities) Browser(com.teamdev.jxbrowser.browser.Browser) HARDWARE_ACCELERATED(com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED) SpellCheckCompleted(com.teamdev.jxbrowser.browser.event.SpellCheckCompleted) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) WindowConstants(javax.swing.WindowConstants) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 4 with BrowserView

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

the class SslCertificateVerifier 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("SSL Certificate Verifier");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    engine.network().set(VerifyCertificateCallback.class, params -> {
        String host = params.host().value();
        System.out.println("Verifying certificate for " + host + "...");
        // Reject SSL certificate for all "google.com" hosts.
        if (host.contains("google.com")) {
            return Response.invalid(AUTHORITY_INVALID);
        } else {
            return Response.valid();
        }
    });
    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 5 with BrowserView

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

the class DomForm 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("DOM HTML Form");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> {
        element.findElementByName("firstName").ifPresent(firstName -> firstName.putAttribute("value", "John"));
        element.findElementByName("lastName").ifPresent(lastName -> lastName.putAttribute("value", "Doe"));
    }));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body><form name=\"myForm\">" + "First name: <input type=\"text\" name=\"firstName\"/><br/>" + "Last name: <input type=\"text\" name=\"lastName\"/><br/>" + "<input type=\"button\" value=\"Save\"/>" + "</form></body></html>");
    });
}
Also used : SwingUtilities.invokeLater(javax.swing.SwingUtilities.invokeLater) FrameLoadFinished(com.teamdev.jxbrowser.navigation.event.FrameLoadFinished) Document(com.teamdev.jxbrowser.dom.Document) Browser(com.teamdev.jxbrowser.browser.Browser) HARDWARE_ACCELERATED(com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) WindowConstants(javax.swing.WindowConstants) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Document(com.teamdev.jxbrowser.dom.Document) 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