Search in sources :

Example 1 with BrowserView

use of com.teamdev.jxbrowser.view.swt.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SamplePart method createComposite.

@PostConstruct
public void createComposite(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    Engine engine = Engine.newInstance(EngineOptions.newBuilder(RenderingMode.HARDWARE_ACCELERATED).licenseKey("your_license_key").build());
    Browser browser = engine.newBrowser();
    Text addressBar = new Text(parent, SWT.SINGLE);
    addressBar.setText("https://google.com");
    addressBar.addListener(SWT.Traverse, event -> {
        if (event.detail == SWT.TRAVERSE_RETURN) {
            browser.navigation().loadUrl(addressBar.getText());
        }
    });
    browser.navigation().loadUrl(addressBar.getText());
    GridData textGrid = new GridData();
    textGrid.horizontalAlignment = GridData.FILL;
    addressBar.setLayoutData(textGrid);
    BrowserView view = BrowserView.newInstance(parent, browser);
    view.setLayoutData(new GridData(FILL, FILL, true, true));
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) BrowserView(com.teamdev.jxbrowser.view.swt.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser) PostConstruct(javax.annotation.PostConstruct)

Example 2 with BrowserView

use of com.teamdev.jxbrowser.view.swt.BrowserView 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)

Example 3 with BrowserView

use of com.teamdev.jxbrowser.view.swt.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class DefaultOpenPopupCallback method on.

@Override
public Response on(Params params) {
    Browser browser = params.popupBrowser();
    try {
        Display display = Display.getDefault();
        display.asyncExec(() -> {
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
            BrowserView view = BrowserView.newInstance(shell, browser);
            updateBounds(shell, view, params.initialBounds());
            shell.addDisposeListener(event -> {
                if (!browser.isClosed()) {
                    asyncExec(shell, browser::close);
                }
            });
            browser.on(TitleChanged.class, event -> asyncExec(shell, () -> shell.setText(event.title())));
            browser.on(BrowserClosed.class, event -> asyncExec(shell, shell::dispose));
            browser.on(UpdateBoundsRequested.class, event -> asyncExec(shell, () -> updateBounds(shell, view, event.bounds())));
            view.setVisible(true);
            shell.pack();
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
        });
    } catch (SWTException ignore) {
        Response.proceed();
    }
    return Response.proceed();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SWTException(org.eclipse.swt.SWTException) BrowserView(com.teamdev.jxbrowser.view.swt.BrowserView) FillLayout(org.eclipse.swt.layout.FillLayout) Browser(com.teamdev.jxbrowser.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Example 4 with BrowserView

use of com.teamdev.jxbrowser.view.swt.BrowserView in project JxBrowser-Examples by TeamDev-IP.

the class SwtBrowserView method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SWT BrowserView");
    shell.setLayout(new GridLayout());
    com.teamdev.jxbrowser.view.swt.BrowserView view = BrowserView.newInstance(shell, browser);
    view.setSize(700, 500);
    shell.pack();
    shell.open();
    browser.navigation().loadUrl("https://www.google.com");
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    engine.close();
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) BrowserView(com.teamdev.jxbrowser.view.swt.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser) Display(org.eclipse.swt.widgets.Display)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)4 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)4 Engine (com.teamdev.jxbrowser.engine.Engine)3 FillLayout (org.eclipse.swt.layout.FillLayout)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 Element (com.teamdev.jxbrowser.dom.Element)1 Event (com.teamdev.jxbrowser.dom.event.Event)1 EventType (com.teamdev.jxbrowser.dom.event.EventType)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 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