Search in sources :

Example 36 with Engine

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);
    });
}
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 37 with Engine

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");
}
Also used : JFrame(javax.swing.JFrame) JTabbedPane(javax.swing.JTabbedPane) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 38 with Engine

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");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 39 with Engine

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();
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) BitmapImage(com.teamdev.jxbrowser.view.swt.graphics.BitmapImage) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Engine(com.teamdev.jxbrowser.engine.Engine) Display(org.eclipse.swt.widgets.Display) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 40 with Engine

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();
}
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)70 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)50 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)46 BorderLayout (java.awt.BorderLayout)8 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 SwingUtilities (javax.swing.SwingUtilities)7 WindowConstants (javax.swing.WindowConstants)7 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)6 Document (com.teamdev.jxbrowser.dom.Document)5 Frame (com.teamdev.jxbrowser.frame.Frame)5 JsObject (com.teamdev.jxbrowser.js.JsObject)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)5 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3 Bitmap (com.teamdev.jxbrowser.ui.Bitmap)3 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)3 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)3