Search in sources :

Example 6 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class SpellCheckSuggestions method main.

public static void main(String[] args) {
    // Enable heavyweight popup menu for the heavyweight
    // (default) BrowserView component. Otherwise – the popup
    // menu will be displayed under the BrowserView component.
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Spell Check Suggestions");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.set(ShowContextMenuCallback.class, (params, tell) -> {
        JPopupMenu popupMenu = new JPopupMenu();
        popupMenu.addPopupMenuListener(myPopupMenuListener(tell));
        // Add the suggestions menu items.
        SpellCheckMenu spellCheckMenu = params.spellCheckMenu();
        List<String> suggestions = spellCheckMenu.dictionarySuggestions();
        suggestions.forEach(suggestion -> {
            JMenuItem menuItem = new JMenuItem(suggestion);
            menuItem.addActionListener(e -> {
                browser.replaceMisspelledWord(suggestion);
                tell.close();
            });
            popupMenu.add(menuItem);
        });
        // Add menu separator if necessary.
        if (!suggestions.isEmpty()) {
            popupMenu.addSeparator();
        }
        // Add the "Add to Dictionary" menu item.
        JMenuItem addToDictionary = new JMenuItem(spellCheckMenu.addToDictionaryMenuItemText());
        addToDictionary.addActionListener(e -> {
            Dictionary dictionary = engine.spellChecker().customDictionary();
            dictionary.add(spellCheckMenu.misspelledWord());
            tell.close();
        });
        popupMenu.add(addToDictionary);
        // Display context menu at specified location.
        Point location = params.location();
        popupMenu.show(view, location.x(), location.y());
    });
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body><textarea rows='20' cols='30'>" + "Smple text with mitake.</textarea></body></html>");
    });
}
Also used : Dictionary(com.teamdev.jxbrowser.spellcheck.Dictionary) JFrame(javax.swing.JFrame) SpellCheckMenu(com.teamdev.jxbrowser.menu.SpellCheckMenu) Point(com.teamdev.jxbrowser.ui.Point) JMenuItem(javax.swing.JMenuItem) Engine(com.teamdev.jxbrowser.engine.Engine) JPopupMenu(javax.swing.JPopupMenu) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 7 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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 8 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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)

Example 9 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class DomGetAttributes method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(OFF_SCREEN);
    Browser browser = engine.newBrowser();
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body><a href='#' id='link' title='link title'>Link</a></body></html>");
    });
    browser.mainFrame().flatMap(Frame::document).flatMap(Document::documentElement).flatMap(element -> element.findElementById("link")).ifPresent(linkElement -> linkElement.attributes().forEach(DomGetAttributes::print));
}
Also used : Document(com.teamdev.jxbrowser.dom.Document) OFF_SCREEN(com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN) Browser(com.teamdev.jxbrowser.browser.Browser) Engine(com.teamdev.jxbrowser.engine.Engine) Frame(com.teamdev.jxbrowser.frame.Frame) Document(com.teamdev.jxbrowser.dom.Document) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 10 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class DomMouseEvents method main.

public static void main(String[] args) {
    EngineOptions options = EngineOptions.newBuilder(HARDWARE_ACCELERATED).build();
    Engine engine = Engine.newInstance(options);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("DOM Mouse Event Listener");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    loadHtmlAndWait(browser);
    findButton(browser).ifPresent(element -> {
        element.addEventListener(MOUSE_DOWN, DomMouseEvents::printEventDetails, false);
        element.addEventListener(MOUSE_UP, DomMouseEvents::printEventDetails, false);
        element.addEventListener(MOUSE_OVER, DomMouseEvents::printEventDetails, false);
    });
}
Also used : JFrame(javax.swing.JFrame) EngineOptions(com.teamdev.jxbrowser.engine.EngineOptions) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)73 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)51 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)47 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)6 Document (com.teamdev.jxbrowser.dom.Document)5 Frame (com.teamdev.jxbrowser.frame.Frame)5 JsObject (com.teamdev.jxbrowser.js.JsObject)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)5 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)5 WindowAdapter (java.awt.event.WindowAdapter)5 WindowEvent (java.awt.event.WindowEvent)5 Scene (javafx.scene.Scene)5 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3