📄 blocksitem.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: BlocksItem.java
package org.gudy.azureus2.ui.swt.views.tableitems.pieces;
import com.aelitis.azureus.core.diskmanager.cache.*;
import java.util.Arrays;
import org.eclipse.swt.graphics.*;
import org.gudy.azureus2.core3.disk.DiskManager;
import org.gudy.azureus2.core3.disk.DiskManagerPiece;
import org.gudy.azureus2.core3.peer.PEPeerManager;
import org.gudy.azureus2.core3.peer.PEPiece;
import org.gudy.azureus2.plugins.ui.tables.*;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
import org.gudy.azureus2.ui.swt.plugins.UISWTGraphic;
import org.gudy.azureus2.ui.swt.pluginsimpl.UISWTGraphicImpl;
import org.gudy.azureus2.ui.swt.views.table.TableCellSWT;
import org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn;
public class BlocksItem extends CoreTableColumn
implements TableCellAddedListener, TableCellRefreshListener, TableCellDisposeListener
{
private final int COLOR_REQUESTED = 0;
private final int COLOR_WRITTEN = 1;
private final int COLOR_DOWNLOADED = 2;
private final int COLOR_INCACHE = 3;
public static Color colors[];
private static CacheFileManagerStats cacheStats = null;
public BlocksItem()
{
super("blocks", "Pieces");
initializeAsGraphic(-2, 200);
}
public void fillTableColumnInfo(TableColumnInfo info)
{
info.addCategories(new String[] {
"progress"
});
}
public void cellAdded(TableCell cell)
{
if (cacheStats == null)
try
{
cacheStats = CacheFileManagerFactory.getSingleton().getStats();
}
catch (Exception e)
{
e.printStackTrace();
}
cell.setFillCell(true);
}
public void dispose(TableCell cell)
{
Image img = ((TableCellSWT)cell).getGraphicSWT();
if (img != null && !img.isDisposed())
img.dispose();
}
public void refresh(TableCell cell)
{
PEPiece pePiece = (PEPiece)cell.getDataSource();
if (pePiece == null)
{
cell.setSortValue(0L);
dispose(cell);
cell.setGraphic(null);
return;
}
cell.setSortValue(pePiece.getNbWritten());
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(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
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 = 0L;
int factor = 4;
for (; iPixelsPerBlock <= 0; iPixelsPerBlock = (int)((long)(x1 + 1) / (lNumBlocks / (long)blocksPerPixel)))
blocksPerPixel++;
pxRes = (int)((long)x1 - (lNumBlocks / (long)blocksPerPixel) * (long)iPixelsPerBlock);
if (pxRes <= 0)
pxRes = 1;
pxBlockStep = (lNumBlocks * (long)factor) / (long)pxRes;
long addBlocks = (lNumBlocks * (long)factor) / pxBlockStep;
if (addBlocks * (long)iPixelsPerBlock > (long)pxRes)
pxBlockStep++;
org.gudy.azureus2.core3.torrent.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[])(long[])offsets.clone();
Arrays.fill(offsets, (long)pePiece.getManager().getDiskManager().getPieceLength() * (long)pieceNumber);
for (int i = 0; (long)i < lNumBlocks; i++)
{
lengths[i] = pePiece.getBlockSize(i);
offsets[i] += 16384 * i;
}
boolean isCached[] = cacheStats != null ? cacheStats.getBytesInCache(torrent, offsets, lengths) : null;
for (int i = 0; (long)i < lNumBlocks; i += blocksPerPixel)
{
int nextWidth = iPixelsPerBlock;
blockStep += blocksPerPixel * factor;
if ((long)blockStep >= pxBlockStep)
{
nextWidth += (int)((long)blockStep / pxBlockStep);
blockStep = (int)((long)blockStep - pxBlockStep);
}
if ((long)i >= lNumBlocks - (long)blocksPerPixel)
nextWidth = x1 - drawnWidth;
Color color = Colors.white;
if (written == null && piece_written || written != null && written[i])
color = colors[1];
else
if (pePiece.isDownloaded(i))
color = colors[2];
else
if (pePiece.isRequested(i))
color = colors[0];
gcImage.setBackground(color);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);
if (isCached[i])
{
gcImage.setBackground(colors[3]);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);
}
drawnWidth += nextWidth;
}
gcImage.dispose();
Image oldImage = null;
org.gudy.azureus2.plugins.ui.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();
}
static
{
colors = (new Color[] {
Colors.blues[2], Colors.blues[9], Colors.red, Colors.grey
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -