Search in sources :

Example 6 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project BiglyBT by BiglySoftware.

the class BrowserWrapperFake method setUrl.

@Override
public void setUrl(final String _url) {
    url = _url;
    Utils.execSWTThread(new Runnable() {

        @Override
        public void run() {
            String url_str = _url;
            int pos = url_str.indexOf('?');
            if (pos != -1) {
                url_str = url_str.substring(0, pos);
            }
            link_label.setText(url_str);
            browser.layout();
            for (LocationListener l : location_listeners) {
                try {
                    LocationEvent event = new LocationEvent(browser);
                    event.top = true;
                    event.location = _url;
                    l.changed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            for (ProgressListener l : progress_listeners) {
                try {
                    ProgressEvent event = new ProgressEvent(browser);
                    l.completed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
            for (TitleListener l : title_listeners) {
                try {
                    TitleEvent event = new TitleEvent(browser);
                    event.title = "Browser Disabled";
                    l.changed(event);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    });
}
Also used : TitleListener(org.eclipse.swt.browser.TitleListener) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Example 7 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project epp.mpc by eclipse.

the class OverviewToolTip method createToolTipContentArea.

@Override
protected Composite createToolTipContentArea(Event event, final Composite parent) {
    Shell shell = parent.getShell();
    setData(Shell.class.getName(), shell);
    AbstractMarketplaceDiscoveryItem.setWidgetId(shell, DiscoveryItem.WIDGET_ID_OVERVIEW);
    GridLayoutFactory.fillDefaults().applyTo(parent);
    Color backgroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_WHITE);
    final Composite container = new Composite(parent, SWT.NULL);
    container.setBackground(backgroundColor);
    boolean hasImage = false;
    if (overview.getScreenshot() != null) {
        hasImage = true;
    }
    final boolean addLearnMoreLink = browser != null && overview.getUrl() != null && overview.getUrl().length() > 0;
    final int borderWidth = 1;
    final int heightHint = SCREENSHOT_HEIGHT + (borderWidth * 2);
    final int widthHint = SCREENSHOT_WIDTH;
    final int containerWidthHintWithImage = 650;
    final int containerWidthHintWithoutImage = 500;
    GridDataFactory.fillDefaults().grab(true, true).hint(hasImage ? containerWidthHintWithImage : containerWidthHintWithoutImage, SWT.DEFAULT).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns((leftImage != null) ? 3 : 2).margins(5, 5).spacing(3, 0).applyTo(container);
    if (leftImage != null) {
        Label imageLabel = new Label(container, SWT.NONE);
        imageLabel.setImage(leftImage);
        imageLabel.setBackground(backgroundColor);
        int imageWidthHint = leftImage.getBounds().width + 5;
        GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).hint(imageWidthHint, SWT.DEFAULT).applyTo(imageLabel);
    }
    String summary = overview.getSummary();
    Composite summaryContainer = new Composite(container, SWT.NULL);
    summaryContainer.setBackground(backgroundColor);
    GridLayoutFactory.fillDefaults().applyTo(summaryContainer);
    GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().grab(true, true).span(hasImage ? 1 : 2, 1);
    if (hasImage) {
        gridDataFactory.hint(widthHint, heightHint);
    }
    gridDataFactory.applyTo(summaryContainer);
    Browser summaryLabel = new Browser(summaryContainer, SWT.NULL);
    Font dialogFont = JFaceResources.getDialogFont();
    FontData[] fontData = dialogFont.getFontData();
    // $NON-NLS-1$
    String attr = "";
    // $NON-NLS-1$
    String fontSizeUnitOfMeasure = "pt";
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
        // $NON-NLS-1$
        fontSizeUnitOfMeasure = "px";
    } else if (Platform.OS_WIN32.equals(Platform.getOS())) {
        // $NON-NLS-1$
        attr = "overflow: auto; ";
    }
    String cssStyle = // $NON-NLS-1$ //$NON-NLS-2$
    "body, p, div, *  {" + attr + "font-family:\"" + fontData[0].getName() + "\",Arial,sans-serif !important;font-size:" + fontData[0].getHeight() + fontSizeUnitOfMeasure + // $NON-NLS-1$ //$NON-NLS-2$
    " !important;" + // $NON-NLS-1$
    "} body { margin: 0px; background-color: white;}";
    summaryLabel.setFont(dialogFont);
    String html = // $NON-NLS-1$//$NON-NLS-2$
    "<html><style>" + cssStyle + "</style><body>" + TextUtil.cleanInformalHtmlMarkup(summary) + // $NON-NLS-1$
    "</body></html>";
    summaryLabel.setText(html);
    summaryLabel.setBackground(backgroundColor);
    // instead of opening links in the tooltip, open a new browser window
    summaryLabel.addLocationListener(new LocationListener() {

        public void changing(LocationEvent event) {
            if (event.location.equals("about:blank")) {
                // $NON-NLS-1$
                return;
            }
            event.doit = false;
            OverviewToolTip.this.hide();
            WorkbenchUtil.openUrl(event.location, IWorkbenchBrowserSupport.AS_EXTERNAL);
        }

        public void changed(LocationEvent event) {
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, hasImage ? SWT.DEFAULT : SCREENSHOT_HEIGHT).applyTo(summaryLabel);
    if (hasImage) {
        final Composite imageContainer = new Composite(container, SWT.BORDER);
        GridLayoutFactory.fillDefaults().applyTo(imageContainer);
        GridDataFactory.fillDefaults().grab(false, false).align(SWT.CENTER, SWT.BEGINNING).hint(widthHint + (borderWidth * 2), heightHint).applyTo(imageContainer);
        Label imageLabel = new Label(imageContainer, SWT.NULL);
        GridDataFactory.fillDefaults().hint(widthHint, SCREENSHOT_HEIGHT).indent(borderWidth, borderWidth).applyTo(imageLabel);
        imageLabel.setBackground(backgroundColor);
        imageLabel.setSize(widthHint, SCREENSHOT_HEIGHT);
        provideImage(imageLabel, source, overview.getScreenshot());
        final Cursor handCursor = new Cursor(imageLabel.getDisplay(), SWT.CURSOR_HAND);
        imageLabel.setCursor(handCursor);
        imageLabel.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                handCursor.dispose();
            }
        });
        imageLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                OverviewToolTip.this.hide();
                WorkbenchUtil.openUrl(overview.getScreenshot(), IWorkbenchBrowserSupport.AS_EXTERNAL);
            }
        });
        // creates a border
        imageContainer.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
    }
    if (addLearnMoreLink) {
        Link link = new Link(summaryContainer, SWT.NULL);
        AbstractMarketplaceDiscoveryItem.setWidgetId(link, DiscoveryItem.WIDGET_ID_LEARNMORE);
        GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(link);
        link.setText(Messages.OverviewToolTip_learnMoreLink);
        link.setBackground(backgroundColor);
        link.setToolTipText(NLS.bind(Messages.OverviewToolTip_openUrlInBrowser, overview.getUrl()));
        link.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                OverviewToolTip.this.hide();
                browser.openUrl(overview.getUrl());
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    if (!hasImage) {
        // prevent overviews with no image from providing unlimited text.
        Point optimalSize = summaryContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        if (optimalSize.y > (heightHint + 10)) {
            ((GridData) summaryContainer.getLayoutData()).heightHint = heightHint;
            container.layout(true);
        }
    }
    // hack: cause the tooltip to gain focus so that we can capture the escape key
    // this must be done async since the tooltip is not yet visible.
    Display.getCurrent().asyncExec(new Runnable() {

        public void run() {
            if (!parent.isDisposed()) {
                parent.setFocus();
            }
        }
    });
    return container;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Label(org.eclipse.swt.widgets.Label) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) Shell(org.eclipse.swt.widgets.Shell) LocationListener(org.eclipse.swt.browser.LocationListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) Link(org.eclipse.swt.widgets.Link) Browser(org.eclipse.swt.browser.Browser) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 8 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project eclipse-integration-commons by spring-projects.

the class HtmlTooltip method createToolTipContentArea.

@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());
    Browser browser = new Browser(composite, SWT.NONE);
    browser.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    browser.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    browser.setJavascriptEnabled(false);
    browser.addOpenWindowListener(new OpenWindowListener() {

        @Override
        public void open(WindowEvent event) {
            // Cancel opening of new windows
            event.required = true;
        }
    });
    // Replace browser's built-in context menu with none
    browser.setMenu(new Menu(browser.getShell(), SWT.NONE));
    String htmlContent = html.get();
    browser.setText(htmlContent);
    Point size = computeSizeHint(browser, htmlContent);
    browser.setLayoutData(GridDataFactory.swtDefaults().hint(size.x, size.y).create());
    // Add after HTML content is set to avoid event fired after the content is set
    browser.addLocationListener(new LocationAdapter() {

        @Override
        public void changing(LocationEvent event) {
            super.changing(event);
            event.doit = false;
            try {
                PlatformUI.getWorkbench().getBrowserSupport().createBrowser(null).openURL(new URL(event.location));
                hide();
            } catch (PartInitException | MalformedURLException e) {
                UiPlugin.log(e);
            }
        }
    });
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) Menu(org.eclipse.swt.widgets.Menu) Point(org.eclipse.swt.graphics.Point) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) URL(java.net.URL) Browser(org.eclipse.swt.browser.Browser)

