Search in sources :

Example 1 with UISkinnableSWTListener

use of com.biglybt.ui.swt.UISkinnableSWTListener 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)

Example 2 with UISkinnableSWTListener

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

the class MessageSlideShell method create.

private void create(final Display display, final PopupParams popupParams, boolean bSlide) {
    // Reset the last read message counter.
    firstUnreadMessage = -1;
    GridData gridData;
    int style = SWT.ON_TOP;
    boolean bDisableSliding = COConfigurationManager.getBooleanParameter("GUI_SWT_DisableAlertSliding");
    if (bDisableSliding) {
        bSlide = false;
        style = SWT.NONE;
    }
    if (DEBUG)
        System.out.println("create " + (bSlide ? "SlideIn" : "") + ";" + historyList.indexOf(popupParams) + ";");
    idxHistory = historyList.indexOf(popupParams);
    // 2 Assertions
    if (idxHistory < 0) {
        System.err.println("Not in popup history list");
        return;
    }
    if (currentPopupIndex == idxHistory) {
        System.err.println("Trying to open already opened!! " + idxHistory);
        return;
    }
    try {
        monitor.enter();
        currentPopupIndex = idxHistory;
    } finally {
        monitor.exit();
    }
    if (DEBUG)
        System.out.println("set currIdx = " + idxHistory);
    sDetails = popupParams.details;
    // Load Images
    Image imgIcon = popupParams.iconID <= 0 ? null : display.getSystemImage(popupParams.iconID);
    /*
		 * If forceTimer is true then we always show the counter for auto-closing the shell;
		 * otherwise proceed to the more fine-grained logic
		 */
    // if there's a link, or the info is non-information,
    // disable timer and mouse watching
    bDelayPaused = popupParams.iconID != SWT.ICON_INFORMATION || !bSlide;
    // Pause the auto-close delay when mouse is over slidey
    // This will be applies to every control
    final MouseTrackAdapter mouseAdapter = bDelayPaused ? null : new MouseTrackAdapter() {

        @Override
        public void mouseEnter(MouseEvent e) {
            bDelayPaused = true;
        }

        @Override
        public void mouseExit(MouseEvent e) {
            bDelayPaused = false;
        }
    };
    // Create shell & widgets
    if (bDisableSliding) {
        UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
        if (uiFunctions != null) {
            Shell mainShell = uiFunctions.getMainShell();
            if (mainShell != null) {
                shell = new Shell(mainShell, style);
            }
        }
    }
    if (shell == null) {
        shell = new Shell(display, style);
    }
    try {
        shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    } catch (NoSuchMethodError e) {
    // Ignore
    } catch (NoSuchFieldError e2) {
    // ignore
    }
    Utils.setShellIcon(shell);
    if (popupParams.title != null) {
        shell.setText(popupParams.title);
    }
    shellWidth = Utils.adjustPXForDPI(SHELL_DEF_WIDTH);
    UISkinnableSWTListener[] listeners = UISkinnableManagerSWT.getInstance().getSkinnableListeners(MessageSlideShell.class.toString());
    for (int i = 0; i < listeners.length; i++) {
        try {
            listeners[i].skinBeforeComponents(shell, this, popupParams.relatedTo);
        } catch (Exception e) {
            Debug.out(e);
        }
    }
    if (colorFG == null) {
        colorFG = Colors.getSystemColor(display, SWT.COLOR_BLACK);
    }
    FormLayout shellLayout = new FormLayout();
    shell.setLayout(shellLayout);
    cShell = new Composite(shell, SWT.NULL);
    GridLayout layout = new GridLayout(3, false);
    cShell.setLayout(layout);
    FormData formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    cShell.setLayoutData(formData);
    Label lblIcon = new Label(cShell, SWT.NONE);
    lblIcon.setImage(imgIcon);
    lblIcon.setLayoutData(new GridData());
    if (popupParams.title != null) {
        Label lblTitle = new Label(cShell, SWT.getVersion() < 3100 ? SWT.NONE : SWT.WRAP);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        if (SWT.getVersion() < 3100)
            gridData.widthHint = 140;
        lblTitle.setLayoutData(gridData);
        lblTitle.setForeground(colorFG);
        lblTitle.setText(popupParams.title);
        FontData[] fontData = lblTitle.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        fontData[0].setHeight((int) (fontData[0].getHeight() * 1.5));
        Font boldFont = new Font(display, fontData);
        disposeList.add(boldFont);
        lblTitle.setFont(boldFont);
    }
    final Button btnDetails = new Button(cShell, SWT.TOGGLE);
    btnDetails.setForeground(colorFG);
    Messages.setLanguageText(btnDetails, "label.details");
    gridData = new GridData();
    btnDetails.setLayoutData(gridData);
    btnDetails.addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            try {
                boolean bShow = btnDetails.getSelection();
                if (bShow) {
                    Shell detailsShell = new Shell(display, SWT.BORDER | SWT.ON_TOP);
                    Utils.setShellIcon(detailsShell);
                    detailsShell.setLayout(new FillLayout());
                    StyledText textDetails = new StyledText(detailsShell, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
                    textDetails.setBackground(Colors.getSystemColor(display, SWT.COLOR_LIST_BACKGROUND));
                    textDetails.setForeground(Colors.getSystemColor(display, SWT.COLOR_LIST_FOREGROUND));
                    textDetails.setWordWrap(true);
                    textDetails.setText(sDetails);
                    detailsShell.layout();
                    Rectangle shellBounds = shell.getBounds();
                    int detailsWidth = Utils.adjustPXForDPI(DETAILS_WIDTH);
                    int detailsHeight = Utils.adjustPXForDPI(DETAILS_HEIGHT);
                    detailsShell.setBounds(shellBounds.x + shellBounds.width - detailsWidth, shellBounds.y - detailsHeight, detailsWidth, detailsHeight);
                    detailsShell.open();
                    shell.setData("detailsShell", detailsShell);
                    shell.addDisposeListener(new DisposeListener() {

                        @Override
                        public void widgetDisposed(DisposeEvent e) {
                            Shell detailsShell = (Shell) shell.getData("detailsShell");
                            if (detailsShell != null && !detailsShell.isDisposed()) {
                                detailsShell.dispose();
                            }
                        }
                    });
                    // disable auto-close on opening of details
                    bDelayPaused = true;
                    removeMouseTrackListener(shell, mouseAdapter);
                } else {
                    Shell detailsShell = (Shell) shell.getData("detailsShell");
                    if (detailsShell != null && !detailsShell.isDisposed()) {
                        detailsShell.dispose();
                    }
                }
            } catch (Exception e) {
                Logger.log(new LogEvent(LogIDs.GUI, "Mr. Slidey DetailsButton", e));
            }
        }
    });
    createLinkLabel(cShell, popupParams);
    lblCloseIn = new Label(cShell, SWT.TRAIL);
    lblCloseIn.setForeground(colorFG);
    // Ensure computeSize computes for 2 lined label
    lblCloseIn.setText(" \n ");
    gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
    gridData.horizontalSpan = 3;
    lblCloseIn.setLayoutData(gridData);
    final Composite cButtons = new Composite(cShell, SWT.NULL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    gridLayout.verticalSpacing = 0;
    if (Constants.isOSX)
        gridLayout.horizontalSpacing = 0;
    gridLayout.numColumns = (idxHistory > 0) ? 3 : 2;
    cButtons.setLayout(gridLayout);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
    gridData.horizontalSpan = 3;
    cButtons.setLayoutData(gridData);
    btnHideAll = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnHideAll, "popup.error.hideall");
    btnHideAll.setVisible(false);
    btnHideAll.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
    // XXX SWT.Selection doesn't work on latest GTK (2.8.17) & SWT3.2 for ON_TOP
    btnHideAll.addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            cButtons.setEnabled(false);
            shell.dispose();
        }
    });
    if (idxHistory > 0) {
        final Button btnPrev = new Button(cButtons, SWT.PUSH);
        btnPrev.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
        btnPrev.setText(MessageText.getString("popup.previous", new String[] { "" + idxHistory }));
        btnPrev.addListener(SWT.MouseUp, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                disposeShell(shell);
                int idx = historyList.indexOf(popupParams) - 1;
                if (idx >= 0) {
                    PopupParams item = historyList.get(idx);
                    showPopup(display, item, false);
                    disposeShell(shell);
                }
            }
        });
    }
    btnNext = new Button(cButtons, SWT.PUSH);
    btnNext.setForeground(Colors.getSystemColor(display, SWT.COLOR_BLACK));
    int numAfter = historyList.size() - idxHistory - 1;
    setButtonNextText(numAfter);
    btnNext.addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            if (DEBUG)
                System.out.println("Next Pressed");
            if (idxHistory + 1 < historyList.size()) {
                showPopup(display, historyList.get(idxHistory + 1), false);
            }
            disposeShell(shell);
        }
    });
    // Image has gap for text at the top (with image at bottom left)
    // trim top to height of shell
    Point bestSize = cShell.computeSize(shellWidth, SWT.DEFAULT);
    int minHeight = Utils.adjustPXForDPI(SHELL_MIN_HEIGHT);
    int maxHeight = Utils.adjustPXForDPI(SHELL_MAX_HEIGHT);
    if (bestSize.y < minHeight)
        bestSize.y = minHeight;
    else if (bestSize.y > maxHeight) {
        bestSize.y = maxHeight;
        if (sDetails == null) {
            sDetails = popupParams.text;
        } else {
            sDetails = popupParams.text + "\n===============\n" + sDetails;
        }
    }
    Rectangle bounds = null;
    try {
        UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
        if (uiFunctions != null) {
            Shell mainShell = uiFunctions.getMainShell();
            if (mainShell != null) {
                bounds = mainShell.getMonitor().getClientArea();
            }
        } else {
            Shell shell = display.getActiveShell();
            if (shell != null) {
                bounds = shell.getMonitor().getClientArea();
            }
        }
        if (bounds == null) {
            bounds = shell.getMonitor().getClientArea();
        }
    } catch (Exception e) {
    }
    if (bounds == null) {
        bounds = display.getClientArea();
    }
    Rectangle endBounds;
    if (bDisableSliding) {
        endBounds = new Rectangle(((bounds.x + bounds.width) / 2) - (bestSize.x / 2), ((bounds.y + bounds.height) / 2) - (bestSize.y / 2), bestSize.x, bestSize.y);
    } else {
        int boundsX2 = bounds.x + bounds.width;
        int boundsY2 = bounds.y + bounds.height;
        endBounds = shell.computeTrim(boundsX2 - bestSize.x, boundsY2 - bestSize.y, bestSize.x, bestSize.y);
        // bottom and right trim will be off the edge, calulate this trim
        // and adjust it up and left (trim may not be the same size on all sides)
        int diff = (endBounds.x + endBounds.width) - boundsX2;
        if (diff >= 0)
            endBounds.x -= diff + EDGE_GAP;
        diff = (endBounds.y + endBounds.height) - boundsY2;
        if (diff >= 0) {
            endBounds.y -= diff + EDGE_GAP;
        }
    // System.out.println("best" + bestSize + ";mon" + bounds + ";end" + endBounds);
    }
    FormData data = new FormData(bestSize.x, bestSize.y);
    cShell.setLayoutData(data);
    btnDetails.setVisible(sDetails != null);
    if (sDetails == null) {
        gridData = new GridData();
        gridData.widthHint = 0;
        btnDetails.setLayoutData(gridData);
    }
    shell.layout();
    btnNext.setFocus();
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            Utils.disposeSWTObjects(disposeList);
            if (currentPopupIndex == idxHistory) {
                if (DEBUG)
                    System.out.println("Clear #" + currentPopupIndex + "/" + idxHistory);
                try {
                    monitor.enter();
                    currentPopupIndex = -1;
                } finally {
                    monitor.exit();
                }
            }
        }
    });
    shell.addListener(SWT.Traverse, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE) {
                disposeShell(shell);
                event.doit = false;
            }
        }
    });
    if (mouseAdapter != null)
        addMouseTrackListener(shell, mouseAdapter);
    for (int i = 0; i < listeners.length; i++) {
        try {
            listeners[i].skinAfterComponents(shell, this, popupParams.relatedTo);
        } catch (Exception e) {
            Debug.out(e);
        }
    }
    int timeoutSecs;
    if (popupParams.timeoutSecs < 0) {
        timeoutSecs = COConfigurationManager.getIntParameter("Message Popup Autoclose in Seconds");
    } else {
        timeoutSecs = popupParams.timeoutSecs;
    }
    runPopup(endBounds, idxHistory, bSlide, timeoutSecs);
}
Also used : UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener) StyledText(org.eclipse.swt.custom.StyledText) LogEvent(com.biglybt.core.logging.LogEvent) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener) LogEvent(com.biglybt.core.logging.LogEvent)

Aggregations

UISkinnableSWTListener (com.biglybt.ui.swt.UISkinnableSWTListener)2 MessageText (com.biglybt.core.internat.MessageText)1 LogEvent (com.biglybt.core.logging.LogEvent)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 BrowserWrapper (com.biglybt.ui.swt.BrowserWrapper)1 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1 StyledText (org.eclipse.swt.custom.StyledText)1