use of com.teamdev.jxbrowser.event.Observer in project convertigo by convertigo.
the class C8oBrowser method init.
private void init(Engine browserContext) {
setLayout(new FillLayout());
browserView = BrowserView.newInstance(this, browserContext.newBrowser());
threadSwt = getDisplay().getThread();
Observer<Event> observer = ev -> {
if (!useExternalBrowser) {
return;
}
try {
Element elt = (Element) ev.target().get();
if (!elt.nodeName().equalsIgnoreCase("a")) {
return;
}
String href = elt.attributes().get("href");
if (!href.startsWith("http")) {
String url = elt.document().baseUri();
if (href.startsWith("/")) {
href = url.replaceFirst("(https?://.*?)/.*", "$1" + href);
} else {
href = url.replaceFirst("(https?://.*/).*", "$1" + href);
}
}
if (href.matches("https?://.*")) {
com.twinsoft.convertigo.engine.Engine.logStudio.info("Internal browser open link with the default browser: " + href);
Program.launch(href);
ev.preventDefault();
}
} catch (Exception e) {
}
};
getBrowser().mainFrame().get().document().get().addEventListener(EventType.CLICK, observer, false);
getBrowser().navigation().on(FrameLoadFinished.class, event -> {
event.frame().document().get().addEventListener(EventType.CLICK, observer, false);
});
}
Aggregations