Example 9 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project bndtools by bndtools.

the class JPMBrowserView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    StackLayout stack = new StackLayout();
    parent.setLayout(stack);
    JpmPreferences prefs = new JpmPreferences();
    if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
        external = true;
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout(2, false));
        new Label(composite, SWT.NONE).setText("Searchable Repository is configured to open in an external browser.");
        Hyperlink linkToPrefs = new Hyperlink(composite, SWT.NONE);
        linkToPrefs.setText("Open Preference Page");
        linkToPrefs.setUnderlined(true);
        linkToPrefs.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getViewSite().getShell(), "bndtools.prefPages.jpm", new String[] { "bndtools.prefPages.jpm" }, null);
                dialog.open();
            }
        });
        // linkToPrefs.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
        stack.topControl = composite;
    } else {
        if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_PLATFORM_DEFAULT) {
            browser = new Browser(parent, SWT.NONE);
            stack.topControl = browser;
        } else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_WEBKIT) {
            browser = new Browser(parent, SWT.WEBKIT);
            stack.topControl = browser;
        } else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_MOZILLA) {
            browser = new Browser(parent, SWT.MOZILLA);
            stack.topControl = browser;
        }
        createActions();
        // Prevent navigation away from JPM4J.org, and redirect from HTTP back to HTTPS
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changing(LocationEvent event) {
                setContentDescription(event.location);
            /*
                     * if (event.location.startsWith(HTTPS_URL)) return; if (event.location.startsWith(HTTP_URL))
                     * event.location = event.location.replaceFirst(HTTP_URL, HTTP_URL); else event.doit = false;
                     */
            }
        });
    }
    selectionService = getViewSite().getWorkbenchWindow().getSelectionService();
    selectionService.addSelectionListener(this);
    handleWorkbenchSelection(selectionService.getSelection());
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) JpmPreferences(bndtools.preferences.JpmPreferences) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) StackLayout(org.eclipse.swt.custom.StackLayout) LocationEvent(org.eclipse.swt.browser.LocationEvent) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Browser(org.eclipse.swt.browser.Browser)

