Search in sources :

Example 6 with GCStringPrinter

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

the class ColorParameter method updateButtonColor.

private void updateButtonColor(final Display display, final int rV, final int gV, final int bV) {
    Image oldImg = img;
    img = new Image(display, 25, 10);
    GC gc = new GC(img);
    if (r >= 0 && g >= 0 && b >= 0) {
        Color color = ColorCache.getColor(display, rV, gV, bV);
        gc.setBackground(color);
        gc.fillRectangle(0, 0, 25, 10);
    } else {
        Color color = colorChooser.getBackground();
        gc.setBackground(color);
        gc.fillRectangle(0, 0, 25, 10);
        new GCStringPrinter(gc, "-", new Rectangle(0, 0, 25, 10), 0, SWT.CENTER).printString();
    }
    gc.dispose();
    colorChooser.setImage(img);
    if (oldImg != null && !oldImg.isDisposed())
        oldImg.dispose();
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 7 with GCStringPrinter

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

the class ColumnSearchSubResultActions method cellMouseTrigger.

@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    SearchSubsResultBase entry = (SearchSubsResultBase) event.cell.getDataSource();
    String tooltip = null;
    boolean invalidateAndRefresh = false;
    Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
    String text = (String) event.cell.getTableRow().getData("text");
    if (text == null) {
        return;
    }
    GCStringPrinter sp = null;
    GC gc = new GC(Display.getDefault());
    try {
        if (font != null) {
            gc.setFont(font);
        }
        Rectangle drawBounds = getDrawBounds((TableCellSWT) event.cell);
        sp = new GCStringPrinter(gc, text, drawBounds, true, true, SWT.WRAP | SWT.CENTER);
        sp.calculateMetrics();
    } catch (Exception e) {
        Debug.out(e);
    } finally {
        gc.dispose();
    }
    if (sp != null) {
        URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
        int newCursor;
        if (hitUrl != null) {
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP && event.button == 1) {
                if (hitUrl.url.equals("download")) {
                    SBC_SearchResultsView.downloadAction(entry);
                } else if (hitUrl.url.equals("details")) {
                    String details_url = entry.getDetailsLink();
                    try {
                        Utils.launch(new URL(details_url));
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            } else {
                if (hitUrl.url.equals("download")) {
                    tooltip = entry.getTorrentLink();
                } else if (hitUrl.url.equals("details")) {
                    tooltip = entry.getDetailsLink();
                }
            }
            newCursor = SWT.CURSOR_HAND;
        } else {
            newCursor = SWT.CURSOR_ARROW;
        }
        int oldCursor = ((TableCellSWT) event.cell).getCursorID();
        if (oldCursor != newCursor) {
            invalidateAndRefresh = true;
            ((TableCellSWT) event.cell).setCursorID(newCursor);
        }
    }
    Object o = event.cell.getToolTip();
    if ((o == null) || (o instanceof String)) {
        String oldTooltip = (String) o;
        if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
            invalidateAndRefresh = true;
            event.cell.setToolTip(tooltip);
        }
    }
    if (invalidateAndRefresh) {
        event.cell.invalidate();
        ((TableCellSWT) event.cell).redraw();
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) SearchSubsResultBase(com.biglybt.ui.swt.utils.SearchSubsResultBase) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) URL(java.net.URL)

Example 8 with GCStringPrinter

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

the class ViewQuickNotifications method initialize.

