Search in sources :

Example 1 with BrowserWrapper

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

the class DonationWindow method _open.

public static void _open(final boolean showNoLoad, final String sourceRef) {
    if (shell != null && !shell.isDisposed()) {
        return;
    }
    final Shell parentShell = Utils.findAnyShell();
    shell = ShellFactory.createShell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    shell.setLayout(new FillLayout());
    if (parentShell != null) {
        parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
    }
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                e.widget.dispose();
                e.doit = false;
            }
        }
    });
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (parentShell != null) {
                parentShell.setCursor(e.display.getSystemCursor(SWT.CURSOR_ARROW));
            }
            if (browserFunction != null && !browserFunction.isDisposed()) {
                browserFunction.dispose();
            }
            shell = null;
        }
    });
    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 == null || shell.isDisposed()) {
                return;
            }
            shell.setText(event.title);
        }
    });
    browserFunction = browser.addBrowserFunction("sendDonationEvent", new BrowserWrapper.BrowserFunction() {

        @Override
        public Object function(Object[] arguments) {
            if (shell == null || shell.isDisposed()) {
                return null;
            }
            if (arguments == null) {
                Debug.out("Invalid sendDonationEvent null ");
                return null;
            }
            if (arguments.length < 1) {
                Debug.out("Invalid sendDonationEvent length " + arguments.length + " not 1");
                return null;
            }
            if (!(arguments[0] instanceof String)) {
                Debug.out("Invalid sendDonationEvent " + (arguments[0] == null ? "NULL" : arguments.getClass().getSimpleName()) + " not String");
                return null;
            }
            String text = (String) arguments[0];
            if (text.contains("page-loaded")) {
                pageLoadedOk = true;
                COConfigurationManager.setParameter("donations.count", COConfigurationManager.getLongParameter("donations.count", 1) + 1);
                Utils.centreWindow(shell);
                if (parentShell != null) {
                    parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
                }
                shell.open();
            } else if (text.contains("reset-ask-time")) {
                int time = reAskEveryHours;
                String[] strings = text.split(" ");
                if (strings.length > 1) {
                    try {
                        time = Integer.parseInt(strings[1]);
                    } catch (Throwable ignore) {
                    }
                }
                resetAskTime(time);
            } else if (text.contains("never-ask-again")) {
                neverAskAgain();
            } else if (text.contains("close")) {
                Utils.execSWTThreadLater(0, new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (shell != null && !shell.isDisposed()) {
                            shell.dispose();
                        }
                    }
                });
            } else if (text.startsWith("open-url")) {
                String url = text.substring(9);
                Utils.launch(url);
            } 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 ignore) {
                    }
                }
            }
            return null;
        }
    });
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
        }

        @Override
        public void changed(LocationEvent event) {
        }
    });
    long upTime = StatsFactory.getStats().getTotalUpTime();
    // secs * mins
    int upHours = (int) (upTime / (60 * 60));
    final String url = Constants.URL_DONATION + "?locale=" + MessageText.getCurrentLocale().toString() + "&azv=" + Constants.AZUREUS_VERSION + "&count=" + COConfigurationManager.getLongParameter("donations.count", 1) + "&uphours=" + upHours + "&sourceref=" + UrlUtils.encode(sourceRef);
    if (!browser.isFake()) {
        SimpleTimer.addEvent("donation.pageload", SystemTime.getOffsetTime(6000), new TimerEventPerformer() {

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

                        @Override
                        public void runSupport() {
                            Debug.out("Page Didn't Load:" + url);
                            shell.dispose();
                            if (showNoLoad) {
                                new MessageBoxShell(SWT.OK, MessageText.getString("DonationWindow.noload.title"), MessageText.getString("DonationWindow.noload.text", new String[] { url })).open(null);
                            }
                        }
                    });
                }
            }
        });
    }
    browser.setUrl(url);
    if (browser.isFake()) {
        browser.setUrl(Constants.URL_DONATION);
        browser.setText("Please follow the link to donate via an external browser");
        shell.setSize(400, 500);
        Utils.centreWindow(shell);
        if (parentShell != null) {
            parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
        }
        shell.open();
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) Rectangle(org.eclipse.swt.graphics.Rectangle) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Shell(org.eclipse.swt.widgets.Shell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper)

Example 2 with BrowserWrapper

