Search in sources :

Example 1 with TitleEvent

use of org.eclipse.swt.browser.TitleEvent 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 2 with TitleEvent

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

the class BrowserWindow method init.

public void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal) {
    int style = SWT.DIALOG_TRIM;
    if (allowResize) {
        style |= SWT.RESIZE;
    }
    if (isModal) {
        style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, style);
    shell.setLayout(new FillLayout());
    Utils.setShellIcon(shell);
    shell.setText(url);
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
                e.doit = false;
            }
        }
    });
    final Listener escListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.keyCode == 27) {
                shell.dispose();
            }
        }
    };
    shell.getDisplay().addFilter(SWT.KeyDown, escListener);
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.display.removeFilter(SWT.KeyDown, escListener);
        }
    });
    browser = Utils.createSafeBrowser(shell, SWT.NONE);
    if (browser == null) {
        shell.dispose();
        return;
    }
    context = new BrowserContext("browser-window" + Math.random(), browser, null, true);
    context.addMessageListener(new TorrentListener());
    context.addMessageListener(new VuzeListener());
    context.addMessageListener(new DisplayListener());
    context.addMessageListener(new ConfigListener(browser));
    context.addMessageListener(new MetaSearchListener(new OpenCloseSearchDetailsListener() {

        @Override
        public void resizeSecondaryBrowser() {
        }

        @Override
        public void resizeMainBrowser() {
        }

        @Override
        public void openSearchResults(Map params) {
        }

        @Override
        public void closeSearchResults(Map params) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.dispose();
        }
    }));
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.open();
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    browser.addCloseWindowListener(new CloseWindowListener() {

        @Override
        public void close(WindowEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            context.debug("window.close called");
            shell.dispose();
        }
    });
    browser.addTitleListener(new TitleListener() {

        @Override
        public void changed(TitleEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    browser.addStatusTextListener(new StatusTextListener() {

        @Override
        public void changed(StatusTextEvent event) {
            if (browser.isDisposed() || browser.getShell().isDisposed()) {
                return;
            }
            if (MessageBoxShell.STATUS_TEXT_CLOSE.equals(event.text)) {
                // For some reason disposing the shell / browser in the same Thread makes
                // ieframe.dll crash on windows.
                Utils.execSWTThreadLater(0, new Runnable() {

                    @Override
                    public void run() {
                        if (!browser.isDisposed() && !shell.isDisposed()) {
                            shell.close();
                        }
                    }
                });
            }
        }
    });
    SimpleTimer.addEvent("showWin", SystemTime.getOffsetTime(3000), new TimerEventPerformer() {

        @Override
        public void perform(TimerEvent event) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (shell != null && !shell.isDisposed()) {
                        shell.open();
                    }
                }
            });
        }
    });
    if (w > 0 && h > 0) {
        Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
        shell.setSize(computeTrim.width, computeTrim.height);
    // shell.setSize(w, h);
    }
    Utils.centerWindowRelativeTo(shell, parent);
    browser.setUrl(url);
    browser.setData("StartURL", url);
}
Also used : OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) OpenCloseSearchDetailsListener(com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener) TitleListener(org.eclipse.swt.browser.TitleListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) Rectangle(org.eclipse.swt.graphics.Rectangle) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) BrowserContext(com.biglybt.ui.swt.browser.BrowserContext) FillLayout(org.eclipse.swt.layout.FillLayout) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) WindowEvent(org.eclipse.swt.browser.WindowEvent) TitleEvent(org.eclipse.swt.browser.TitleEvent) Map(java.util.Map)

Example 3 with TitleEvent

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

the class FullUpdateWindow method open.

