use of com.teamdev.jxbrowser.frame.Frame in project convertigo by convertigo.
the class ApplicationComponentEditor method createBrowser.
private void createBrowser(Composite parent) {
browserScroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
browserScroll.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
browserScroll.setExpandHorizontal(true);
browserScroll.setExpandVertical(true);
Composite canvas = new Composite(browserScroll, SWT.NONE);
browserScroll.setContent(canvas);
GridLayout gl = new GridLayout(1, false);
gl.marginBottom = gl.marginTop = gl.marginLeft = gl.marginRight = gl.marginHeight = gl.marginWidth = gl.horizontalSpacing = gl.verticalSpacing = 0;
canvas.setLayout(gl);
c8oBrowser = new C8oBrowser(canvas, SWT.NONE, applicationEditorInput.application.getProject());
browserGD = new GridData(SWT.CENTER, SWT.CENTER, true, true);
c8oBrowser.setLayoutData(browserGD);
browser = c8oBrowser.getBrowser();
debugUrl = c8oBrowser.getDebugUrl();
browserInterface = new ApplicationComponentBrowserImpl();
browser.set(InjectJsCallback.class, params -> {
String url = params.frame().browser().url();
if (baseUrl != null && url.startsWith(baseUrl)) {
try {
Frame frame = params.frame();
JsObject sessionStorage = frame.executeJavaScript("sessionStorage");
frame.executeJavaScript("sessionStorage.setItem('_c8ocafsession_storage_mode', 'session');\n" + "navigator.__defineGetter__('userAgent', function(){ return '" + deviceOS.agent() + "'});\n" + IOUtils.toString(getClass().getResourceAsStream("inject.js"), "UTF-8"));
sessionStorage.call("setItem", "_c8ocafsession_storage_mode", "session");
if (!dataset.equals("none")) {
String json = FileUtils.readFileToString(new File(datasetDir, dataset + ".json"), "UTF-8");
sessionStorage.call("setItem", "_c8ocafsession_storage_data", json);
} else {
sessionStorage.call("setItem", "_c8ocafsession_storage_data", null);
}
JsObject window = frame.executeJavaScript("window");
window.putProperty("java", browserInterface);
} catch (Exception e) {
Engine.logStudio.info("onScriptContextCreate failed for '" + url + "' with baseUrl '" + baseUrl + "': " + e.getMessage());
}
}
// browser.setZoomLevel(zoomFactor.zoomLevel());
return Response.proceed();
});
browser.set(ShowContextMenuCallback.class, (params, tell) -> {
com.teamdev.jxbrowser.ui.Point location = params.location();
highlightPoint(location.x(), location.y());
tell.close();
});
browser.engine().permissions().set(RequestPermissionCallback.class, (params, tell) -> {
tell.grant();
});
}
use of com.teamdev.jxbrowser.frame.Frame in project JxBrowser-Examples by TeamDev-IP.
the class PrintToPdf method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browser = engine.newBrowser();
browser.set(PrintCallback.class, (params, tell) -> tell.print());
browser.set(PrintHtmlCallback.class, (params, tell) -> {
PdfPrinter<PdfPrinter.HtmlSettings> pdfPrinter = params.printers().pdfPrinter();
PrintJob<HtmlSettings> printJob = pdfPrinter.printJob();
printJob.settings().pdfFilePath(Paths.get("google.pdf").toAbsolutePath()).enablePrintingBackgrounds().orientation(PORTRAIT).apply();
printJob.on(PrintCompleted.class, event -> {
if (event.isSuccess()) {
System.out.println("Printing is completed successfully.");
} else {
System.out.println("Printing has failed.");
}
});
tell.proceed(pdfPrinter);
});
browser.navigation().loadUrlAndWait("https://google.com");
browser.mainFrame().ifPresent(Frame::print);
}
Aggregations