Search in sources :

Example 51 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class DemoApp method main.

public static void main(String[] args) {
    // Set your JxBrowser license key.
    System.setProperty("jxbrowser.license.key", "ENTER YOUR LICENSE KEY HERE");
    EngineOptions.Builder options = EngineOptions.newBuilder(HARDWARE_ACCELERATED);
    // #docfragment "enable-remote-debugging-port"
    // Enable the remote debugging port.
    options.remoteDebuggingPort(9222);
    // #enddocfragment "enable-remote-debugging-port"
    // Creating Chromium engine.
    Engine engine = Engine.newInstance(options.build());
    Browser browser = engine.newBrowser();
    // Print the web page's title once the page is loaded.
    browser.navigation().on(LoadFinished.class, event -> {
        System.out.println("Title: " + browser.title());
    });
    SwingUtilities.invokeLater(() -> {
        final BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Demo App");
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                engine.close();
            }
        });
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        browser.navigation().loadUrl("https://google.com");
    });
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) EngineOptions(com.teamdev.jxbrowser.engine.EngineOptions) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 52 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class LoggingRedirectExample method main.

public static void main(String[] args) {
    // Configure JxBrowser logging level.
    Logger.level(Level.ALL);
    // Get the JxBrowser logger.
    java.util.logging.Logger jxBrowserLogger = LogManager.getLogManager().getLogger("com.teamdev.jxbrowser");
    // Remove existing handlers attached to the JxBrowser logger.
    for (java.util.logging.Handler handler : jxBrowserLogger.getHandlers()) {
        jxBrowserLogger.removeHandler(handler);
    }
    // Add SLF4JBridgeHandler to the JxBrowser logger to route log records to the SLF4j.
    jxBrowserLogger.addHandler(new SLF4JBridgeHandler());
    // Creating and running Chromium engine.
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    browser.navigation().loadUrl("https://google.com");
    engine.close();
}
Also used : SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 53 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class DomKeyEvents method main.

public static void main(String[] args) {
    EngineOptions options = EngineOptions.newBuilder(HARDWARE_ACCELERATED).build();
    Engine engine = Engine.newInstance(options);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("DOM Keyboard Event Listener ");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    loadHtmlAndWait(browser);
    findInputField(browser).ifPresent(element -> {
        element.addEventListener(KEY_DOWN, DomKeyEvents::printEventDetails, false);
        element.addEventListener(KEY_PRESS, DomKeyEvents::printEventDetails, false);
        element.addEventListener(KEY_UP, DomKeyEvents::printEventDetails, false);
    });
}
Also used : JFrame(javax.swing.JFrame) EngineOptions(com.teamdev.jxbrowser.engine.EngineOptions) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 54 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class FileUpload method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("File Upload");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    browser.set(OpenFileCallback.class, (params, tell) -> tell.open(Paths.get("file.txt")));
    browser.mainFrame().ifPresent(mainFrame -> {
        mainFrame.loadHtml("Please specify a file, or a set of files:<br>\n" + "<input type='file' name='datafile' size='40'>");
    });
}
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 55 with Engine

use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.

the class FilterImages method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Filter Images");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    engine.network().set(BeforeUrlRequestCallback.class, params -> {
        if (params.urlRequest().resourceType() == IMAGE) {
            return BeforeUrlRequestCallback.Response.cancel();
        }
        return BeforeUrlRequestCallback.Response.proceed();
    });
    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)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