use of com.biglybt.ui.swt.BrowserWrapper 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.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 OpenWindowListener() {

            @Override
            public void open(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.AZUREUS_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("http://www.vuze.com/download");
            browser.setText("Update available, please go to www.vuze.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) Rectangle(org.eclipse.swt.graphics.Rectangle) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Shell(org.eclipse.swt.widgets.Shell) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 3 with BrowserWrapper

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

the class WelcomeWindow method _setWhatsNew.

public void _setWhatsNew() {
    if (sWhatsNew.contains("<html") || sWhatsNew.contains("<HTML")) {
        BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
        if (browser != null) {
            browser.setText(sWhatsNew);
        } else {
            try {
                File tempFile = File.createTempFile("AZU", ".html");
                tempFile.deleteOnExit();
                FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
                Utils.launch(tempFile.getAbsolutePath());
                shell.dispose();
                return;
            } catch (IOException e) {
            }
        }
    } else {
        StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);
        helpPanel.setEditable(false);
        try {
            helpPanel.setRedraw(false);
            helpPanel.setWordWrap(false);
            helpPanel.setFont(monospace);
            black = ColorCache.getColor(display, 0, 0, 0);
            white = ColorCache.getColor(display, 255, 255, 255);
            light = ColorCache.getColor(display, 200, 200, 200);
            grey = ColorCache.getColor(display, 50, 50, 50);
            green = ColorCache.getColor(display, 30, 80, 30);
            blue = ColorCache.getColor(display, 20, 20, 80);
            int style;
            boolean setStyle;
            helpPanel.setForeground(grey);
            String[] lines = sWhatsNew.split("\\r?\\n");
            for (int i = 0; i < lines.length; i++) {
                String line = lines[i];
                setStyle = false;
                fg = grey;
                bg = white;
                style = SWT.NORMAL;
                char styleChar;
                String text;
                if (line.length() < 2) {
                    styleChar = ' ';
                    text = " " + lineSeparator;
                } else {
                    styleChar = line.charAt(0);
                    text = line.substring(1) + lineSeparator;
                }
                switch(styleChar) {
                    case '*':
                        text = "  * " + text;
                        fg = green;
                        setStyle = true;
                        break;
                    case '+':
                        text = "     " + text;
                        fg = black;
                        bg = light;
                        style = SWT.BOLD;
                        setStyle = true;
                        break;
                    case '!':
                        style = SWT.BOLD;
                        setStyle = true;
                        break;
                    case '@':
                        fg = blue;
                        setStyle = true;
                        break;
                    case '$':
                        bg = blue;
                        fg = white;
                        style = SWT.BOLD;
                        setStyle = true;
                        break;
                    case ' ':
                        text = "  " + text;
                        break;
                    default:
                        text = styleChar + text;
                }
                helpPanel.append(text);
                if (setStyle) {
                    int lineCount = helpPanel.getLineCount() - 1;
                    int charCount = helpPanel.getCharCount();
                    // System.out.println("Got Linecount " + lineCount + ", Charcount " + charCount);
                    int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
                    int lineLen = charCount - lineOfs;
                    // System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
                    helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
                    helpPanel.setLineBackground(lineCount - 1, 1, bg);
                }
            }
            helpPanel.setRedraw(true);
        } catch (Exception e) {
            System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
        }
    }
    if (labelLoading != null && !labelLoading.isDisposed()) {
        labelLoading.dispose();
    }
    shell.layout(true, true);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) StyleRange(org.eclipse.swt.custom.StyleRange) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)

Example 4 with BrowserWrapper

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

the class SearchResultsTabAreaBrowser method anotherSearch.

@Override
public void anotherSearch(SearchQuery sq) {
    this.sq = sq;
    String url = Constants.URL_WEBSEARCH.replaceAll("%s", UrlUtils.encode(sq.term));
    AEProxyFactory.PluginHTTPProxy proxy = getSearchProxy(this);
    if (proxy != null) {
        url = proxy.proxifyURL(url);
    }
    if (Utils.isThisThreadSWT()) {
        try {
            final AESemaphore sem = new AESemaphore("brwoserWait");
            final BrowserWrapper browser = browserSkinObject.getBrowser();
            browser.addLocationListener(new LocationListener() {

                @Override
                public void changing(LocationEvent event) {
                }

                @Override
                public void changed(LocationEvent event) {
                    browser.removeLocationListener(this);
                    sem.releaseForever();
                }
            });
            browserSkinObject.getBrowser().setUrl("about:blank");
            browserSkinObject.getBrowser().refresh();
            browserSkinObject.getBrowser().update();
            final String finalURL = url;
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    sem.reserve(300);
                    browserSkinObject.setURL(finalURL);
                }
            });
        } catch (Throwable t) {
        }
    } else {
        browserSkinObject.setURL(url);
    }
}
Also used : LocationListener(org.eclipse.swt.browser.LocationListener) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) AEProxyFactory(com.biglybt.core.proxy.AEProxyFactory) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Example 5 with BrowserWrapper

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

