Search in sources :

Example 1 with Observer

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);
    });
}
Also used : Element(com.teamdev.jxbrowser.dom.Element) HashMap(java.util.HashMap) ProgressListener(org.eclipse.swt.browser.ProgressListener) Event(com.teamdev.jxbrowser.dom.event.Event) Program(org.eclipse.swt.program.Program) Observer(com.teamdev.jxbrowser.event.Observer) FrameLoadFinished(com.teamdev.jxbrowser.navigation.event.FrameLoadFinished) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) Browser(com.teamdev.jxbrowser.browser.Browser) FillLayout(org.eclipse.swt.layout.FillLayout) Engine(com.teamdev.jxbrowser.engine.Engine) NetworkUtils(com.twinsoft.convertigo.engine.util.NetworkUtils) LoadFinished(com.teamdev.jxbrowser.navigation.event.LoadFinished) IOException(java.io.IOException) JsObject(com.teamdev.jxbrowser.js.JsObject) File(java.io.File) Project(com.twinsoft.convertigo.beans.core.Project) EngineOptions(com.teamdev.jxbrowser.engine.EngineOptions) Paths(java.nio.file.Paths) RenderingMode(com.teamdev.jxbrowser.engine.RenderingMode) ZoomLevel(com.teamdev.jxbrowser.zoom.ZoomLevel) EventType(com.teamdev.jxbrowser.dom.event.EventType) BrowserView(com.teamdev.jxbrowser.view.swt.BrowserView) FileUtils(com.twinsoft.convertigo.engine.util.FileUtils) Element(com.teamdev.jxbrowser.dom.Element) Event(com.teamdev.jxbrowser.dom.event.Event) FillLayout(org.eclipse.swt.layout.FillLayout) IOException(java.io.IOException)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)1 Element (com.teamdev.jxbrowser.dom.Element)1 Event (com.teamdev.jxbrowser.dom.event.Event)1 EventType (com.teamdev.jxbrowser.dom.event.EventType)1 Engine (com.teamdev.jxbrowser.engine.Engine)1 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)1 RenderingMode (com.teamdev.jxbrowser.engine.RenderingMode)1 Observer (com.teamdev.jxbrowser.event.Observer)1 JsObject (com.teamdev.jxbrowser.js.JsObject)1 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)1 LoadFinished (com.teamdev.jxbrowser.navigation.event.LoadFinished)1 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)1 ZoomLevel (com.teamdev.jxbrowser.zoom.ZoomLevel)1 Project (com.twinsoft.convertigo.beans.core.Project)1 FileUtils (com.twinsoft.convertigo.engine.util.FileUtils)1 NetworkUtils (com.twinsoft.convertigo.engine.util.NetworkUtils)1 File (java.io.File)1 IOException (java.io.IOException)1 Paths (java.nio.file.Paths)1 HashMap (java.util.HashMap)1