public void refresh(TableCell cell) { DownloadManager dm = (DownloadManager) cell.getDataSource(); long value = (dm == null) ? 0 : dm.getStats().getSecondsDownloading(); if (!cell.setSortValue(value) && cell.isValid()) return; cell.setText(TimeFormatter.format(value)); }
public void refresh(TableCell cell) { TRHostTorrent item = (TRHostTorrent) cell.getDataSource(); long value = (item == null) ? 0 : item.getAnnounceCount(); if (!cell.setSortValue(value) && cell.isValid()) { return; } cell.setText("" + value); }
// @see // org.gudy.azureus2.plugins.ui.tables.TableCellRefreshListener#refresh(org.gudy.azureus2.plugins.ui.tables.TableCell) public void refresh(TableCell cell) { VuzeActivitiesEntry entry = (VuzeActivitiesEntry) cell.getDataSource(); if (entry == null) return; if (!cell.setSortValue(entry.getTypeID()) && cell.isValid()) { return; } DownloadManager dm = entry.getDownloadManger(); boolean canPlay = PlayUtils.canPlayDS(entry, -1, false); boolean canDL = dm == null && entry.getDownloadManger() == null && (entry.getTorrent() != null || entry.getAssetHash() != null); boolean canRun = !canPlay && dm != null; if (canRun && dm != null && !dm.getAssumedComplete()) { canRun = false; } StringBuffer sb = new StringBuffer(); if (canDL) { if (sb.length() > 0) { sb.append(" | "); } sb.append("<A HREF=\"download\">Download</A>"); } if (canPlay) { if (sb.length() > 0) { sb.append(" | "); } sb.append("<A HREF=\"play\">Play</A>"); } if (canRun) { if (sb.length() > 0) { sb.append(", "); } sb.append("<A HREF=\"launch\">Launch</A>"); } cell.getTableRow().setData("text", sb.toString()); }
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; int a1 = ((i + 1) * nbPieces) / newWidth; if (a1 == a0) a1++; if (a1 > nbPieces && nbPieces != 0) a1 = nbPieces; int nbAvailable = 0; boolean written = false; boolean partially_written = false; if (firstPiece >= 0) for (int j = a0; j < a1; j++) { final int this_index = j + firstPiece; final DiskManagerPiece dm_piece = dm_pieces[this_index]; if (dm_piece.isDone()) nbAvailable++; if (written) continue; if (pe_pieces != null) { PEPiece pe_piece = pe_pieces[this_index]; if (pe_piece != null) written = written || (pe_piece.getLastDownloadTime(now) + 500) > last_draw_time; } if ((!written) && (!partially_written)) { final boolean[] blocks = dm_piece.getWritten(); if (blocks != null) for (int k = 0; k < blocks.length; k++) if (blocks[k]) { partially_written = true; break; } } } // for j else nbAvailable = 1; gcImage.setBackground( written ? Colors.red : partially_written ? Colors.grey : Colors.blues[(nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0)]); gcImage.fillRectangle(i, 1, 1, newHeight - 2); if (written) bNoRed = false; } gcImage.setForeground(Colors.grey); } } else gcImage.setForeground(Colors.grey); if (manager != null) gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1); gcImage.dispose(); last_draw_time = now; if (cell instanceof TableCellSWT) ((TableCellSWT) cell).setGraphic(piecesImage); else cell.setGraphic(new UISWTGraphicImpl(piecesImage)); }