Search in sources :

Example 1 with URLInfo

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

the class ColumnActivityText method cellPaint.

// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.pif.ui.tables.TableCell)
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    GCStringPrinter sp = setupStringPrinter(gc, cell);
    if (sp.hasHitUrl()) {
        URLInfo[] hitUrlInfo = sp.getHitUrlInfo();
        for (int i = 0; i < hitUrlInfo.length; i++) {
            URLInfo info = hitUrlInfo[i];
            info.urlUnderline = 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();
    gc.setFont(null);
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)

Example 2 with URLInfo

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

the class RemotePairingWindow method _open.

private void _open() {
    alreadyTested = false;
    pairingManager = PairingManagerFactory.getSingleton();
    PluginInterface piWebUI = getWebUI();
    boolean showFTUX = piWebUI == null || !pairingManager.isEnabled();
    if (skinnedDialog == null || skinnedDialog.isDisposed()) {
        skinnedDialog = new SkinnedDialog("skin3_dlg_remotepairing", "shell", SWT.DIALOG_TRIM);
        skin = skinnedDialog.getSkin();
        soCodeArea = skin.getSkinObject("code-area");
        control = soCodeArea.getControl();
        soEnablePairing = (SWTSkinObjectButton) skin.getSkinObject("enable-pairing");
        soEnablePairing.addSelectionListener(new ButtonListenerAdapter() {

            // @see SWTSkinButtonUtility.ButtonListenerAdapter#pressed(SWTSkinButtonUtility, SWTSkinObject, int)
            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                skinObject.getControl().setEnabled(false);
                if (!pairingManager.isEnabled()) {
                    // enabling will automatically get access code and trigger
                    // somethingChanged
                    pairingManager.setEnabled(true);
                    if (SHOW_SPEW) {
                        System.out.println("PAIR] SetEnabled");
                    }
                } else {
                    // picked up
                    if (SHOW_SPEW) {
                        System.out.println("PAIR] AlreadyEnabled");
                    }
                    somethingChanged(pairingManager);
                }
                if (getWebUI() == null) {
                    installWebUI();
                } else {
                    switchToCode();
                }
            }
        });
        soFTUX = skin.getSkinObject("pairing-ftux");
        soCode = skin.getSkinObject("pairing-code");
        soQR = (SWTSkinObjectImage) skin.getSkinObject("pairing-qr");
        if (accessCode != null) {
            setupQR(accessCode);
        }
        soStatusText = (SWTSkinObjectText) skin.getSkinObject("status-text");
        soStatusText.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {

            @Override
            public boolean urlClicked(URLInfo urlInfo) {
                if (urlInfo.url.equals("retry")) {
                    if (DEBUG) {
                        testPairingClass.inc();
                    }
                    alreadyTested = false;
                    testPairing(false);
                    return true;
                }
                return false;
            }
        });
        pairingManager.addListener(this);
        Font font = control.getFont();
        GC gc = new GC(control);
        fontCode = FontUtils.getFontWithHeight(font, gc, Constants.isWindows ? 20 : 18, SWT.BOLD);
        gc.dispose();
        control.setFont(fontCode);
        control.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                Color oldColor = e.gc.getForeground();
                Rectangle printArea = ((Composite) e.widget).getClientArea();
                printArea.y += 10;
                printArea.height -= 20;
                int fullWidth = printArea.width;
                int fullHeight = printArea.height;
                GCStringPrinter sp = new GCStringPrinter(e.gc, MessageText.getString("remote.pairing.accesscode"), printArea, false, false, SWT.NONE);
                sp.calculateMetrics();
                Point sizeAccess = sp.getCalculatedSize();
                String drawAccessCode = accessCode == null ? "      " : accessCode;
                int numBoxes = drawAccessCode.length();
                int boxSize = 25;
                int boxSizeAndPadding = 30;
                int allBoxesWidth = numBoxes * boxSizeAndPadding;
                int textPadding = 15;
                printArea.y = (fullHeight - boxSizeAndPadding - sizeAccess.y + textPadding) / 2;
                sp.printString(e.gc, printArea, SWT.CENTER | SWT.TOP);
                e.gc.setBackground(Colors.white);
                e.gc.setForeground(Colors.blue);
                int xStart = (fullWidth - allBoxesWidth) / 2;
                int yStart = printArea.y + sizeAccess.y + textPadding;
                for (int i = 0; i < numBoxes; i++) {
                    Rectangle r = new Rectangle(xStart + (i * boxSizeAndPadding), yStart, boxSize, boxSize);
                    e.gc.fillRectangle(r);
                    e.gc.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
                    e.gc.drawRectangle(r);
                    if (isCodeVisible()) {
                        e.gc.setForeground(oldColor);
                        GCStringPrinter.printString(e.gc, "" + drawAccessCode.charAt(i), r, false, false, SWT.CENTER);
                    }
                }
            }
        });
        soToClipboard = (SWTSkinObjectText) skin.getSkinObject("pair-clipboard");
        soToClipboard.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {

            @Override
            public boolean urlClicked(URLInfo urlInfo) {
                if (urlInfo.url.equals("new")) {
                    try {
                        accessCode = pairingManager.getReplacementAccessCode();
                    } catch (PairingException e) {
                    // ignore.. if error, lastErrorUpdates will trigger
                    }
                    control.redraw();
                    setupQR(accessCode);
                    String s = soToClipboard.getText();
                    int i = s.indexOf("|");
                    if (i > 0) {
                        soToClipboard.setText(s.substring(0, i - 1));
                    }
                } else if (urlInfo.url.equals("clip")) {
                    ClipboardCopy.copyToClipBoard(accessCode);
                }
                return true;
            }
        });
        SWTSkinButtonUtility btnToClipboard = new SWTSkinButtonUtility(soToClipboard);
        btnToClipboard.addSelectionListener(new ButtonListenerAdapter() {

            @Override
            public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
            }
        });
        skinnedDialog.addCloseListener(new SkinnedDialogClosedListener() {

            @Override
            public void skinDialogClosed(SkinnedDialog dialog) {
                skinnedDialog = null;
                pairingManager.removeListener(RemotePairingWindow.this);
                Utils.disposeSWTObjects(new Object[] { fontCode });
                if (pairingTest != null) {
                    pairingTest.cancel();
                }
            }
        });
        if (showFTUX) {
            soFTUX.getControl().moveAbove(null);
        }
    }
    setCodeVisible(false);
    skinnedDialog.open();
    if (showFTUX) {
        switchToFTUX();
    } else {
        switchToCode();
    }
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) PluginInterface(com.biglybt.pif.PluginInterface) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) ButtonListenerAdapter(com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) SkinnedDialogClosedListener(com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)

