use of com.teamdev.jxbrowser.ui.Point 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.ui.Point in project JxBrowser-Examples by TeamDev-IP.
the class DomMouseEvents method printEventDetails.
private static void printEventDetails(Event event) {
MouseEvent mouseEvent = (MouseEvent) event;
Point location = mouseEvent.pageLocation();
String message = format("Event type: %s. Button: %s. Page location: (%d, %d)", mouseEvent.type().value(), mouseEvent.button(), location.x(), location.y());
System.out.println(message);
}
Aggregations