private void initialize(Composite parent) {
    parent.setLayout(new GridLayout());
    composite = new Composite(parent, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(composite, gridData);
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginRight = layout.marginTop = layout.marginBottom = 0;
    composite.setLayout(layout);
    // icon
    notification_icon = new Label(composite, SWT.NONE);
    gridData = new GridData();
    gridData.widthHint = 20;
    Utils.setLayoutData(notification_icon, gridData);
    // text
    notification_text = new Label(composite, SWT.DOUBLE_BUFFERED);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(notification_text, gridData);
    MouseAdapter listener = new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            UIFunctions uif = UIFunctionsManager.getUIFunctions();
            if (uif != null) {
                uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES);
            }
        }
    };
    // text
    more_text = new BufferedLabel(composite, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(more_text, gridData);
    notification_text.setData("");
    Control[] controls = { composite, notification_icon, notification_text, more_text.getControl() };
    for (Control c : controls) {
        c.addMouseListener(listener);
        Messages.setLanguageTooltip(c, "label.click.to.view.tooltip");
    }
    notification_text.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            String text = (String) notification_text.getData();
            int style = SWT.LEFT;
            Rectangle bounds = notification_text.getBounds();
            bounds.x = 4;
            bounds.y = 0;
            bounds.width -= 8;
            GCStringPrinter sp = new GCStringPrinter(e.gc, text, bounds, true, true, style);
            sp.calculateMetrics();
            sp.printString();
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) PaintEvent(org.eclipse.swt.events.PaintEvent) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) PaintListener(org.eclipse.swt.events.PaintListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) GridData(org.eclipse.swt.layout.GridData)

Example 9 with GCStringPrinter

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

the class ColumnSearchSubResultActions method cellPaint.

@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    SearchSubsResultBase entry = (SearchSubsResultBase) cell.getDataSource();
    if (entry == null) {
        return;
    }
    TableRow row = cell.getTableRow();
    if (row == null) {
        return;
    }
    String text = (String) row.getData("text");
    if (text != null && text.length() > 0) {
        if (font == null) {
            FontData[] fontData = gc.getFont().getFontData();
            fontData[0].setStyle(SWT.BOLD);
            font = new Font(gc.getDevice(), fontData);
        }
        gc.setFont(font);
        Rectangle bounds = getDrawBounds(cell);
        GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, true, true, SWT.WRAP | SWT.CENTER);
        sp.calculateMetrics();
        if (sp.hasHitUrl()) {
            URLInfo[] hitUrlInfo = sp.getHitUrlInfo();
            for (int i = 0; i < hitUrlInfo.length; i++) {
                URLInfo info = hitUrlInfo[i];
                // handle fake row when showing in column editor
                info.urlUnderline = cell.getTableRow() == null || cell.getTableRow().isSelected();
                if (info.urlUnderline) {
                    info.urlColor = null;
                } else {
                    info.urlColor = colorLinkNormal;
                }
            }
            int[] mouseOfs = cell.getMouseOffset();
            if (mouseOfs != null) {
                Rectangle realBounds = cell.getBounds();
                URLInfo hitUrl = sp.getHitUrl(mouseOfs[0] + realBounds.x, mouseOfs[1] + realBounds.y);
                if (hitUrl != null) {
                    hitUrl.urlColor = colorLinkHover;
                }
            }
        }
        sp.printString();
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) SearchSubsResultBase(com.biglybt.ui.swt.utils.SearchSubsResultBase) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)

Example 10 with GCStringPrinter

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

the class SystemWarningWindow method openWindow.

