Search in sources :

Example 6 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.

the class TableRowPainted method buildCells.

private void buildCells() {
    // debug("buildCells " + Debug.getCompressedStackTrace());
    TableColumnCore[] visibleColumns = getView().getVisibleColumns();
    if (visibleColumns == null) {
        return;
    }
    synchronized (lock) {
        mTableCells = new LinkedHashMap<>(visibleColumns.length, 1);
        TableColumn currentSortColumn = null;
        if (cellSort != null) {
            currentSortColumn = cellSort.getTableColumn();
        }
        TableRowCore parentRow = getParentRowCore();
        // create all the cells for the column
        for (int i = 0; i < visibleColumns.length; i++) {
            if (visibleColumns[i] == null) {
                continue;
            }
            if (parentRow != null && !visibleColumns[i].handlesDataSourceType(getDataSource(false).getClass())) {
                mTableCells.put(visibleColumns[i].getName(), null);
                continue;
            }
            // System.out.println(dataSource + ": " + tableColumns[i].getName() + ": " + tableColumns[i].getPosition());
            TableCellCore cell = (currentSortColumn != null && visibleColumns[i].equals(currentSortColumn)) ? cellSort : new TableCellPainted(TableRowPainted.this, visibleColumns[i], i);
            mTableCells.put(visibleColumns[i].getName(), cell);
        // if (i == 10) cell.bDebug = true;
        }
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) TableCellCore(com.biglybt.ui.common.table.TableCellCore) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Example 7 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.

the class TableColumnImpl method compare.

// @see java.util.Comparator#compare(T, T)
@Override
public int compare(Object arg0, Object arg1) {
    TableCellCore cell0 = ((TableRowCore) arg0).getTableCellCore(sName);
    TableCellCore cell1 = ((TableRowCore) arg1).getTableCellCore(sName);
    Comparable c0 = (cell0 == null) ? "" : cell0.getSortValue();
    Comparable c1 = (cell1 == null) ? "" : cell1.getSortValue();
    // Put nulls and empty strings at bottom.
    boolean c0_is_null = (c0 == null || c0.equals(""));
    boolean c1_is_null = (c1 == null || c1.equals(""));
    if (c1_is_null) {
        return (c0_is_null) ? 0 : -1;
    } else if (c0_is_null) {
        return 1;
    }
    try {
        boolean c0isString = c0 instanceof String;
        boolean c1isString = c1 instanceof String;
        if (c0isString && c1isString) {
            if (bSortAscending) {
                return ((String) c0).compareToIgnoreCase((String) c1);
            }
            return ((String) c1).compareToIgnoreCase((String) c0);
        }
        int val;
        if (c0isString && !c1isString) {
            val = -1;
        } else if (c1isString && !c0isString) {
            val = 1;
        } else {
            val = c1.compareTo(c0);
        }
        return bSortAscending ? -val : val;
    } catch (ClassCastException e) {
        int c0_index = (cell0 == null) ? -999 : cell0.getTableRowCore().getIndex();
        int c1_index = (cell1 == null) ? -999 : cell1.getTableRowCore().getIndex();
        System.err.println("Can't compare " + c0.getClass().getName() + "(" + c0.toString() + ") from row #" + c0_index + " to " + c1.getClass().getName() + "(" + c1.toString() + ") from row #" + c1_index + " while sorting column " + sName);
        e.printStackTrace();
        return 0;
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) TableCellCore(com.biglybt.ui.common.table.TableCellCore)

Example 8 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.

the class TableRowCoreSorter method compare.

@Override
@SuppressWarnings("null")
public int compare(TableRowCore o1, TableRowCore o2) {
    TableRowCore parent1 = o1.getParentRowCore();
    TableRowCore parent2 = o2.getParentRowCore();
    boolean hasParent1 = parent1 != null;
    boolean hasParent2 = parent2 != null;
    if (parent1 == parent2 || (!hasParent1 && !hasParent2)) {
        return o1.getIndex() - o2.getIndex();
    }
    if (hasParent1 && hasParent2) {
        return parent1.getIndex() - parent2.getIndex();
    }
    if (hasParent1) {
        if (parent1 == o2) {
            return 1;
        }
        return parent1.getIndex() - o2.getIndex();
    }
    if (o1 == parent2) {
        return 0;
    }
    return o1.getIndex() - parent2.getIndex();
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore)

Example 9 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore 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)

Example 10 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore in project BiglyBT by BiglySoftware.

the class ColumnThumbAndName method refresh.

@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
    String name = null;
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        if (fileInfo.isSkipped() && (fileInfo.getStorageType() == DiskManagerFileInfo.ST_COMPACT || fileInfo.getStorageType() == DiskManagerFileInfo.ST_REORDER_COMPACT)) {
            TableRowCore row = (TableRowCore) cell.getTableRow();
            if (row != null) {
                row.getParentRowCore().removeSubRow(ds);
            }
        }
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    if (dm != null) {
        name = dm.getDisplayName();
    }
    if (name == null) {
        name = "";
    }
    cell.setSortValue(name);
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

TableRowCore (com.biglybt.ui.common.table.TableRowCore)29 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 TableCellCore (com.biglybt.ui.common.table.TableCellCore)6 Point (org.eclipse.swt.graphics.Point)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3 FilesView (com.biglybt.ui.swt.views.FilesView)3 List (java.util.List)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)2 PeerItem (com.biglybt.core.peermanager.peerdb.PeerItem)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 TableColumn (com.biglybt.pif.ui.tables.TableColumn)2 TableSelectionListener (com.biglybt.ui.common.table.TableSelectionListener)2 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2