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>");
});
}
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));
}
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>");
});
}
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>");
});
}
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 + "');");
});
}
Aggregations