Search in sources :

Example 1 with HARDWARE_ACCELERATED

use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED 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 2 with HARDWARE_ACCELERATED

use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED 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 3 with HARDWARE_ACCELERATED

use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED 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 4 with HARDWARE_ACCELERATED

use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED in project JxBrowser-Examples by TeamDev-IP.

the class DomQuerySelector 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("DOM Query Selector");
        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.findElementsByCssSelector("p").forEach(paragraph -> System.out.println("innerHTML " + paragraph.innerHtml()))));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body><div id='root'>" + "<p>paragraph1</p>" + "<p>paragraph2</p>" + "<p>paragraph3</p>" + "</div></body></html>");
    });
}
Also used : SwingUtilities(javax.swing.SwingUtilities) 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 5 with HARDWARE_ACCELERATED

use of com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED in project JxBrowser-Examples by TeamDev-IP.

the class DomSelectOption 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("DOM Select Option");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.navigation().on(FrameLoadFinished.class, event -> browser.mainFrame().flatMap(Frame::document).flatMap(Document::documentElement).flatMap(element -> element.findElementById("select-tag")).ifPresent(selectElement -> {
        Object[] options = ((SelectElement) selectElement).options().toArray();
        ((OptionElement) options[2]).select();
        System.out.println(selectElement.innerHtml());
    }));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("<html><body><select id='select-tag'>\n" + "  <option value=\"volvo\">Volvo</option>\n" + "  <option value=\"saab\">Saab</option>\n" + "  <option value=\"opel\">Opel</option>\n" + "  <option value=\"audi\">Audi</option>\n" + "</select></body></html>");
    });
}
Also used : Document(com.teamdev.jxbrowser.dom.Document) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Frame(com.teamdev.jxbrowser.frame.Frame) SelectElement(com.teamdev.jxbrowser.dom.SelectElement) SwingUtilities(javax.swing.SwingUtilities) FrameLoadFinished(com.teamdev.jxbrowser.navigation.event.FrameLoadFinished) Browser(com.teamdev.jxbrowser.browser.Browser) OptionElement(com.teamdev.jxbrowser.dom.OptionElement) HARDWARE_ACCELERATED(com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) Engine(com.teamdev.jxbrowser.engine.Engine) WindowConstants(javax.swing.WindowConstants) SelectElement(com.teamdev.jxbrowser.dom.SelectElement) Frame(com.teamdev.jxbrowser.frame.Frame) JFrame(javax.swing.JFrame) JFrame(javax.swing.JFrame) 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)7 Engine (com.teamdev.jxbrowser.engine.Engine)7 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)7 BorderLayout (java.awt.BorderLayout)7 JFrame (javax.swing.JFrame)7 WindowConstants (javax.swing.WindowConstants)7 SwingUtilities (javax.swing.SwingUtilities)6 Document (com.teamdev.jxbrowser.dom.Document)3 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)3 SpellCheckCompleted (com.teamdev.jxbrowser.browser.event.SpellCheckCompleted)1 OptionElement (com.teamdev.jxbrowser.dom.OptionElement)1 SelectElement (com.teamdev.jxbrowser.dom.SelectElement)1 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)1 Frame (com.teamdev.jxbrowser.frame.Frame)1 HttpHeader (com.teamdev.jxbrowser.net.HttpHeader)1 HttpStatus (com.teamdev.jxbrowser.net.HttpStatus)1 Scheme (com.teamdev.jxbrowser.net.Scheme)1 UrlRequestJob (com.teamdev.jxbrowser.net.UrlRequestJob)1 InterceptUrlRequestCallback (com.teamdev.jxbrowser.net.callback.InterceptUrlRequestCallback)1