Example 3 with URLInfo

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

the class MessageBoxShell method createLinkLabel.

private Canvas createLinkLabel(final Composite shell, final String text) {
    final Canvas canvas = new Canvas(shell, SWT.None) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle area = new Rectangle(0, 0, wHint < 0 ? max_size_x : wHint, 5000);
            GC gc = new GC(this);
            GCStringPrinter sp = new GCStringPrinter(gc, text, area, true, false, SWT.WRAP | SWT.TOP);
            sp.calculateMetrics();
            gc.dispose();
            Point size = sp.getCalculatedSize();
            return size;
        }
    };
    Listener l = new Listener() {

        GCStringPrinter sp;

        @Override
        public void handleEvent(Event e) {
            if (!handleHTML) {
                if (e.type == SWT.Paint) {
                    Rectangle area = canvas.getClientArea();
                    e.gc.setForeground(shell.getForeground());
                    GCStringPrinter.printString(e.gc, text, area, true, false, SWT.WRAP | SWT.TOP);
                }
                return;
            }
            if (e.type == SWT.Paint) {
                Rectangle area = canvas.getClientArea();
                sp = new GCStringPrinter(e.gc, text, area, true, false, SWT.WRAP | SWT.TOP);
                sp.setUrlColor(ColorCache.getColor(e.gc.getDevice(), "#0000ff"));
                if (urlColor != null) {
                    sp.setUrlColor(urlColor);
                }
                e.gc.setForeground(shell.getForeground());
                sp.printString();
            } else if (e.type == SWT.MouseMove) {
                if (sp != null) {
                    URLInfo hitUrl = sp.getHitUrl(e.x, e.y);
                    if (hitUrl != null) {
                        canvas.setCursor(canvas.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                        canvas.setToolTipText(hitUrl.url);
                    } else {
                        canvas.setCursor(canvas.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
                        canvas.setToolTipText(null);
                    }
                }
            } else if (e.type == SWT.MouseUp) {
                if (sp != null) {
                    URLInfo hitUrl = sp.getHitUrl(e.x, e.y);
                    if (hitUrl != null && !hitUrl.url.startsWith(":")) {
                        Utils.launch(hitUrl.url);
                    }
                }
            }
        }
    };
    canvas.addListener(SWT.Paint, l);
    if (handleHTML) {
        canvas.addListener(SWT.MouseMove, l);
        canvas.addListener(SWT.MouseUp, l);
    }
    ClipboardCopy.addCopyToClipMenu(canvas, new ClipboardCopy.copyToClipProvider() {

        @Override
        public String getText() {
            return (text);
        }
    });
    return canvas;
}
Also used : UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy)

Example 4 with URLInfo

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

the class MessageSlideShell method createLinkLabel.

/**
 * @param shell2
 * @param b
 *
 * @since 3.0.0.9
 */
private void createLinkLabel(Composite shell, final PopupParams popupParams) {
    final Canvas canvas = new Canvas(shell, SWT.None) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle area = new Rectangle(0, 0, shellWidth, 5000);
            GC gc = new GC(this);
            GCStringPrinter sp = new GCStringPrinter(gc, popupParams.text, area, true, false, SWT.WRAP | SWT.TOP);
            sp.calculateMetrics();
            gc.dispose();
            Point size = sp.getCalculatedSize();
            return size;
        }
    };
    Listener l = new Listener() {

        GCStringPrinter sp;

        @Override
        public void handleEvent(Event e) {
            if (e.type == SWT.Paint) {
                Rectangle area = canvas.getClientArea();
                sp = new GCStringPrinter(e.gc, popupParams.text, area, true, false, SWT.WRAP | SWT.TOP);
                sp.setUrlColor(ColorCache.getColor(e.gc.getDevice(), "#0000ff"));
                if (colorURL != null) {
                    sp.setUrlColor(colorURL);
                }
                if (colorFG != null) {
                    e.gc.setForeground(colorFG);
                }
                sp.printString();
            } else if (e.type == SWT.MouseMove) {
                if (sp != null) {
                    URLInfo hitUrl = sp.getHitUrl(e.x, e.y);
                    if (hitUrl != null) {
                        canvas.setCursor(canvas.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                        canvas.setToolTipText(hitUrl.url);
                    } else {
                        canvas.setCursor(canvas.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
                        canvas.setToolTipText(null);
                    }
                }
            } else if (e.type == SWT.MouseUp) {
                if (sp != null) {
                    URLInfo hitUrl = sp.getHitUrl(e.x, e.y);
                    if (hitUrl != null && !hitUrl.url.startsWith(":")) {
                        Utils.launch(hitUrl.url);
                    }
                }
            }
        }
    };
    canvas.addListener(SWT.Paint, l);
    canvas.addListener(SWT.MouseMove, l);
    canvas.addListener(SWT.MouseUp, l);
    ClipboardCopy.addCopyToClipMenu(canvas, new ClipboardCopy.copyToClipProvider() {

        @Override
        public String getText() {
            return (popupParams.title + "\n\n" + popupParams.text);
        }
    });
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    canvas.setLayoutData(gridData);
}
Also used : UISkinnableSWTListener(com.biglybt.ui.swt.UISkinnableSWTListener) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy) LogEvent(com.biglybt.core.logging.LogEvent)

Example 5 with URLInfo

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

Aggregations

URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)11 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)8 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)3 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)3 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 UISkinnableSWTListener (com.biglybt.ui.swt.UISkinnableSWTListener)2 ClipboardCopy (com.biglybt.ui.swt.mainwindow.ClipboardCopy)2 SearchSubsResultBase (com.biglybt.ui.swt.utils.SearchSubsResultBase)2 LogAlert (com.biglybt.core.logging.LogAlert)1 LogEvent (com.biglybt.core.logging.LogEvent)1 PluginInterface (com.biglybt.pif.PluginInterface)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 ButtonListenerAdapter (com.biglybt.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter)1 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)1 SkinnedDialogClosedListener (com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1