Search in sources :

Example 16 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class PiecesView method addExistingDatasources.

/**
 * Add datasources already in existance before we called addListener.
 * Faster than allowing addListener to call us one datasource at a time.
 */
private void addExistingDatasources() {
    if (manager == null || tv.isDisposed()) {
        return;
    }
    PEPiece[] dataSources = manager.getCurrentPieces();
    if (dataSources != null && dataSources.length >= 0) {
        tv.addDataSources(dataSources);
        tv.processDataSourceQueue();
    }
    // For this view the tab datasource isn't driven by table row selection so we
    // need to update it with the primary data source
    // TODO: TrackerView and PiecesView now have this similar code -- this
    // would be better handled in TableViewTab (or TableViewSWT?)
    TableViewSWT_TabsCommon tabs = tv.getTabsCommon();
    if (tabs != null) {
        tabs.triggerTabViewsDataSourceChanged(tv);
    }
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) TableViewSWT_TabsCommon(com.biglybt.ui.swt.views.table.impl.TableViewSWT_TabsCommon)

Example 17 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class BlockCountItem method refresh.

@Override
public void refresh(TableCell cell) {
    PEPiece piece = (PEPiece) cell.getDataSource();
    long value = (piece == null) ? 0 : piece.getNbBlocks();
    if (!cell.setSortValue(value) && cell.isValid()) {
        return;
    }
    cell.setText("" + value);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece)

Example 18 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class BlocksItem method refresh.

@Override
public void refresh(final TableCell cell) {
    final PEPiece pePiece = (PEPiece) cell.getDataSource();
    if (pePiece == null) {
        cell.setSortValue(0);
        dispose(cell);
        cell.setGraphic(null);
        return;
    }
    cell.setSortValue(pePiece.getNbWritten());
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            PiecePicker picker = pePiece.getPiecePicker();
            long lNumBlocks = pePiece.getNbBlocks();
            int newWidth = cell.getWidth();
            if (newWidth <= 0) {
                dispose(cell);
                cell.setGraphic(null);
                return;
            }
            int newHeight = cell.getHeight();
            int x1 = newWidth - 2;
            int y1 = newHeight - 3;
            if (x1 < 10 || y1 < 3) {
                dispose(cell);
                cell.setGraphic(null);
                return;
            }
            Image image = new Image(Utils.getDisplay(), newWidth, newHeight);
            Color color;
            GC gcImage = new GC(image);
            gcImage.setForeground(Colors.grey);
            gcImage.drawRectangle(0, 0, x1 + 1, y1 + 1);
            int blocksPerPixel = 0;
            int iPixelsPerBlock = 0;
            int pxRes = 0;
            long pxBlockStep = 0;
            int factor = 4;
            while (iPixelsPerBlock <= 0) {
                blocksPerPixel++;
                iPixelsPerBlock = (int) ((x1 + 1) / (lNumBlocks / blocksPerPixel));
            }
            pxRes = (int) (x1 - ((lNumBlocks / blocksPerPixel) * iPixelsPerBlock));
            if (pxRes <= 0)
                pxRes = 1;
            pxBlockStep = (lNumBlocks * factor) / pxRes;
            long addBlocks = (lNumBlocks * factor) / pxBlockStep;
            if ((addBlocks * iPixelsPerBlock) > pxRes)
                pxBlockStep += 1;
            /*      String msg = "iPixelsPerBlock = "+iPixelsPerBlock + ", blocksPerPixel = " + blocksPerPixel;
				      msg += ", pxRes = " + pxRes + ", pxBlockStep = " + pxBlockStep + ", addBlocks = " + addBlocks + ", x1 = " + x1;
				      Debug.out(msg);*/
            TOTorrent torrent = pePiece.getManager().getDiskManager().getTorrent();
            boolean[] written = pePiece.getDMPiece().getWritten();
            boolean piece_written = pePiece.isWritten();
            int drawnWidth = 0;
            int blockStep = 0;
            int pieceNumber = pePiece.getPieceNumber();
            long[] offsets = new long[(int) lNumBlocks];
            long[] lengths = (long[]) offsets.clone();
            Arrays.fill(offsets, (long) pePiece.getManager().getDiskManager().getPieceLength() * (long) pieceNumber);
            for (int i = 0; i < lNumBlocks; lengths[i] = pePiece.getBlockSize(i), offsets[i] += DiskManager.BLOCK_SIZE * i, i++) ;
            boolean egm = picker.isInEndGameMode();
            boolean[] isCached = cacheStats == null ? new boolean[(int) lNumBlocks] : cacheStats.getBytesInCache(torrent, offsets, lengths);
            for (int i = 0; i < lNumBlocks; i += blocksPerPixel) {
                int nextWidth = iPixelsPerBlock;
                blockStep += blocksPerPixel * factor;
                if (blockStep >= pxBlockStep) {
                    nextWidth += (int) (blockStep / pxBlockStep);
                    blockStep -= pxBlockStep;
                }
                if (i >= lNumBlocks - blocksPerPixel) {
                    nextWidth = x1 - drawnWidth;
                }
                color = Colors.white;
                int num = -1;
                if ((written == null && piece_written) || (written != null && written[i])) {
                    color = colors[COLOR_WRITTEN];
                } else if (pePiece.isDownloaded(i)) {
                    color = colors[COLOR_DOWNLOADED];
                } else if (pePiece.isRequested(i)) {
                    if (egm) {
                        int req_count = picker.getEGMRequestCount(pieceNumber, i);
                        if (req_count < 2) {
                            color = colors[COLOR_REQUESTED];
                        } else {
                            color = colors[COLOR_EGM];
                            num = req_count;
                        }
                    } else {
                        color = colors[COLOR_REQUESTED];
                    }
                }
                gcImage.setBackground(color);
                gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);
                if (isCached[i]) {
                    gcImage.setBackground(colors[COLOR_INCACHE]);
                    gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);
                }
                if (num >= 0) {
                    gcImage.setForeground(Colors.black);
                    gcImage.drawString(String.valueOf(num), drawnWidth + 1, 0, true);
                }
                drawnWidth += nextWidth;
            }
            gcImage.dispose();
            Image oldImage = null;
            Graphic graphic = cell.getGraphic();
            if (graphic instanceof UISWTGraphic) {
                oldImage = ((UISWTGraphic) graphic).getImage();
            }
            if (cell instanceof TableCellSWT) {
                ((TableCellSWT) cell).setGraphic(image);
            } else {
                cell.setGraphic(new UISWTGraphicImpl(image));
            }
            if (oldImage != null && !oldImage.isDisposed())
                oldImage.dispose();
            gcImage.dispose();
        }
    });
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) AERunnable(com.biglybt.core.util.AERunnable) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Color(org.eclipse.swt.graphics.Color) TOTorrent(com.biglybt.core.torrent.TOTorrent) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 19 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class FilesItem method refresh.

