use of com.teamdev.jxbrowser.engine.Engine 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.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class BrowserViewInJTabbedPane method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(OFF_SCREEN);
Browser browserOne = engine.newBrowser();
Browser browserTwo = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
JTabbedPane pane = new JTabbedPane();
pane.addTab("Google", BrowserView.newInstance(browserOne));
pane.addTab("TeamDev", BrowserView.newInstance(browserTwo));
JFrame frame = new JFrame("Browser View In JTabbed Pane");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(pane, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browserOne.navigation().loadUrl("https://www.google.com");
browserTwo.navigation().loadUrl("https://www.teamdev.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class SwingBrowserView method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Swing BrowserView");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class BitmapToSwtImage method main.
public static void main(String[] args) {
Display display = new Display();
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
// Resize browser to the required dimension
browser.resize(1024, 768);
// Load the required web page and wait until it is loaded completely
browser.navigation().loadUrlAndWait("https://www.google.com");
Bitmap bitmap = browser.bitmap();
// Convert the bitmap to org.eclipse.swt.graphics.Image
Image image = BitmapImage.toToolkit(display, bitmap);
// Save the image to a PNG file
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save("bitmap.png", SWT.IMAGE_PNG);
}
display.dispose();
}
use of com.teamdev.jxbrowser.engine.Engine 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