public static void open(final String url, final UIFunctions.actionListener listener) {
    boolean ok = false;
    final boolean[] listener_informed = { false };
    try {
        if (current_shell != null && !current_shell.isDisposed()) {
            return;
        }
        final Shell parentShell = Utils.findAnyShell();
        final Shell shell = current_shell = ShellFactory.createShell(parentShell, SWT.BORDER | SWT.APPLICATION_MODAL | SWT.TITLE | SWT.RESIZE | SWT.DIALOG_TRIM);
        if (shell == null) {
            return;
        }
        shell.setLayout(new FillLayout());
        if (parentShell != null) {
            parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
        }
        shell.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                try {
                    if (parentShell != null) {
                        parentShell.setCursor(e.display.getSystemCursor(SWT.CURSOR_ARROW));
                    }
                    if (browserFunction != null && !browserFunction.isDisposed()) {
                        browserFunction.dispose();
                    }
                    current_shell = null;
                } finally {
                    if (!listener_informed[0]) {
                        try {
                            listener.actionComplete(false);
                        } catch (Throwable f) {
                            Debug.out(f);
                        }
                    }
                }
            }
        });
        BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
        if (browser == null) {
            shell.dispose();
            return;
        }
        browser.addTitleListener(new TitleListener() {

            @Override
            public void changed(TitleEvent event) {
                if (shell.isDisposed()) {
                    return;
                }
                shell.setText(event.title);
            }
        });
        browser.addOpenWindowListener(new BrowserWrapper.OpenWindowListener() {

            @Override
            public void open(BrowserWrapper.WindowEvent event) {
                final BrowserWrapper subBrowser = Utils.createSafeBrowser(shell, SWT.NONE);
                if (subBrowser == null) {
                    return;
                }
                subBrowser.addLocationListener(new LocationListener() {

                    @Override
                    public void changed(LocationEvent arg0) {
                    }

                    @Override
                    public void changing(LocationEvent event) {
                        if (event.location == null || !event.location.startsWith("http")) {
                            return;
                        }
                        event.doit = false;
                        Utils.launch(event.location);
                        Utils.execSWTThreadLater(1000, new AERunnable() {

                            @Override
                            public void runSupport() {
                                subBrowser.dispose();
                            }
                        });
                    }
                });
                subBrowser.setBrowser(event);
            }
        });
        browserFunction = browser.addBrowserFunction("sendVuzeUpdateEvent", new BrowserWrapper.BrowserFunction() {

            private String last = null;

            @Override
            public Object function(Object[] arguments) {
                if (shell.isDisposed()) {
                    return null;
                }
                if (arguments == null) {
                    Debug.out("Invalid sendVuzeUpdateEvent null ");
                    return null;
                }
                if (arguments.length < 1) {
                    Debug.out("Invalid sendVuzeUpdateEvent length " + arguments.length + " not 1");
                    return null;
                }
                if (!(arguments[0] instanceof String)) {
                    Debug.out("Invalid sendVuzeUpdateEvent " + (arguments[0] == null ? "NULL" : arguments.getClass().getSimpleName()) + " not String");
                    return null;
                }
                String text = ((String) arguments[0]).toLowerCase();
                if (last != null && last.equals(text)) {
                    return null;
                }
                last = text;
                if (text.contains("page-loaded")) {
                    Utils.centreWindow(shell);
                    if (parentShell != null) {
                        parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
                    }
                    shell.open();
                } else if (text.startsWith("set-size")) {
                    String[] strings = text.split(" ");
                    if (strings.length > 2) {
                        try {
                            int w = Integer.parseInt(strings[1]);
                            int h = Integer.parseInt(strings[2]);
                            Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
                            shell.setSize(computeTrim.width, computeTrim.height);
                        } catch (Exception ignored) {
                        }
                    }
                } else if (text.contains("decline") || text.contains("close")) {
                    Utils.execSWTThreadLater(0, new AERunnable() {

                        @Override
                        public void runSupport() {
                            shell.dispose();
                        }
                    });
                } else if (text.contains("accept")) {
                    Utils.execSWTThreadLater(0, new AERunnable() {

                        @Override
                        public void runSupport() {
                            listener_informed[0] = true;
                            try {
                                listener.actionComplete(true);
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                            shell.dispose();
                        }
                    });
                }
                return null;
            }
        });
        browser.addStatusTextListener(new StatusTextListener() {

            @Override
            public void changed(StatusTextEvent event) {
                if (browserFunction != null) {
                    browserFunction.function(new Object[] { event.text });
                }
            }
        });
        browser.addLocationListener(new LocationListener() {

            @Override
            public void changing(LocationEvent event) {
            }

            @Override
            public void changed(LocationEvent event) {
            }
        });
        String final_url = url + (url.indexOf('?') == -1 ? "?" : "&") + "locale=" + MessageText.getCurrentLocale().toString() + "&azv=" + Constants.BIGLYBT_VERSION;
        SimpleTimer.addEvent("fullupdate.pageload", SystemTime.getOffsetTime(5000), new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (!shell.isDisposed()) {
                            shell.open();
                        }
                    }
                });
            }
        });
        browser.setUrl(final_url);
        if (browser.isFake()) {
            shell.setSize(400, 500);
            Utils.centreWindow(shell);
            browser.setUrl(Constants.URL_CLIENT_HOME);
            browser.setText("Update available, please go to www.biglybt.com to update.");
            shell.open();
        }
        ok = true;
    } finally {
        if (!ok) {
            try {
                listener.actionComplete(false);
            } catch (Throwable f) {
                Debug.out(f);
            }
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TitleListener(org.eclipse.swt.browser.TitleListener) Rectangle(org.eclipse.swt.graphics.Rectangle) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) StatusTextEvent(org.eclipse.swt.browser.StatusTextEvent) Shell(org.eclipse.swt.widgets.Shell) LocationListener(org.eclipse.swt.browser.LocationListener) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) LocationEvent(org.eclipse.swt.browser.LocationEvent) FillLayout(org.eclipse.swt.layout.FillLayout) TitleEvent(org.eclipse.swt.browser.TitleEvent)

