Search in sources :

Example 61 with Browser

use of org.eclipse.swt.browser.Browser in project yyl_example by Relucent.

the class BrowserTest method main.

public static void main(String[] args) {
    Display display = Display.getDefault();
    Shell shell = new Shell();
    shell.setLayout(new FillLayout());
    Composite compCen = new Composite(shell, SWT.NONE);
    compCen.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    compCen.setLayout(new FillLayout());
    {
        Browser browser = new Browser(compCen, SWT.NONE);
        // 显示浏览器首页
        browser.setUrl("http://www.baidu.com/");
    // ScrolledComposite scrolledComposite = new ScrolledComposite(compCen, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    // scrolledComposite.setExpandHorizontal(true);
    // scrolledComposite.setExpandVertical(true);
    // scrolledComposite.setContent(widGraphPanel);
    }
    shell.layout();
    shell.open();
    // 如果当前窗口未被销毁
    while (!shell.isDisposed()) {
        // display要一直监听窗体事件,没有窗体事件发生时
        if (!display.readAndDispatch()) {
            // 显示对象处于休眠状态
            display.sleep();
        }
    }
    // 销毁当前对象
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser)

Example 62 with Browser

use of org.eclipse.swt.browser.Browser in project hale by halestudio.

the class BrowserTip method showToolTip.

/**
 * Show the tool tip
 *
 * @param control the tip control
 * @param posx the x-position
 * @param posy the y-position
 * @param toolTip the tool tip string
 * @param addBounds additional bounds that will be treated as if in the
 *            tooltip (the tooltip won't hide if the cursor is inside these
 *            bounds), may be <code>null</code>
 * @param addBoundsControl the control the addBounds coordinates are
 *            relative to, <code>null</code> if addBounds is in display
 *            coordinates or no addBounds is provided
 *
 * @return the tool shell
 */
