Search in sources :

Example 36 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-QuickStart by TeamDev-IP.

the class HelloWorld method start.

@Override
public void start(Stage primaryStage) {
    // Initialize Chromium.
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    // Load the required web page.
    browser.navigation().loadUrl("https://html5test.com");
    // Create and embed JavaFX BrowserView component to display web content.
    BrowserView view = BrowserView.newInstance(browser);
    Scene scene = new Scene(new BorderPane(view), 1280, 800);
    primaryStage.setTitle("JxBrowser JavaFX");
    primaryStage.setScene(scene);
    primaryStage.show();
    // Shutdown Chromium and release allocated resources.
    primaryStage.setOnCloseRequest(event -> engine.close());
}
Also used : BorderPane(javafx.scene.layout.BorderPane) BrowserView(com.teamdev.jxbrowser.view.javafx.BrowserView) Scene(javafx.scene.Scene) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 37 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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 38 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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 39 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class DefaultOpenPopupCallback method on.

@Override
public Response on(Params params) {
    Browser browser = params.popupBrowser();
    invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                invokeLater(browser::close);
            }
        });
        updateBounds(frame, params.initialBounds());
        browser.on(TitleChanged.class, event -> invokeLater(() -> frame.setTitle(event.title())));
        browser.on(BrowserClosed.class, event -> invokeLater(() -> {
            frame.setVisible(false);
            frame.dispose();
        }));
        browser.on(UpdateBoundsRequested.class, event -> invokeLater(() -> updateBounds(frame, event.bounds())));
        frame.setVisible(true);
    });
    return Response.proceed();
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 40 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)73 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)51 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)47 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 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)5 WindowAdapter (java.awt.event.WindowAdapter)5 WindowEvent (java.awt.event.WindowEvent)5 Scene (javafx.scene.Scene)5 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3