Example 4 with TitleEvent

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

the class StsBrowserEditor method createPartControl.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
	 * .Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new FillLayout());
    browserViewer = new StsBrowserViewer(parent, hasToolbar() ? StsBrowserViewer.BUTTON_BAR | StsBrowserViewer.LOCATION_BAR : SWT.NONE);
    final Browser browser = browserViewer.getBrowser();
    if (getEditorInput() instanceof WebBrowserEditorInput) {
        homeUrl = ((WebBrowserEditorInput) getEditorInput()).getURL().toString();
        browserViewer.setVisible(true);
    }
    if (homeUrl != null) {
        browserViewer.setHomeUrl(homeUrl);
        browserViewer.setURL(homeUrl);
    } else {
        browser.setText("<h1>URL not set</h1>" + "<p>Url should be provided via the setInitializationData method</p>");
    }
    if (getName() == null) {
        browser.addTitleListener(new TitleListener() {

            @Override
            public void changed(TitleEvent event) {
                String newValue = event.title;
                setName(newValue);
                setPartName(newValue);
            }
        });
    }
    browser.addProgressListener(new ProgressAdapter() {

        @Override
        public void completed(ProgressEvent event) {
            StsBrowserViewer browserViewer = getBrowserViewer();
            if (browserViewer != null) {
                if (browserManager == null) {
                    browserManager = new StsBrowserManager();
                }
                browserManager.setClient(browserViewer.getBrowser());
                if (getEditorInput() instanceof WebBrowserEditorInput) {
                    String url = browserViewer.getURL();
                    try {
                        setInput(new WebBrowserEditorInput(new URL(url), SWT.NONE, url));
                    } catch (MalformedURLException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    });
}
Also used : TitleListener(org.eclipse.swt.browser.TitleListener) MalformedURLException(java.net.MalformedURLException) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) URL(java.net.URL) TitleEvent(org.eclipse.swt.browser.TitleEvent) WebBrowserEditorInput(org.eclipse.ui.internal.browser.WebBrowserEditorInput) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser)

Example 5 with TitleEvent

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

the class SimpleBrowserWindow method init.

private void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal) {
    if (parent == null) {
        parent = Utils.findAnyShell();
    }
    int style = SWT.DIALOG_TRIM;
    if (allowResize) {
        style |= SWT.RESIZE;
    }
    if (isModal) {
        style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, style);
    shell.setLayout(new FillLayout());
    Utils.setShellIcon(shell);
    browser = Utils.createSafeBrowser(shell, SWT.NONE);
    if (browser == null) {
        shell.dispose();
        return;
    }
    browser.addProgressListener(new ProgressListener() {

        @Override
        public void completed(ProgressEvent event) {
            shell.open();
        }

        @Override
        public void changed(ProgressEvent event) {
        }
    });
    browser.addCloseWindowListener(new CloseWindowListener() {

        @Override
        public void close(WindowEvent event) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            shell.dispose();
        }
    });
    browser.addTitleListener(new TitleListener() {

        @Override
        public void changed(TitleEvent event) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    if (w > 0 && h > 0) {
        shell.setSize(w, h);
    }
    Utils.centerWindowRelativeTo(shell, parent);
    browser.setUrl(url);
    browser.setData("StartURL", url);
}
Also used : TitleListener(org.eclipse.swt.browser.TitleListener) TitleEvent(org.eclipse.swt.browser.TitleEvent) ProgressListener(org.eclipse.swt.browser.ProgressListener) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressEvent(org.eclipse.swt.browser.ProgressEvent)

Aggregations

TitleEvent (org.eclipse.swt.browser.TitleEvent)5 TitleListener (org.eclipse.swt.browser.TitleListener)5 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 ProgressListener (org.eclipse.swt.browser.ProgressListener)3 CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)2 LocationEvent (org.eclipse.swt.browser.LocationEvent)2 LocationListener (org.eclipse.swt.browser.LocationListener)2 StatusTextEvent (org.eclipse.swt.browser.StatusTextEvent)2 StatusTextListener (org.eclipse.swt.browser.StatusTextListener)2 WindowEvent (org.eclipse.swt.browser.WindowEvent)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 BrowserWrapper (com.biglybt.ui.swt.BrowserWrapper)1 BrowserContext (com.biglybt.ui.swt.browser.BrowserContext)1 OpenCloseSearchDetailsListener (com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 Browser (org.eclipse.swt.browser.Browser)1 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)1