Search in sources :

Example 6 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.

the class StatusItem method refresh.

@Override
public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm == null) {
        return;
    }
    int state = dm.getState();
    long sort_value;
    String text;
    String tooltip = null;
    if (showTrackerErrors && dm.isUnauthorisedOnTracker() && state != DownloadManager.STATE_ERROR) {
        text = dm.getTrackerStatus();
        sort_value = 1100;
    } else {
        text = DisplayFormatters.formatDownloadStatus(dm);
        if (dm.isForceStart() && (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING)) {
            sort_value = 1000;
        } else {
            switch(state) {
                case DownloadManager.STATE_SEEDING:
                    {
                        sort_value = 900;
                        break;
                    }
                case DownloadManager.STATE_DOWNLOADING:
                    {
                        sort_value = 800;
                        break;
                    }
                case DownloadManager.STATE_QUEUED:
                    {
                        sort_value = 700;
                        tooltip = MessageText.getString("ManagerItem.queued.tooltip");
                        break;
                    }
                case DownloadManager.STATE_STOPPED:
                    {
                        if (dm.isPaused()) {
                            sort_value = 600;
                        } else {
                            sort_value = 500;
                        }
                        break;
                    }
                default:
                    {
                        sort_value = 0;
                    }
            }
        }
    }
    sort_value += state;
    sort_value <<= 32;
    if (dm.isDownloadComplete(false)) {
        Download dl = PluginCoreUtils.wrap(dm);
        if (dl != null) {
            sort_value += dl.getSeedingRank();
        }
    } else {
        sort_value -= dm.getPosition();
    }
    boolean update;
    if (priority_sort) {
        update = cell.setSortValue(sort_value);
        if (!update) {
            if (!cell.getText().equals(text)) {
                update = true;
            }
        }
    } else {
        update = cell.setSortValue(text);
    }
    if (update || !cell.isValid()) {
        cell.setText(text);
        cell.setToolTip(tooltip);
        boolean clickable = false;
        if (cell instanceof TableCellSWT) {
            int cursor_id;
            if (!text.contains("http://")) {
                dm.setUserData(CLICK_KEY, null);
                cursor_id = SWT.CURSOR_ARROW;
            } else {
                dm.setUserData(CLICK_KEY, text);
                cursor_id = SWT.CURSOR_HAND;
                clickable = true;
            }
            ((TableCellSWT) cell).setCursorID(cursor_id);
        }
        if (!changeCellFG && !changeRowFG) {
            // clickable, make it blue whatever
            cell.setForeground(clickable ? BLUE : null);
            return;
        }
        TableRow row = cell.getTableRow();
        if (row != null) {
            Color color = null;
            if (state == DownloadManager.STATE_SEEDING) {
                color = Colors.blues[Colors.BLUES_MIDDARK];
            } else if (state == DownloadManager.STATE_ERROR) {
                color = Colors.colorError;
            } else {
                color = null;
            }
            if (changeRowFG) {
                row.setForeground(Utils.colorToIntArray(color));
            } else if (changeCellFG) {
                cell.setForeground(Utils.colorToIntArray(color));
            }
            if (clickable) {
                cell.setForeground(Utils.colorToIntArray(Colors.blue));
            }
        }
    }
}
Also used : TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Color(org.eclipse.swt.graphics.Color) DownloadManager(com.biglybt.core.download.DownloadManager) Download(com.biglybt.pif.download.Download)

Example 7 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.

the class SizeItem method refresh.