Example 10 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project pentaho-kettle by pentaho.

the class ShowHelpDialog method addProgressAndLocationListener.

private void addProgressAndLocationListener() {
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void changed(ProgressEvent event) {
        }

        @Override
        public void completed(ProgressEvent event) {
            if (fromPrint) {
                wBrowser.execute(PRINT_SCRIPT);
                fromPrint = false;
            }
            setForwardBackEnable();
        }
    };
    LocationListener listener = new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            if (event.location.endsWith(".pdf")) {
                Program.launch(event.location);
                event.doit = false;
            }
        }

        @Override
        public void changed(LocationEvent event) {
            textURL.setText(event.location);
        }
    };
    wBrowser.addProgressListener(progressListener);
    wBrowser.addLocationListener(listener);
}
Also used : ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Aggregations

LocationEvent (org.eclipse.swt.browser.LocationEvent)17 LocationListener (org.eclipse.swt.browser.LocationListener)12 Browser (org.eclipse.swt.browser.Browser)11 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)6 URL (java.net.URL)4 SWTException (org.eclipse.swt.SWTException)4 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)4 ProgressListener (org.eclipse.swt.browser.ProgressListener)4 Point (org.eclipse.swt.graphics.Point)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SWTError (org.eclipse.swt.SWTError)3 Composite (org.eclipse.swt.widgets.Composite)3 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)2 TitleListener (org.eclipse.swt.browser.TitleListener)2 WindowEvent (org.eclipse.swt.browser.WindowEvent)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2