protected void openWindow() {
    Display display = parent.getDisplay();
    // shell = new Shell(parent, SWT.TOOL | SWT.TITLE | SWT.CLOSE);
    // shell.setText("Warning (X of X)");
    shell = new Shell(parent, SWT.TOOL);
    shell.setLayout(new FormLayout());
    shell.setBackground(Colors.getSystemColor(display, SWT.COLOR_INFO_BACKGROUND));
    shell.setForeground(Colors.getSystemColor(display, SWT.COLOR_INFO_FOREGROUND));
    Menu menu = new Menu(shell);
    MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(menuItem, "MyTorrentsView.menu.thisColumn.toClipboard");
    menuItem.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ClipboardCopy.copyToClipBoard(logAlert.text + (logAlert.details == null ? "" : "\n" + logAlert.details));
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    shell.setMenu(menu);
    ImageLoader imageLoader = ImageLoader.getInstance();
    imgClose = imageLoader.getImage("image.systemwarning.closeitem");
    boundsClose = imgClose.getBounds();
    GC gc = new GC(shell);
    FontData[] fontdata = gc.getFont().getFontData();
    fontdata[0].setHeight(fontdata[0].getHeight() + 1);
    fontdata[0].setStyle(SWT.BOLD);
    fontTitle = new Font(display, fontdata);
    fontdata = gc.getFont().getFontData();
    fontdata[0].setHeight(fontdata[0].getHeight() - 1);
    fontCount = new Font(display, fontdata);
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            Utils.disposeSWTObjects(new Object[] { fontTitle, fontCount });
            numWarningWindowsOpen--;
        }
    });
    Rectangle printArea = new Rectangle(BORDER_X, 0, WIDTH - (BORDER_X * 2), 5000);
    spText = new GCStringPrinter(gc, text, printArea, true, false, SWT.WRAP);
    spText.setUrlColor(Colors.blues[Colors.FADED_DARKEST]);
    spText.calculateMetrics();
    gc.setFont(fontCount);
    String sCount = MessageText.getString("label.xOfTotal", new String[] { "" + historyPosition + 1, "" + getWarningCount() });
    spCount = new GCStringPrinter(gc, sCount, printArea, true, false, SWT.WRAP);
    spCount.calculateMetrics();
    gc.setFont(fontTitle);
    spTitle = new GCStringPrinter(gc, title, printArea, true, false, SWT.WRAP);
    spTitle.calculateMetrics();
    gc.dispose();
    sizeText = spText.getCalculatedSize();
    sizeTitle = spTitle.getCalculatedSize();
    sizeCount = spCount.getCalculatedSize();
    FormData fd;
    Button btnDismiss = new Button(shell, SWT.PUSH);
    Messages.setLanguageText(btnDismiss, "Button.dismiss");
    final int btnHeight = btnDismiss.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    Button btnPrev = new Button(shell, SWT.PUSH);
    btnPrev.setText("<");
    Button btnNext = new Button(shell, SWT.PUSH);
    btnNext.setText(">");
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -BORDER_Y1);
    fd.right = new FormAttachment(100, -BORDER_X);
    btnNext.setLayoutData(fd);
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -BORDER_Y1);
    fd.right = new FormAttachment(btnNext, -BORDER_X);
    btnPrev.setLayoutData(fd);
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -BORDER_Y1);
    fd.right = new FormAttachment(btnPrev, -BORDER_X);
    btnDismiss.setLayoutData(fd);
    height = BORDER_Y0 + sizeTitle.y + GAP_Y + sizeText.y + GAP_Y_TITLE_COUNT + sizeCount.y + GAP_BUTTON_Y + btnHeight + BORDER_Y1;
    Rectangle area = shell.computeTrim(ptBottomRight.x - WIDTH, ptBottomRight.y - height, WIDTH, height);
    shell.setBounds(area);
    shell.setLocation(ptBottomRight.x - area.width, ptBottomRight.y - area.height - 2);
    rectX = new Rectangle(area.width - BORDER_X - boundsClose.width, BORDER_Y0, boundsClose.width, boundsClose.height);
    shell.addMouseMoveListener(new MouseMoveListener() {

        int lastCursor = SWT.CURSOR_ARROW;

        @Override
        public void mouseMove(MouseEvent e) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            URLInfo hitUrl = spText.getHitUrl(e.x, e.y);
            int cursor = (rectX.contains(e.x, e.y)) || hitUrl != null ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW;
            if (cursor != lastCursor) {
                lastCursor = cursor;
                shell.setCursor(e.display.getSystemCursor(cursor));
            }
        }
    });
    shell.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (shell == null || shell.isDisposed()) {
                return;
            }
            if (rectX.contains(e.x, e.y)) {
                shell.dispose();
            }
            URLInfo hitUrl = spText.getHitUrl(e.x, e.y);
            if (hitUrl != null) {
                if (hitUrl.url.equals("details")) {
                    MessageBoxShell mb = new MessageBoxShell(Constants.APP_NAME, logAlert.details, new String[] { MessageText.getString("Button.ok") }, 0);
                    mb.setUseTextBox(true);
                    mb.setParent(Utils.findAnyShell());
                    mb.open(null);
                } else {
                    Utils.launch(hitUrl.url);
                }
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    shell.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.drawImage(imgClose, WIDTH - BORDER_X - boundsClose.width, BORDER_Y0);
            Rectangle printArea;
            printArea = new Rectangle(BORDER_X, BORDER_Y0 + sizeTitle.y + GAP_Y_TITLE_COUNT, WIDTH, 100);
            String sCount = MessageText.getString("label.xOfTotal", new String[] { "" + (historyPosition + 1), "" + getWarningCount() });
            e.gc.setAlpha(180);
            Font lastFont = e.gc.getFont();
            e.gc.setFont(fontCount);
            spCount = new GCStringPrinter(e.gc, sCount, printArea, true, false, SWT.WRAP | SWT.TOP);
            spCount.printString();
            e.gc.setAlpha(255);
            sizeCount = spCount.getCalculatedSize();
            e.gc.setFont(lastFont);
            spText.printString(e.gc, new Rectangle(BORDER_X, BORDER_Y0 + sizeTitle.y + GAP_Y_TITLE_COUNT + sizeCount.y + GAP_Y, WIDTH - BORDER_X - BORDER_X, 5000), SWT.WRAP | SWT.TOP);
            e.gc.setFont(fontTitle);
            e.gc.setForeground(ColorCache.getColor(e.gc.getDevice(), "#54728c"));
            spTitle.printString(e.gc, new Rectangle(BORDER_X, BORDER_Y0, WIDTH - BORDER_X - BORDER_X, 5000), SWT.WRAP | SWT.TOP);
            e.gc.setLineStyle(SWT.LINE_DOT);
            e.gc.setLineWidth(1);
            e.gc.setAlpha(180);
            e.gc.drawLine(BORDER_X, height - btnHeight - (GAP_BUTTON_Y / 2) - BORDER_Y1, WIDTH - BORDER_X, height - btnHeight - (GAP_BUTTON_Y / 2) - BORDER_Y1);
        }
    });
    shell.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                shell.dispose();
                return;
            }
        }
    });
    btnPrev.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            int pos = historyPosition - 1;
            if (pos < 0 || pos >= alerts.size()) {
                return;
            }
            new SystemWarningWindow(alerts.get(pos), ptBottomRight, parent, pos);
            shell.dispose();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnPrev.setEnabled(historyPosition > 0);
    btnNext.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            int pos = historyPosition + 1;
            if (pos >= alerts.size()) {
                return;
            }
            new SystemWarningWindow(alerts.get(pos), ptBottomRight, parent, pos);
            shell.dispose();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
    btnNext.setEnabled(alerts.size() != historyPosition + 1);
    btnDismiss.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
            for (int i = 0; i < alerts.size() && i <= historyPosition; i++) {
                Alerts.markAlertAsViewed(alerts.get(i));
            }
            shell.dispose();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    shell.open();
    numWarningWindowsOpen++;
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) ArrayList(java.util.ArrayList) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) LogAlert(com.biglybt.core.logging.LogAlert) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Aggregations

GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)23 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Point (org.eclipse.swt.graphics.Point)5 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)4 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)4 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 GC (org.eclipse.swt.graphics.GC)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)2 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)2 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)2 SearchSubsResultBase (com.biglybt.ui.swt.utils.SearchSubsResultBase)2 URL (java.net.URL)2 EnhancedDownloadManager (com.biglybt.core.download.EnhancedDownloadManager)1 MessageText (com.biglybt.core.internat.MessageText)1 LogAlert (com.biglybt.core.logging.LogAlert)1 AERunnable (com.biglybt.core.util.AERunnable)1