@Override
public void refresh(TableCell cell) {
    PEPiece pePiece = (PEPiece) cell.getDataSource();
    String value = "";
    if (pePiece != null) {
        DiskManagerPiece dmp = pePiece.getDMPiece();
        if (dmp != null) {
            DMPieceList l = dmp.getManager().getPieceList(pePiece.getPieceNumber());
            for (int i = 0; i < l.size(); i++) {
                DMPieceMapEntry entry = l.get(i);
                String name = entry.getFile().getTorrentFile().getRelativePath();
                value += (value.isEmpty() ? "" : "; ") + name;
            }
        }
    }
    if (!cell.setSortValue(value) && cell.isValid())
        return;
    cell.setText(value);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) DMPieceMapEntry(com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) DMPieceList(com.biglybt.core.disk.impl.piecemapper.DMPieceList)

Example 20 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class SpeedItem method refresh.

@Override
public void refresh(TableCell cell) {
    PEPiece piece = (PEPiece) cell.getDataSource();
    int value = 0;
    if (null != piece) {
        value = piece.getSpeed();
        if (!cell.setSortValue(value) && cell.isValid()) {
            return;
        }
    }
    cell.setText("" + value);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece)

Aggregations

PEPiece (com.biglybt.core.peer.PEPiece)26 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)7 DiskManager (com.biglybt.core.disk.DiskManager)6 DownloadManager (com.biglybt.core.download.DownloadManager)4 LogEvent (com.biglybt.core.logging.LogEvent)4 PEPeer (com.biglybt.core.peer.PEPeer)4 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 DMPieceList (com.biglybt.core.disk.impl.piecemapper.DMPieceList)3 DMPieceMapEntry (com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry)3 AERunnable (com.biglybt.core.util.AERunnable)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)2 UISWTViewCoreEventListener (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 Color (org.eclipse.swt.graphics.Color)2 GC (org.eclipse.swt.graphics.GC)2 Image (org.eclipse.swt.graphics.Image)2 GridData (org.eclipse.swt.layout.GridData)2