⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piecesitem.java

📁 java 文件下载器。可自定义
💻 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:   PiecesItem.java

package org.gudy.azureus2.ui.swt.views.tableitems.mytorrents;

import java.io.PrintStream;
import org.eclipse.swt.graphics.*;
import org.gudy.azureus2.core3.disk.DiskManager;
import org.gudy.azureus2.core3.disk.DiskManagerPiece;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.download.DownloadManagerStats;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.plugins.download.DownloadTypeIncomplete;
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 PiecesItem extends CoreTableColumn
	implements TableCellAddedListener, TableCellRefreshListener, TableCellDisposeListener
{

	public static final Class DATASOURCE_TYPE = org/gudy/azureus2/plugins/download/DownloadTypeIncomplete;
	private static final int INDEX_COLOR_NONEAVAIL = 10;
	private static final int borderHorizontalSize = 1;
	private static final int borderVerticalSize = 1;
	private static final int borderSplit = 1;
	private static final int completionHeight = 2;
	public static final String COLUMN_ID = "pieces";
	private int marginHeight;

	public PiecesItem(String sTableID)
	{
		this(sTableID, -1);
	}

	public void fillTableColumnInfo(TableColumnInfo info)
	{
		info.addCategories(new String[] {
			"content", "progress"
		});
		info.setProficiency((byte)1);
	}

	public PiecesItem(String sTableID, int marginHeight)
	{
		super(DATASOURCE_TYPE, "pieces", 1, 100, sTableID);
		this.marginHeight = -1;
		this.marginHeight = marginHeight;
		initializeAsGraphic(-1, 100);
		setMinWidth(100);
	}

	public void cellAdded(TableCell cell)
	{
		if (marginHeight != -1)
			cell.setMarginHeight(marginHeight);
		cell.setFillCell(true);
	}

	public void dispose(TableCell cell)
	{
		DownloadManager infoObj = (DownloadManager)cell.getDataSource();
		if (infoObj == null)
			return;
		Image img = (Image)infoObj.getUserData("PiecesImage");
		if (img != null && !img.isDisposed())
			img.dispose();
		infoObj.setUserData("PiecesImageBuffer", null);
		infoObj.setUserData("PiecesImage", null);
	}

	public void refresh(TableCell cell)
	{
		DownloadManager infoObj = (DownloadManager)cell.getDataSource();
		long lCompleted = infoObj != null ? infoObj.getStats().getCompleted() : 0L;
		boolean bForce = infoObj != null && infoObj.getUserData("PiecesImage") == null;
		if (!cell.setSortValue(lCompleted) && cell.isValid() && !bForce)
			return;
		if (infoObj == null)
			return;
		int newWidth = cell.getWidth();
		if (newWidth <= 0)
			return;
		int newHeight = cell.getHeight();
		int x0 = 1;
		int x1 = newWidth - 1 - 1;
		int y0 = 4;
		int y1 = newHeight - 1 - 1;
		int drawWidth = (x1 - x0) + 1;
		if (drawWidth < 10 || y1 < 3)
			return;
		boolean bImageBufferValid = true;
		int imageBuffer[] = (int[])(int[])infoObj.getUserData("PiecesImageBuffer");
		if (imageBuffer == null || imageBuffer.length != drawWidth)
		{
			imageBuffer = new int[drawWidth];
			bImageBufferValid = false;
		}
		Image image = (Image)infoObj.getUserData("PiecesImage");
		boolean bImageChanged;
		if (image == null || image.isDisposed())
		{
			bImageChanged = true;
		} else
		{
			Rectangle imageBounds = image.getBounds();
			bImageChanged = imageBounds.width != newWidth || imageBounds.height != newHeight;
		}
		GC gcImage;
		if (bImageChanged)
		{
			if (image != null && !image.isDisposed())
				image.dispose();
			image = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
			Rectangle imageBounds = image.getBounds();
			bImageBufferValid = false;
			gcImage = new GC(image);
			gcImage.setForeground(Colors.grey);
			gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
			gcImage.setForeground(Colors.white);
			gcImage.drawLine(x0, 3, x1, 3);
		} else
		{
			gcImage = new GC(image);
		}
		DiskManager disk_manager = infoObj.getDiskManager();
		DiskManagerPiece pieces[] = disk_manager != null ? disk_manager.getPieces() : null;
		int nbPieces = infoObj.getNbPieces();
		try
		{
			int nbComplete = 0;
			int a1 = 0;
			for (int i = 0; i < drawWidth; i++)
			{
				int a0;
				if (i == 0)
				{
					a0 = 0;
					a1 = nbPieces / drawWidth;
					if (a1 == 0)
						a1 = 1;
				} else
				{
					a0 = a1;
					a1 = ((i + 1) * nbPieces) / drawWidth;
				}
				int index;
				if (a1 <= a0)
				{
					index = imageBuffer[i - 1];
				} else
				{
					int nbAvailable = 0;
					for (int j = a0; j < a1; j++)
						if (pieces != null && pieces[j].isDone())
							nbAvailable++;

					nbComplete += nbAvailable;
					index = (nbAvailable * 9) / (a1 - a0);
				}
				if (!bImageBufferValid || imageBuffer[i] != index)
				{
					imageBuffer[i] = index;
					bImageChanged = true;
					gcImage.setForeground(index != 10 ? Colors.blues[index] : Colors.red);
					gcImage.drawLine(i + x0, y0, i + x0, y1);
				}
			}

			int limit = nbPieces != 0 ? (drawWidth * nbComplete) / nbPieces : 0;
			if (limit < drawWidth)
			{
				gcImage.setBackground(Colors.blues[0]);
				gcImage.fillRectangle(limit + x0, 1, x1 - limit, 2);
			}
			gcImage.setBackground(Colors.colorProgressBar);
			gcImage.fillRectangle(x0, 1, limit, 2);
		}
		catch (Exception e)
		{
			System.out.println("Error Drawing PiecesItem");
			Debug.printStackTrace(e);
		}
		gcImage.dispose();
		Image oldImage = null;
		org.gudy.azureus2.plugins.ui.Graphic graphic = cell.getGraphic();
		if (graphic instanceof UISWTGraphic)
			oldImage = ((UISWTGraphic)graphic).getImage();
		if (bImageChanged || image != oldImage || !cell.isValid())
		{
			if (cell instanceof TableCellSWT)
				((TableCellSWT)cell).setGraphic(image);
			else
				cell.setGraphic(new UISWTGraphicImpl(image));
			if (bImageChanged)
				cell.invalidate();
			infoObj.setUserData("PiecesImage", image);
			infoObj.setUserData("PiecesImageBuffer", imageBuffer);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -