Search in sources :

Example 1 with GCStringPrinter

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

the class ColumnTC_NameInfo method cellPaint.

// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.ui.swt.views.table.TableCellSWT)
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    TableColumnCore column = (TableColumnCore) cell.getDataSource();
    String raw_key = column.getTitleLanguageKey(false);
    String current_key = column.getTitleLanguageKey(true);
    Rectangle bounds = cell.getBounds();
    if (bounds == null || bounds.isEmpty()) {
        return;
    }
    Font fontDefault = gc.getFont();
    if (fontHeader == null) {
        FontData[] fontData = gc.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        fontData[0].setHeight(fontData[0].getHeight() + 1);
        fontHeader = new Font(gc.getDevice(), fontData);
    }
    gc.setFont(fontHeader);
    bounds.y += 3;
    bounds.x += 7;
    bounds.width -= 14;
    String name = MessageText.getString(raw_key, column.getName());
    if (!raw_key.equals(current_key)) {
        String rename = MessageText.getString(current_key, "");
        if (rename.length() > 0) {
            name += " (->" + rename + ")";
        }
    }
    GCStringPrinter sp = new GCStringPrinter(gc, name, bounds, GCStringPrinter.FLAG_SKIPCLIP, SWT.TOP);
    sp.printString();
    Point titleSize = sp.getCalculatedSize();
    gc.setFont(fontDefault);
    String info = MessageText.getString(raw_key + ".info", "");
    Rectangle infoBounds = new Rectangle(bounds.x + 10, bounds.y + titleSize.y + 5, bounds.width - 15, bounds.height - 20);
    GCStringPrinter.printString(gc, info, infoBounds, true, false);
    TableColumnInfo columnInfo = (TableColumnInfo) cell.getTableRow().getData("columninfo");
    if (columnInfo == null) {
        final TableColumnManager tcm = TableColumnManager.getInstance();
        columnInfo = tcm.getColumnInfo(column.getForDataSourceType(), column.getTableID(), column.getName());
        cell.getTableRowCore().setData("columninfo", columnInfo);
    }
    Rectangle profBounds = new Rectangle(bounds.width - 100, bounds.y - 2, 100, 20);
    byte proficiency = columnInfo.getProficiency();
    if (proficiency > 0 && proficiency < profText.length) {
        int alpha = gc.getAlpha();
        gc.setAlpha(0xA0);
        GCStringPrinter.printString(gc, MessageText.getString("ConfigView.section.mode." + profText[proficiency]), profBounds, true, false, SWT.RIGHT | SWT.TOP);
        gc.setAlpha(alpha);
    }
    Rectangle hitArea;
    TableView<?> tv = ((TableCellCore) cell).getTableRowCore().getView();
    TableColumnSetupWindow tvs = (TableColumnSetupWindow) tv.getParentDataSource();
    if (tvs.isColumnAdded(column)) {
        hitArea = Utils.EMPTY_RECT;
    } else {
        int x = bounds.x + titleSize.x + 15;
        int y = bounds.y - 1;
        int h = 15;
        String textAdd = MessageText.getString("Button.add");
        GCStringPrinter sp2 = new GCStringPrinter(gc, textAdd, new Rectangle(x, y, 500, h), true, false, SWT.CENTER);
        sp2.calculateMetrics();
        int w = sp2.getCalculatedSize().x + 12;
        gc.setAdvanced(true);
        gc.setAntialias(SWT.ON);
        gc.setBackground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
        gc.fillRoundRectangle(x, y, w, h, 15, h);
        gc.setBackground(ColorCache.getColor(gc.getDevice(), 215, 215, 215));
        gc.fillRoundRectangle(x + 2, y + 2, w, h, 15, h);
        gc.setForeground(ColorCache.getColor(gc.getDevice(), 145, 145, 145));
        gc.drawRoundRectangle(x, y, w, h, 15, h);
        gc.setForeground(ColorCache.getColor(gc.getDevice(), 50, 50, 50));
        hitArea = new Rectangle(x, y, w + 2, h);
        sp2.printString(gc, hitArea, SWT.CENTER);
        bounds = cell.getBounds();
        hitArea.x -= bounds.x;
        hitArea.y -= bounds.y;
    }
    cell.getTableRowCore().setData("AddHitArea", hitArea);
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 2 with GCStringPrinter

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

the class FakeTableCell method doPaint.

public void doPaint(GC gc, Rectangle bounds) {
    if (isDisposed()) {
        return;
    }
    // }
    if (bounds == null) {
        return;
    }
    // gc.fillRectangle(bounds);
    if (!bounds.intersects(gc.getClipping())) {
        return;
    }
    if (image != null && !image.isDisposed()) {
        Point size = new Point(bounds.width, bounds.height);
        int x;
        int y = marginHeight;
        y += (size.y - imageBounds.height) / 2;
        if (orientation == SWT.CENTER) {
            x = marginWidth;
            x += (size.x - (marginWidth * 2) - imageBounds.width) / 2;
        } else if (orientation == SWT.RIGHT) {
            x = bounds.width - marginWidth - imageBounds.width;
        } else {
            x = marginWidth;
        }
        int width = Math.min(bounds.width - x - marginWidth, imageBounds.width);
        int height = Math.min(bounds.height - y - marginHeight, imageBounds.height);
        if (width >= 0 && height >= 0) {
            gc.drawImage(image, 0, 0, width, height, bounds.x + x, bounds.y + y, width, height);
        }
    }
    if (text != null && text.length() > 0) {
        GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, true, false, wrapText ? (orientation | SWT.WRAP) : orientation);
        sp.printString();
        hadMore = sp.isCutoff();
    }
    invokeSWTPaintListeners(gc);
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter)

Example 3 with GCStringPrinter

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

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

the class ColumnActivityText method setupStringPrinter.

private GCStringPrinter setupStringPrinter(GC gc, TableCellSWT cell) {
    ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource();
    String text = entry.getText();
    Rectangle drawBounds = getDrawBounds(cell);
    entry.setViewed();
    if (!entry.isRead()) {
        if (font == null) {
            FontData[] fontData = gc.getFont().getFontData();
            fontData[0].setStyle(SWT.BOLD);
            font = new Font(gc.getDevice(), fontData);
        }
        gc.setFont(font);
    }
    int style = SWT.WRAP;
    GCStringPrinter sp = new GCStringPrinter(gc, text, drawBounds, true, true, style);
    sp.calculateMetrics();
    return sp;
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry)

Example 5 with GCStringPrinter

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

the class ColumnProgressETA method cellPaint.

// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.ui.swt.views.table.TableCellSWT)
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        TableRowCore row = cell.getTableRowCore();
        if (row != null) {
            fileProgress.fillInfoProgressETA(row, gc, (DiskManagerFileInfo) ds, cell.getBounds());
        }
        return;
    }
    if (!(ds instanceof DownloadManager)) {
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    String tooltip = null;
    if (dm.getState() == DownloadManager.STATE_QUEUED) {
        tooltip = MessageText.getString("ManagerItem.queued.tooltip");
    }
    int percentDone = getPercentDone(ds);
    long eta = showETA ? getETA(cell) : 0;
    // Compute bounds ...
    int newWidth = cell.getWidth();
    if (newWidth <= 0) {
        return;
    }
    int newHeight = cell.getHeight();
    Color fgFirst = gc.getForeground();
    final Color fgOriginal = fgFirst;
    Rectangle cellBounds = cell.getBounds();
    int xStart = cellBounds.x;
    int yStart = cellBounds.y;
    int xRelProgressFillStart = borderWidth;
    int yRelProgressFillStart = borderWidth;
    int xRelProgressFillEnd = newWidth - xRelProgressFillStart - borderWidth;
    int yRelProgressFillEnd = yRelProgressFillStart + 13;
    boolean showSecondLine = yRelProgressFillEnd + 10 < newHeight;
    if (xRelProgressFillEnd < 10) {
        return;
    }
    String sStatusLine = null;
    // Draw Progress bar
    // ImageLoader imageLoader = ImageLoader.getInstance();
    Rectangle boundsImgBG;
    if (!ImageLoader.isRealImage(imgBGTorrent)) {
        boundsImgBG = new Rectangle(0, 0, 0, 13);
    } else {
        boundsImgBG = imgBGTorrent.getBounds();
    }
    if (fontText == null) {
        fontText = FontUtils.getFontWithHeight(gc.getFont(), gc, boundsImgBG.height - 3);
    }
    if (!showSecondLine) {
        yRelProgressFillStart = (cellBounds.height / 2) - ((boundsImgBG.height) / 2);
    }
    yRelProgressFillEnd = yRelProgressFillStart + boundsImgBG.height;
    int progressWidth = newWidth - 1;
    gc.setForeground(cBorder);
    gc.drawRectangle(xStart + xRelProgressFillStart - 1, yStart + yRelProgressFillStart - 1, progressWidth + 1, boundsImgBG.height + 1);
    int pctWidth = (int) (percentDone * (progressWidth) / 1000);
    gc.setBackground(percentDone == 1000 || dm.isDownloadComplete(false) ? cBGcd : cBGdl);
    gc.fillRectangle(xStart + xRelProgressFillStart, yStart + yRelProgressFillStart, pctWidth, boundsImgBG.height);
    if (progressWidth > pctWidth) {
        gc.setBackground(Colors.white);
        gc.fillRectangle(xStart + xRelProgressFillStart + pctWidth, yStart + yRelProgressFillStart, progressWidth - pctWidth, boundsImgBG.height);
    }
    if (boundsImgBG.width > 0) {
        gc.drawImage(imgBGTorrent, 0, 0, boundsImgBG.width, boundsImgBG.height, xStart + xRelProgressFillStart, yStart + yRelProgressFillStart, progressWidth, boundsImgBG.height);
    }
    if (sStatusLine == null) {
        if (dm.isUnauthorisedOnTracker()) {
            sStatusLine = dm.getTrackerStatus();
        // fgFirst = Colors.colorError;	pftt, no colours allowed apparently
        } else {
            if (showETA && eta > 0) {
                String sETA = ViewUtils.formatETA(eta, progress_eta_absolute, cdf.getDateFormat());
                sStatusLine = MessageText.getString("MyTorrents.column.ColumnProgressETA.2ndLine", new String[] { sETA });
            } else {
                sStatusLine = DisplayFormatters.formatDownloadStatus(dm).toUpperCase();
            }
        }
        int cursor_id;
        if (sStatusLine != null && !sStatusLine.contains("http://")) {
            dm.setUserData(CLICK_KEY, null);
            cursor_id = SWT.CURSOR_ARROW;
        } else {
            dm.setUserData(CLICK_KEY, sStatusLine);
            cursor_id = SWT.CURSOR_HAND;
            if (!cell.getTableRow().isSelected()) {
                fgFirst = Colors.blue;
            }
        }
        ((TableCellSWT) cell).setCursorID(cursor_id);
    }
    gc.setTextAntialias(SWT.ON);
    gc.setFont(fontText);
    if (showSecondLine && sStatusLine != null) {
        gc.setForeground(fgFirst);
        boolean fit = GCStringPrinter.printString(gc, sStatusLine, new Rectangle(cellBounds.x, yStart + yRelProgressFillEnd, cellBounds.width, newHeight - yRelProgressFillEnd), true, false, SWT.CENTER);
        if (!fit) {
            if (tooltip == null) {
                tooltip = sStatusLine;
            } else {
                tooltip = sStatusLine + ": " + tooltip;
            }
        }
        gc.setForeground(fgOriginal);
    }
    String sSpeed = "";
    if (showSpeed) {
        long lSpeed = getSpeed(ds);
        if (lSpeed > 0) {
            sSpeed = " (" + DisplayFormatters.formatByteCountToKiBEtcPerSec(lSpeed, true) + ")";
        }
    }
    String sPercent = DisplayFormatters.formatPercentFromThousands(percentDone);
    Rectangle area = new Rectangle(xStart + xRelProgressFillStart + 3, yStart + yRelProgressFillStart, xRelProgressFillEnd - xRelProgressFillStart - 6, yRelProgressFillEnd - yRelProgressFillStart);
    GCStringPrinter sp = new GCStringPrinter(gc, sPercent + sSpeed, area, true, false, SWT.LEFT);
    if (cTextDrop != null) {
        area.x++;
        area.y++;
        gc.setForeground(cTextDrop);
        sp.printString();
        area.x--;
        area.y--;
    }
    gc.setForeground(cText);
    sp.printString();
    Point pctExtent = sp.getCalculatedSize();
    area.width -= (pctExtent.x + 3);
    area.x += (pctExtent.x + 3);
    if (!showSecondLine && sStatusLine != null) {
        boolean fit = GCStringPrinter.printString(gc, sStatusLine, area.intersection(cellBounds), true, false, SWT.RIGHT);
        if (!fit) {
            if (tooltip == null) {
                tooltip = sStatusLine;
            } else {
                tooltip = sStatusLine + ": " + tooltip;
            }
        }
    }
    cell.setToolTip(tooltip);
    gc.setFont(null);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) DownloadManager(com.biglybt.core.download.DownloadManager) EnhancedDownloadManager(com.biglybt.core.download.EnhancedDownloadManager) TableRowCore(com.biglybt.ui.common.table.TableRowCore)

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