public void refresh(TableCell cell) {
refresh(cell, false);
}
public void refresh(TableCell cell, boolean sortOnly) {
final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
int percentDone = 0;
if (fileInfo != null && fileInfo.getLength() != 0)
percentDone = (int) ((1000 * fileInfo.getDownloaded()) / fileInfo.getLength());
cell.setSortValue(percentDone);
if (sortOnly)
{
dispose(cell);
return;
}
//Compute bounds ...
int newWidth = cell.getWidth();
if (newWidth <= 0)
return;
final int newHeight = cell.getHeight();
final int x1 = newWidth - borderWidth - 1;
final int y1 = newHeight - borderWidth - 1;
if (x1 < 10 || y1 < 3)
return;
final DiskManager manager = fileInfo.getDiskManager();
// we want to run through the image part once one the transition from with a disk manager (running)
// to without a disk manager (stopped) in order to clear the pieces view
boolean running = manager != null;
boolean hasGraphic = false;
Graphic graphic = cell.getGraphic();
if (graphic instanceof UISWTGraphic) {
Image img = ((UISWTGraphic) graphic).getImage();
hasGraphic = img != null && !img.isDisposed();
}
final boolean bImageBufferValid = (lastPercentDone == percentDone)
&& cell.isValid() && bNoRed && running == was_running && hasGraphic;
if (bImageBufferValid)
return;
was_running = running;
lastPercentDone = percentDone;
Image piecesImage = null;
if (graphic instanceof UISWTGraphic)
piecesImage = ((UISWTGraphic) graphic).getImage();
if (piecesImage != null && !piecesImage.isDisposed())
piecesImage.dispose();
if (!running) {
cell.setGraphic(null);
return;
}
piecesImage = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
final GC gcImage = new GC(piecesImage);
// dm may be null if this is a skeleton file view
DownloadManager download_manager = fileInfo.getDownloadManager();
PEPeerManager peer_manager = download_manager == null ? null : download_manager.getPeerManager();
PEPiece[] pe_pieces = peer_manager == null ? null : peer_manager.getPieces();
final long now = SystemTime.getCurrentTime();
if (fileInfo != null && manager != null)
{
if (percentDone == 1000)
{
gcImage.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
gcImage.setBackground(Colors.blues[Colors.BLUES_DARKEST]);
gcImage.fillRectangle(1, 1, newWidth - 2, newHeight - 2);
} else
{
final int firstPiece = fileInfo.getFirstPieceNumber();
final int nbPieces = fileInfo.getNbPieces();
final DiskManagerPiece[] dm_pieces = manager.getPieces();
bNoRed = true;
for (int i = 0; i < newWidth; i++)
{
final int a0 = (i * nbPieces) / newWidth;