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);
}
}
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);
}
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();
}
});
}
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);
}
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);
}
Aggregations