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));
}
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);
});
}
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();
}
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();
}
Aggregations