Search in sources :

Example 1 with Document

use of com.teamdev.jxbrowser.dom.Document 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 2 with Document

use of com.teamdev.jxbrowser.dom.Document 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 3 with Document

use of com.teamdev.jxbrowser.dom.Document 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 4 with Document

use of com.teamdev.jxbrowser.dom.Document 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)

Example 5 with Document

use of com.teamdev.jxbrowser.dom.Document in project convertigo by convertigo.

the class ApplicationComponentEditor method highlightComponent.

public void highlightComponent(MobileComponent mobileComponent, boolean selectPage) {
    C8oBrowser.run(() -> {
        if (selectPage && mobileComponent instanceof UIComponent) {
            PageComponent pageComponent = ((UIComponent) mobileComponent).getPage();
            if (pageComponent != null) {
                selectPage(pageComponent.getSegment());
            }
        }
        Document doc = browser.mainFrame().get().document().get();
        MobileComponent mc = mobileComponent;
        if (mc instanceof UIUseShared) {
            UISharedComponent uisc = ((UIUseShared) mc).getTargetSharedComponent();
            if (uisc != null) {
                try {
                    mc = uisc.getUIComponentList().get(0);
                } catch (IndexOutOfBoundsException ioobe) {
                }
            }
        }
        while (doc.findElementsByClassName("class" + mc.priority).isEmpty()) {
            DatabaseObject parent = mc.getParent();
            if (parent instanceof MobileComponent) {
                mc = (MobileComponent) parent;
            } else {
                return;
            }
        }
        c8oBrowser.executeJavaScriptAndReturnValue("_c8o_highlight_class('class" + mc.priority + "');");
    });
}
Also used : UIUseShared(com.twinsoft.convertigo.beans.mobile.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.mobile.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Document(com.teamdev.jxbrowser.dom.Document) UISharedComponent(com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) MobileComponent(com.twinsoft.convertigo.beans.mobile.components.MobileComponent)

Aggregations

Document (com.teamdev.jxbrowser.dom.Document)7 Browser (com.teamdev.jxbrowser.browser.Browser)5 Engine (com.teamdev.jxbrowser.engine.Engine)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)4 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)4 BorderLayout (java.awt.BorderLayout)4 JFrame (javax.swing.JFrame)4 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)3 SwingUtilities (javax.swing.SwingUtilities)3 WindowConstants (javax.swing.WindowConstants)3 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)2 Frame (com.teamdev.jxbrowser.frame.Frame)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 OptionElement (com.teamdev.jxbrowser.dom.OptionElement)1 SelectElement (com.teamdev.jxbrowser.dom.SelectElement)1 XPathException (com.teamdev.jxbrowser.dom.XPathException)1 XPathResult (com.teamdev.jxbrowser.dom.XPathResult)1 Navigation (com.teamdev.jxbrowser.navigation.Navigation)1 MobileComponent (com.twinsoft.convertigo.beans.mobile.components.MobileComponent)1 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)1