@Override
public void refresh(TableCell cell) {
    sizeitemsort value;
    Object ds = cell.getDataSource();
    if (ds instanceof DownloadManager) {
        DownloadManager dm = (DownloadManager) ds;
        value = new sizeitemsort(dm.getStats().getSizeExcludingDND(), dm.getStats().getRemainingExcludingDND());
    } else if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        value = new sizeitemsort(fileInfo.getLength(), fileInfo.getLength() - fileInfo.getDownloaded());
    } else {
        return;
    }
    // I'm afraid something will break.. so use compareTo
    if (value.compareTo(cell.getSortValue()) == 0 && cell.isValid())
        return;
    cell.setSortValue(value);
    String s = DisplayFormatters.formatCustomSize("column.size", value.size);
    if (s == null) {
        s = DisplayFormatters.formatByteCountToKiBEtc(value.size);
    }
    if (DO_MULTILINE && cell.getMaxLines() > 1 && value.remaining > 0) {
        s += "\n" + DisplayFormatters.formatByteCountToKiBEtc(value.remaining, false, false, 0) + " " + MessageText.getString("TableColumn.header.remaining");
    }
    cell.setText(s);
    if (Utils.getUserMode() > 0 && (cell instanceof TableCellSWT)) {
        if (value.size >= 0x40000000l) {
            ((TableCellSWT) cell).setTextAlpha(200 | 0x100);
        } else if (value.size < 0x100000) {
            ((TableCellSWT) cell).setTextAlpha(180);
        } else {
            ((TableCellSWT) cell).setTextAlpha(255);
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 8 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.

the class NameItem method refresh.

@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
    String name = null;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm != null)
        name = dm.getDisplayName();
    if (name == null)
        name = "";
    // setText returns true only if the text is updated
    if ((cell.setText(name) || !cell.isValid())) {
        if (dm != null && isShowIcon() && !sortOnlyRefresh && (cell instanceof TableCellSWT)) {
            DiskManagerFileInfo fileInfo = dm.getDownloadState().getPrimaryFile();
            if (fileInfo != null) {
                // Don't ever dispose of PathIcon, it's cached and may be used elsewhere
                TOTorrent torrent = dm.getTorrent();
                Image icon = ImageRepository.getPathIcon(fileInfo.getFile(false).getName(), false, torrent != null && !torrent.isSimpleTorrent());
                ((TableCellSWT) cell).setIcon(icon);
            }
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TOTorrent(com.biglybt.core.torrent.TOTorrent) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 9 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT in project BiglyBT by BiglySoftware.

the class NameItem method refresh.

@Override
public void refresh(TableCell cell) {
    TRHostTorrent item = (TRHostTorrent) cell.getDataSource();
    String name = (item == null) ? "" : TorrentUtils.getLocalisedName(item.getTorrent());
    if (cell.setText(name) || !cell.isValid()) {
        if (item != null && item.getTorrent() != null && bShowIcon && (cell instanceof TableCellSWT)) {
            try {
                final TOTorrent torrent = item.getTorrent();
                final String path = torrent.getFiles()[0].getRelativePath();
                if (path != null) {
                    Image icon = null;
                    final TableCellSWT _cell = (TableCellSWT) cell;
                    if (Utils.isSWTThread()) {
                        icon = ImageRepository.getPathIcon(path, false, !torrent.isSimpleTorrent());
                    } else {
                        // happens rarely (seen of filtering of file-view rows
                        // when a new row is added )
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                Image icon = ImageRepository.getPathIcon(path, false, !torrent.isSimpleTorrent());
                                _cell.setIcon(icon);
                                _cell.redraw();
                            }
                        });
                    }
                    if (icon != null) {
                        _cell.setIcon(icon);
                    }
                }
            } catch (Exception e) {
            }
        }
    }
}
Also used : TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TOTorrent(com.biglybt.core.torrent.TOTorrent) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) Image(org.eclipse.swt.graphics.Image)

Example 10 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT 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

TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)21 Image (org.eclipse.swt.graphics.Image)9 DownloadManager (com.biglybt.core.download.DownloadManager)7 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 Download (com.biglybt.pif.download.Download)4 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)4 GC (org.eclipse.swt.graphics.GC)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Graphic (com.biglybt.pif.ui.Graphic)3 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)3 UISWTGraphicImpl (com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl)3 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)3 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)2 AERunnable (com.biglybt.core.util.AERunnable)2 TableCell (com.biglybt.pif.ui.tables.TableCell)2 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)2 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)2 TableManager (com.biglybt.pif.ui.tables.TableManager)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2