Search in sources :

Example 1 with BrowserContext

use of com.biglybt.ui.swt.browser.BrowserContext 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 2 with BrowserContext

use of com.biglybt.ui.swt.browser.BrowserContext in project BiglyBT by BiglySoftware.

the class SWTSkinObjectBrowser method setAutoReloadPending.

public void setAutoReloadPending(boolean is_pending, boolean aborted) {
    autoReloadPending = is_pending;
    BrowserContext bc = context;
    if (bc != null) {
        bc.setAutoReloadPending(is_pending, aborted);
    }
}
Also used : BrowserContext(com.biglybt.ui.swt.browser.BrowserContext)

Example 3 with BrowserContext

use of com.biglybt.ui.swt.browser.BrowserContext in project BiglyBT by BiglySoftware.

the class SWTSkinObjectBrowser method init.

public void init() {
    if (browser != null && !browser.isDisposed()) {
        return;
    }
    try {
        browser = BrowserWrapper.createBrowser(cArea, SWT.NONE);
        browser.setLayoutData(Utils.getFilledFormData());
        browser.getParent().layout(true);
    } catch (SWTError e) {
        System.err.println("Browser: " + e.toString());
        return;
    }
    Control widgetIndicator = null;
    String sIndicatorWidgetID = properties.getStringValue(sConfigID + ".indicator");
    if (sIndicatorWidgetID != null) {
        SWTSkinObject skinObjectIndicator = skin.getSkinObjectByID(sIndicatorWidgetID);
        if (skinObjectIndicator != null) {
            widgetIndicator = skinObjectIndicator.getControl();
        }
    }
    String browserID = properties.getStringValue(sConfigID + ".view");
    if (browserID == null) {
        browserID = sID;
    }
    forceVisibleAfterLoad = properties.getBooleanValue(sConfigID + ".forceVisibleAfterLoad", true);
    context = new BrowserContext(browserID, browser, widgetIndicator, forceVisibleAfterLoad);
    if (autoReloadPending) {
        context.setAutoReloadPending(autoReloadPending, false);
    }
    boolean noListeners = properties.getBooleanValue(sConfigID + ".browser.nolisteners", false);
    if (!noListeners) {
        context.addMessageListener(new TorrentListener());
        context.addMessageListener(new VuzeListener());
        context.addMessageListener(new DisplayListener());
        context.addMessageListener(new ConfigListener(browser));
    }
    boolean popouts = properties.getBooleanValue(sConfigID + ".browser.allowPopouts", true);
    context.setAllowPopups(popouts);
    String[] whitelist_urls = properties.getStringArray(sConfigID + ".browser.popoutWhitelist", null);
    if (whitelist_urls != null) {
        context.setPopoutWhitelist(whitelist_urls);
    }
    String[] blacklist_urls = properties.getStringArray(sConfigID + ".browser.popoutBlacklist", null);
    if (blacklist_urls != null) {
        context.setPopoutBlacklist(blacklist_urls);
    }
    context.addListener(new BrowserContext.loadingListener() {

        @Override
        public void browserLoadingChanged(boolean loading, String url) {
            if (loading && browser.isVisible()) {
                // hack so search results page doesn't clear cur selected
                if (UrlFilter.getInstance().urlCanRPC(url)) {
                    SelectedContentManager.clearCurrentlySelectedContent();
                }
            }
        }
    });
    String url = urlToUse != null ? urlToUse : sStartURL != null ? sStartURL : properties.getStringValue(sConfigID + ".url", (String) null);
    if (url != null) {
        setURL(url);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) TorrentListener(com.biglybt.ui.swt.browser.listener.TorrentListener) DisplayListener(com.biglybt.ui.swt.browser.listener.DisplayListener) VuzeListener(com.biglybt.ui.swt.browser.listener.VuzeListener) BrowserContext(com.biglybt.ui.swt.browser.BrowserContext) ConfigListener(com.biglybt.ui.swt.browser.listener.ConfigListener)

Aggregations

BrowserContext (com.biglybt.ui.swt.browser.BrowserContext)3 OpenCloseSearchDetailsListener (com.biglybt.ui.swt.browser.OpenCloseSearchDetailsListener)1 ConfigListener (com.biglybt.ui.swt.browser.listener.ConfigListener)1 DisplayListener (com.biglybt.ui.swt.browser.listener.DisplayListener)1 TorrentListener (com.biglybt.ui.swt.browser.listener.TorrentListener)1 VuzeListener (com.biglybt.ui.swt.browser.listener.VuzeListener)1 Map (java.util.Map)1 SWTError (org.eclipse.swt.SWTError)1 CloseWindowListener (org.eclipse.swt.browser.CloseWindowListener)1 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)1 ProgressListener (org.eclipse.swt.browser.ProgressListener)1 StatusTextEvent (org.eclipse.swt.browser.StatusTextEvent)1 StatusTextListener (org.eclipse.swt.browser.StatusTextListener)1 TitleEvent (org.eclipse.swt.browser.TitleEvent)1 TitleListener (org.eclipse.swt.browser.TitleListener)1 WindowEvent (org.eclipse.swt.browser.WindowEvent)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FillLayout (org.eclipse.swt.layout.FillLayout)1