public Shell showToolTip(Control control, int posx, int posy, String toolTip, final Rectangle addBounds, final Control addBoundsControl) {
    final Shell toolShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
    FillLayout layout = new FillLayout();
    toolShell.setLayout(layout);
    try {
        if (plainText) {
            Text text = new Text(toolShell, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
            text.setFont(control.getDisplay().getSystemFont());
            text.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            text.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            text.setText(toolTip);
        } else {
            Browser browser = new Browser(toolShell, SWT.NONE);
            browser.setFont(control.getDisplay().getSystemFont());
            browser.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            browser.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            browser.setText(toolTip);
        }
        Point pt = control.toDisplay(posx, posy);
        Rectangle bounds = control.getDisplay().getBounds();
        Point size = toolShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        int width = Math.min(toolTipWidth, size.x);
        /*
			 * On Windows XP (not on 7) computeSize seems to result in a size
			 * where the whole text is pressed into one line. We try to fix this
			 * by using the... "widthFactor"! (only for small computed heights)
			 */
        int widthFactor = (size.y < 30) ? (size.x / width) : (1);
        int height = Math.min(toolTipHeight, size.y * widthFactor + heightAdjustment);
        int x = (pt.x + width > bounds.x + bounds.width) ? (bounds.x + bounds.width - width) : (pt.x);
        int y = (pt.y + height > bounds.y + bounds.height) ? (bounds.y + bounds.height - height) : (pt.y);
        toolShell.setBounds(x, y, width, height);
        final Point initCursor = toolShell.getDisplay().getCursorLocation();
        toolShell.addMouseTrackListener(new MouseTrackAdapter() {

            @Override
            public void mouseExit(MouseEvent e) {
                hideToolTip(toolShell);
            }
        });
        final AtomicReference<ScheduledFuture<?>> closeTimerRef = new AtomicReference<ScheduledFuture<?>>();
        ScheduledFuture<?> closeTimer = scheduleService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                if (!toolShell.isDisposed()) {
                    toolShell.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            // check if cursor is over tooltip
                            if (!toolShell.isDisposed()) {
                                Point cursor = toolShell.getDisplay().getCursorLocation();
                                if (!cursor.equals(initCursor)) {
                                    Rectangle bounds = toolShell.getBounds();
                                    if (addBounds != null) {
                                        Rectangle add;
                                        if (addBoundsControl != null) {
                                            Point addP = addBoundsControl.toDisplay(addBounds.x, addBounds.y);
                                            add = new Rectangle(addP.x, addP.y, addBounds.width, addBounds.height);
                                        } else {
                                            add = addBounds;
                                        }
                                        bounds = bounds.union(add);
                                    }
                                    if (!bounds.contains(cursor)) {
                                        hideToolTip(toolShell);
                                        ScheduledFuture<?> closeTimer = closeTimerRef.get();
                                        if (closeTimer != null)
                                            closeTimer.cancel(true);
                                    }
                                }
                            } else {
                                ScheduledFuture<?> closeTimer = closeTimerRef.get();
                                if (closeTimer != null)
                                    closeTimer.cancel(true);
                            }
                        }
                    });
                } else {
                    // disposed -> cancel timer
                    ScheduledFuture<?> closeTimer = closeTimerRef.get();
                    if (closeTimer != null)
                        closeTimer.cancel(true);
                }
            }
        }, 2 * HOVER_DELAY, 1000, TimeUnit.MILLISECONDS);
        closeTimerRef.set(closeTimer);
        toolShell.setVisible(true);
        toolShell.setFocus();
        return toolShell;
    } catch (SWTError err) {
        log.error(err.getMessage(), err);
        return null;
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) MouseEvent(org.eclipse.swt.events.MouseEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) Text(org.eclipse.swt.widgets.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ScheduledFuture(java.util.concurrent.ScheduledFuture) Shell(org.eclipse.swt.widgets.Shell) Browser(org.eclipse.swt.browser.Browser)

Example 63 with Browser

use of org.eclipse.swt.browser.Browser in project hale by halestudio.

the class CustomFunctionExplanationPage method createPreviewPart.

@SuppressWarnings("unused")
private void createPreviewPart(Composite page) {
    GridDataFactory df = GridDataFactory.fillDefaults().grab(true, false).hint(10, 200);
    try {
        previewBrowser = new Browser(page, SWT.NONE);
        df.applyTo(previewBrowser);
    } catch (Throwable e) {
        if (BROWSER_ERROR_REPORTED.compareAndSet(false, true)) {
            log.error("Could not create embedded browser, using text field as fall-back", e);
        }
        previewText = new Text(page, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
        df.applyTo(previewText);
    }
}
Also used : GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Text(org.eclipse.swt.widgets.Text) Browser(org.eclipse.swt.browser.Browser)

Example 64 with Browser

use of org.eclipse.swt.browser.Browser in project translationstudio8 by heartsome.

the class HtmlBrowserEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));
    cmp = new Composite(parent, SWT.BORDER);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(cmp);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(cmp);
    browser = new Browser(cmp, SWT.NONE);
    browser.setLayoutData(new GridData(GridData.FILL_BOTH));
    browser.setUrl(htmlUrl);
    browser.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            getSite().getPart().setFocus();
            super.mouseDown(e);
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Browser(org.eclipse.swt.browser.Browser)

Example 65 with Browser

use of org.eclipse.swt.browser.Browser in project cubrid-manager by CUBRID.

the class NoticeDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    {
        GridLayout tLayout = new GridLayout();
        tLayout.marginHeight = 0;
        tLayout.marginWidth = 0;
        tLayout.verticalSpacing = 0;
        tLayout.horizontalSpacing = 0;
        parentComp.setLayout(tLayout);
        parentComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    try {
        Browser browser = new Browser(parentComp, SWT.NONE);
        browser.setSize(500, 400);
        {
            GridLayout tLayout = new GridLayout();
            tLayout.marginHeight = 0;
            tLayout.marginWidth = 0;
            tLayout.verticalSpacing = 0;
            tLayout.horizontalSpacing = 0;
            browser.setLayout(tLayout);
            browser.setLayoutData(new GridData(GridData.FILL_BOTH));
        }
        browser.setUrl(url);
    } catch (Exception e) {
    }
    return parent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) 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