Search in sources :

Example 86 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug326117_EmbeddedBrowser method installBrowser.

public static Browser installBrowser(Composite parent, String homeURL) {
    Browser browser = new Browser(parent, SWT.EMBEDDED);
    browser.setUrl(homeURL);
    return browser;
}
Also used : Browser(org.eclipse.swt.browser.Browser)

Example 87 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug326117_EmbeddedBrowser method main.

public static void main(String[] args) {
    final Display display = Display.getDefault();
    Frame frm = new Frame("MyBrowser");
    Canvas embedded = new Canvas();
    frm.add(embedded, BorderLayout.CENTER);
    frm.pack();
    final Shell composite = SWT_AWT.new_Shell(display, embedded);
    composite.setLayout(new FillLayout(SWT.VERTICAL));
    final Browser browser = installBrowser(composite, "http://www.baidu.com");
    frm.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
        // composite.dispose();
        // display.dispose();
        }
    });
    JTextField addr = new JTextField(80);
    addr.addActionListener(e -> display.syncExec(() -> browser.setUrl(((JTextComponent) e.getSource()).getText())));
    frm.add(addr, BorderLayout.NORTH);
    frm.setSize(800, 600);
    frm.setVisible(true);
    while (frm.isDisplayable()) if (!display.readAndDispatch())
        display.sleep();
// display.dispose();
}
Also used : Frame(java.awt.Frame) Shell(org.eclipse.swt.widgets.Shell) Canvas(java.awt.Canvas) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) JTextField(javax.swing.JTextField) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 88 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug510905_Browser_TwoJsConsoles method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(500, 600);
    shell.setLayout(new RowLayout());
    Composite leftBrowser = new Composite(shell, SWT.NONE);
    Composite rightBrowser = new Composite(shell, SWT.None);
    Button button = new Button(rightBrowser, SWT.PUSH);
    button.setText("my button");
    final Browser browser = makeBrowserWithConsole(leftBrowser, "theJavaFunction");
    new CustomFunction(browser, "theJavaFunction");
    final Browser browser2 = makeBrowserWithConsole(rightBrowser, "theJavaFunction");
    new CustomFunction(browser2, "theJavaFunction");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 89 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug525305_Browser_OpenUrl method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(500, 600);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.setText("hello <b>world!</b>");
    display.addListener(SWT.OpenUrl, e -> {
        System.out.println("OpenUrl with:" + e.text);
        browser.setUrl(e.text);
    });
    display.addListener(SWT.OpenDocument, e -> {
        System.out.println("OpenDocument with: " + e.text);
        browser.setText("OpenDocument was called with arg: " + e.text);
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 90 with Browser

use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.

the class Bug528549_browser_MouseFocusEventListeners method main.

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setSize(500, 200);
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            System.out.println("Browser Focus lost " + e.toString());
        }

        @Override
        public void focusGained(FocusEvent e) {
            System.out.println("Browser Focus gained " + e.toString());
        }
    });
    browser.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            System.out.println("Browser Mouse Up " + e.toString());
        }

        @Override
        public void mouseDown(MouseEvent e) {
            System.out.println("Browser Mouse Down " + e.toString());
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            System.out.println("Browse Mouse Double click " + e.toString());
        }
    });
    // Below listeners already worked before bug. But good to have around.
    browser.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
            System.out.println("Browser key released " + e.toString());
        }

        @Override
        public void keyPressed(KeyEvent e) {
            System.out.println("Browser key pressed " + e.toString());
        }
    });
    browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
    // Generates a lot of events...
    browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
    Button jsOnButton = new Button(shell, SWT.PUSH);
    jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    jsOnButton.setText("JS Off");
    jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
    Button jsOffButton = new Button(shell, SWT.PUSH);
    jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    jsOffButton.setText("JS On");
    jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
    Button loadNextPage = new Button(shell, SWT.PUSH);
    loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    loadNextPage.setText("Load next page");
    loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
    browser.setText(getNewText());
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FocusEvent(org.eclipse.swt.events.FocusEvent) Display(org.eclipse.swt.widgets.Display) FocusListener(org.eclipse.swt.events.FocusListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) SWT(org.eclipse.swt.SWT) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyListener(org.eclipse.swt.events.KeyListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) SelectionListener(org.eclipse.swt.events.SelectionListener) MouseEvent(org.eclipse.swt.events.MouseEvent) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Aggregations

Browser (org.eclipse.swt.browser.Browser)117 Shell (org.eclipse.swt.widgets.Shell)40 FillLayout (org.eclipse.swt.layout.FillLayout)29 Composite (org.eclipse.swt.widgets.Composite)29 Display (org.eclipse.swt.widgets.Display)29 GridData (org.eclipse.swt.layout.GridData)28 Test (org.junit.Test)26 GridLayout (org.eclipse.swt.layout.GridLayout)20 LocationEvent (org.eclipse.swt.browser.LocationEvent)18 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)18 Point (org.eclipse.swt.graphics.Point)18 IOException (java.io.IOException)16 SWTError (org.eclipse.swt.SWTError)16 BrowserFunction (org.eclipse.swt.browser.BrowserFunction)14 WindowEvent (org.eclipse.swt.browser.WindowEvent)14 Label (org.eclipse.swt.widgets.Label)14 URL (java.net.URL)13 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)13 LocationListener (org.eclipse.swt.browser.LocationListener)13 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)13