use of com.teamdev.jxbrowser.engine.Engine 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>");
});
}
use of com.teamdev.jxbrowser.engine.Engine 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");
}
use of com.teamdev.jxbrowser.engine.Engine 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.engine.Engine 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.engine.Engine 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);
});
}
Aggregations