the class MessageBoxShell method _open.

private void _open() {
    if (instanceID != null) {
        if (mapInstances.containsKey(instanceID)) {
            MessageBoxShell mb = mapInstances.get(instanceID);
            if (mb.shell != null && !mb.shell.isDisposed()) {
                mb.shell.open();
                return;
            }
        }
        mapInstances.put(instanceID, this);
    }
    result = -1;
    boolean ourParent = false;
    if (parent == null || parent.isDisposed()) {
        parent = Utils.findAnyShell();
        ourParent = true;
        if (parent == null || parent.isDisposed()) {
            triggerResultListener(result);
            return;
        }
    }
    final Display display = parent.getDisplay();
    // APPLICATION_MODAL causes some crazy sht to happen on Windows.
    // Example: 5 windows open in APPLICATION MODAL mode,
    // and somehow none of them show until you do a "Window->Bring To Front"
    // which only makes ONE visible
    int shell_style = SWT.DIALOG_TRIM | SWT.RESIZE;
    if (modal) {
        shell_style |= SWT.APPLICATION_MODAL;
    }
    shell = ShellFactory.createShell(parent, shell_style);
    if (title != null) {
        shell.setText(title);
    }
    shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            mapInstances.remove(instanceID);
            if (iconImageID != null) {
                ImageLoader.getInstance().releaseImage(iconImageID);
            }
            triggerResultListener(result);
            if (display != null && !display.isDisposed() && filterListener != null) {
                display.removeFilter(SWT.Traverse, filterListener);
            }
            numOpen--;
        }
    });
    GridLayout gridLayout = new GridLayout();
    if (squish) {
        gridLayout.verticalSpacing = 0;
        gridLayout.horizontalSpacing = 0;
        gridLayout.marginLeft = 0;
        gridLayout.marginRight = 0;
        gridLayout.marginTop = 0;
        gridLayout.marginBottom = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
    }
    shell.setLayout(gridLayout);
    Utils.setShellIcon(shell);
    UISkinnableSWTListener[] listeners = UISkinnableManagerSWT.getInstance().getSkinnableListeners(MessageBoxShell.class.toString());
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].skinBeforeComponents(shell, this, relatedObjects);
    }
    FormData formData;
    GridData gridData;
    Composite textComposite = shell;
    if (imgLeft != null) {
        textComposite = new Composite(shell, SWT.NONE);
        textComposite.setForeground(shell.getForeground());
        GridLayout gl = new GridLayout(2, false);
        gl.horizontalSpacing = 10;
        Utils.setLayout(textComposite, gl);
        Utils.setLayoutData(textComposite, new GridData(GridData.FILL_BOTH));
        Label lblImage = new Label(textComposite, SWT.NONE);
        lblImage.setImage(imgLeft);
        Utils.setLayoutData(lblImage, new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    } else if (!squish) {
        textComposite = new Composite(shell, SWT.NONE);
        GridLayout gl = new GridLayout(2, false);
        gl.marginWidth = 5;
        Utils.setLayout(textComposite, gl);
        Utils.setLayoutData(textComposite, new GridData(GridData.FILL_BOTH));
    }
    Control linkControl;
    if (text != null && text.length() > 0) {
        if (useTextBox()) {
            linkControl = createTextBox(textComposite, text);
        } else {
            linkControl = createLinkLabel(textComposite, text);
        }
    } else {
        linkControl = null;
    }
    if ((html != null && html.length() > 0) || (url != null && url.length() > 0)) {
        try {
            final BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
            if (url != null && url.length() > 0) {
                browser.setUrl(url);
            } else {
                browser.setText(html);
            }
            GridData gd = new GridData(GridData.FILL_BOTH);
            gd.heightHint = 200;
            Utils.setLayoutData(browser.getControl(), gd);
            browser.addProgressListener(new ProgressListener() {

                @Override
                public void completed(ProgressEvent event) {
                    if (shell == null || shell.isDisposed()) {
                        return;
                    }
                    browser.addLocationListener(new LocationListener() {

                        @Override
                        public void changing(LocationEvent event) {
                            event.doit = browser_follow_links;
                        }

                        @Override
                        public void changed(LocationEvent event) {
                        }
                    });
                    browser.addOpenWindowListener(new OpenWindowListener() {

                        @Override
                        public void open(WindowEvent event) {
                            event.required = true;
                        }
                    });
                }

                @Override
                public void changed(ProgressEvent event) {
                }
            });
            browser.addStatusTextListener(new StatusTextListener() {

                @Override
                public void changed(StatusTextEvent event) {
                    if (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();
                                }
                            }
                        });
                    }
                }
            });
        } catch (Exception e) {
            Debug.out(e);
            if (html != null) {
                Text text = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP);
                text.setText(html);
                GridData gd = new GridData(GridData.FILL_BOTH);
                gd.heightHint = 200;
                Utils.setLayoutData(text, gd);
            }
        }
        if (linkControl != null) {
            gridData = new GridData(GridData.FILL_HORIZONTAL);
            Utils.setLayoutData(linkControl, gridData);
        }
    } else {
        if (linkControl != null) {
            gridData = new GridData(GridData.FILL_BOTH);
            Utils.setLayoutData(linkControl, gridData);
        }
    }
    if (!squish && (autoCloseInMS > 0 || rememberID != null || (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode))) {
        Label lblPadding = new Label(shell, SWT.NONE);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 5;
        Utils.setLayoutData(lblPadding, gridData);
    }
    // Closing in..
    if (autoCloseInMS > 0) {
        final BufferedLabel lblCloseIn = new BufferedLabel(shell, SWT.WRAP | SWT.DOUBLE_BUFFERED);
        lblCloseIn.setForeground(shell.getForeground());
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        if (!squish) {
            gridData.horizontalIndent = 5;
        }
        lblCloseIn.setText(MessageText.getString("popup.closing.in", new String[] { String.valueOf(autoCloseInMS / 1000) }));
        Utils.setLayoutData(lblCloseIn, gridData);
        long endOn = SystemTime.getCurrentTime() + autoCloseInMS;
        lblCloseIn.setData("CloseOn", new Long(endOn));
        SimpleTimer.addPeriodicEvent("autoclose", 500, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                if (shell.isDisposed()) {
                    event.cancel();
                    return;
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (!shell.isDisposed()) {
                            boolean bDelayPaused = lblCloseIn.getData("DelayPaused") != null;
                            if (bDelayPaused) {
                                return;
                            }
                            long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue();
                            if (SystemTime.getCurrentTime() > endOn) {
                                result = defaultButtonPos;
                                autoClosed = true;
                                shell.dispose();
                            } else {
                                String sText = "";
                                if (lblCloseIn.isDisposed())
                                    return;
                                if (!bDelayPaused) {
                                    long delaySecs = (endOn - SystemTime.getCurrentTime()) / 1000;
                                    sText = MessageText.getString("popup.closing.in", new String[] { String.valueOf(delaySecs) });
                                }
                                lblCloseIn.setText(sText);
                            }
                        }
                    }
                });
            }
        });
        SimpleTimer.addPeriodicEvent("OverPopup", 100, new TimerEventPerformer() {

            boolean wasOver = true;

            long lEnterOn = 0;

            @Override
            public void perform(final TimerEvent event) {
                if (shell.isDisposed()) {
                    event.cancel();
                    return;
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        if (shell.isDisposed()) {
                            event.cancel();
                            return;
                        }
                        boolean isOver = shell.getBounds().contains(shell.getDisplay().getCursorLocation());
                        if (isOver != wasOver) {
                            wasOver = isOver;
                            if (isOver) {
                                lblCloseIn.setData("DelayPaused", "");
                                lEnterOn = SystemTime.getCurrentTime();
                                lblCloseIn.setText("");
                            } else {
                                lblCloseIn.setData("DelayPaused", null);
                                if (lEnterOn > 0) {
                                    long diff = SystemTime.getCurrentTime() - lEnterOn;
                                    long endOn = ((Long) lblCloseIn.getData("CloseOn")).longValue() + diff;
                                    lblCloseIn.setData("CloseOn", new Long(endOn));
                                }
                            }
                        }
                    }
                });
            }
        });
    }
    if (cbMessageID != null && Utils.getUserMode() >= cbMinUserMode) {
        Button cb = new Button(shell, SWT.CHECK);
        cb.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                cbEnabled = ((Button) e.widget).getSelection();
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        Messages.setLanguageText(cb, cbMessageID);
        cb.setSelection(cbEnabled);
    }
    // Remember Me
    Button checkRemember = null;
    if (rememberID != null) {
        checkRemember = new Button(shell, SWT.CHECK);
        checkRemember.setText(rememberText);
        checkRemember.setSelection(rememberByDefault);
        isRemembered = rememberByDefault;
        checkRemember.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Button checkRemember = (Button) event.widget;
                isRemembered = checkRemember.getSelection();
            }
        });
        checkRemember.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                Button checkRemember = (Button) e.widget;
                isRemembered = checkRemember != null && checkRemember.getSelection();
                if (rememberID != null && isRemembered && (rememberOnlyIfButtonPos == -1 || rememberOnlyIfButtonPos == result)) {
                    RememberedDecisionsManager.setRemembered(rememberID, getButtonVal(result));
                }
            }
        });
    } else {
        Button spacer = new Button(shell, SWT.CHECK);
        spacer.setVisible(false);
    }
    if (buttons.length > 0) {
        Canvas line = new Canvas(shell, SWT.NO_BACKGROUND);
        line.addListener(SWT.Paint, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Rectangle clientArea = ((Canvas) e.widget).getClientArea();
                e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_NORMAL_SHADOW));
                e.gc.drawRectangle(clientArea);
                clientArea.y++;
                e.gc.setForeground(Colors.getSystemColor(e.display, SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                e.gc.drawRectangle(clientArea);
            }
        });
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 2;
        Utils.setLayoutData(line, gridData);
        Composite cButtons = new Composite(shell, SWT.NONE);
        FormLayout layout = new FormLayout();
        cButtons.setLayout(layout);
        gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
        Utils.setLayoutData(cButtons, gridData);
        Control lastButton = null;
        Listener buttonListener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                result = ((Integer) event.widget.getData()).intValue();
                shell.dispose();
            }
        };
        int buttonWidth = 0;
        Button[] swtButtons = new Button[buttons.length];
        for (int i = 0; i < buttons.length; i++) {
            Button button = new Button(cButtons, SWT.PUSH);
            swtButtons[i] = button;
            button.setData(Integer.valueOf(i));
            button.setText(buttons[i]);
            button.addListener(SWT.Selection, buttonListener);
            formData = new FormData();
            if (lastButton != null) {
                formData.left = new FormAttachment(lastButton, 5);
            }
            Utils.setLayoutData(button, formData);
            Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            if (size.x > buttonWidth) {
                buttonWidth = size.x;
            }
            if (i == defaultButtonPos) {
                button.setFocus();
                shell.setDefaultButton(button);
            }
            lastButton = button;
        }
        if (buttonWidth > 0) {
            if (buttonWidth < MIN_BUTTON_SIZE) {
                buttonWidth = MIN_BUTTON_SIZE;
            }
            for (int i = 0; i < buttons.length; i++) {
                Point size = swtButtons[i].computeSize(buttonWidth, SWT.DEFAULT);
                swtButtons[i].setSize(size);
                formData = (FormData) swtButtons[i].getLayoutData();
                formData.width = buttonWidth;
            }
        }
    }
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
            }
        }
    });
    filterListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.detail == SWT.TRAVERSE_ARROW_NEXT) {
                event.detail = SWT.TRAVERSE_TAB_NEXT;
                event.doit = true;
            } else if (event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
                event.detail = SWT.TRAVERSE_TAB_PREVIOUS;
                event.doit = true;
            }
        }
    };
    display.addFilter(SWT.Traverse, filterListener);
    shell.pack();
    Point size = shell.getSize();
    if (size.x < min_size_x) {
        size.x = min_size_x;
        shell.setSize(size);
    } else if (size.x > max_size_x) {
        size = shell.computeSize(max_size_x, SWT.DEFAULT);
        shell.setSize(size);
    }
    if (size.y < min_size_y) {
        size.y = min_size_y;
        shell.setSize(size);
    }
    Shell centerRelativeToShell = parent;
    if (ourParent) {
        Control cursorControl = display.getCursorControl();
        if (cursorControl != null) {
            centerRelativeToShell = cursorControl.getShell();
        }
    }
    Utils.centerWindowRelativeTo(shell, centerRelativeToShell);
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].skinAfterComponents(shell, this, relatedObjects);
    }
    shell.open();
    opened = true;
    numOpen++;
    return;
}
Also used : UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) MessageText(com.biglybt.core.internat.MessageText) UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener)

Aggregations

BrowserWrapper (com.biglybt.ui.swt.BrowserWrapper)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Shell (org.eclipse.swt.widgets.Shell)2 MessageText (com.biglybt.core.internat.MessageText)1 AEProxyFactory (com.biglybt.core.proxy.AEProxyFactory)1 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 UISkinnableSWTListener (com.biglybt.ui.swt.UISkinnableSWTListener)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 File (java.io.File)1 IOException (java.io.IOException)1 LocationEvent (org.eclipse.swt.browser.LocationEvent)1 LocationListener (org.eclipse.swt.browser.LocationListener)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledText (org.eclipse.swt.custom.StyledText)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1