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

📄 progressgraphitem.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:   ProgressGraphItem.java

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

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.gudy.azureus2.core3.disk.*;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.peer.PEPeerManager;
import org.gudy.azureus2.core3.peer.PEPiece;
import org.gudy.azureus2.core3.util.SystemTime;
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 ProgressGraphItem extends CoreTableColumn
	implements TableCellAddedListener, TableCellDisposeListener, TableCellVisibilityListener
{
	private class Cell
		implements TableCellLightRefreshListener
	{

		int lastPercentDone;
		private long last_draw_time;
		private boolean bNoRed;
		private boolean was_running;
		final ProgressGraphItem this$0;

		public void refresh(TableCell cell)
		{
			refresh(cell, false);
		}

		public void refresh(TableCell cell, boolean sortOnly)
		{
			DiskManagerFileInfo fileInfo = (DiskManagerFileInfo)cell.getDataSource();
			int percentDone = 0;
			if (fileInfo != null && fileInfo.getLength() != 0L)
				percentDone = (int)((1000L * fileInfo.getDownloaded()) / fileInfo.getLength());
			cell.setSortValue(percentDone);
			if (sortOnly)
			{
				dispose(cell);
				return;
			}
			int newWidth = cell.getWidth();
			if (newWidth <= 0)
				return;
			int newHeight = cell.getHeight();
			int x1 = newWidth - 1 - 1;
			int y1 = newHeight - 1 - 1;
			if (x1 < 10 || y1 < 3)
				return;
			DiskManager manager = fileInfo.getDiskManager();
			boolean running = manager != null;
			boolean hasGraphic = false;
			org.gudy.azureus2.plugins.ui.Graphic graphic = cell.getGraphic();
			if (graphic instanceof UISWTGraphic)
			{
				Image img = ((UISWTGraphic)graphic).getImage();
				hasGraphic = img != null && !img.isDisposed();
			}
			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();
			piecesImage = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
			GC gcImage = new GC(piecesImage);
			DownloadManager download_manager = fileInfo.getDownloadManager();
			PEPeerManager peer_manager = download_manager != null ? download_manager.getPeerManager() : null;
			PEPiece pe_pieces[] = peer_manager != null ? peer_manager.getPieces() : null;
			long now = SystemTime.getCurrentTime();
			if (fileInfo != null && manager != null)
			{
				if (percentDone == 1000)
				{
					gcImage.setForeground(Colors.blues[9]);
					gcImage.setBackground(Colors.blues[9]);
					gcImage.fillRectangle(1, 1, newWidth - 2, newHeight - 2);
				} else
				{
					int firstPiece = fileInfo.getFirstPieceNumber();
					int nbPieces = fileInfo.getNbPieces();
					DiskManagerPiece dm_pieces[] = manager.getPieces();
					bNoRed = true;
					for (int i = 0; i < newWidth; i++)
					{
						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++)
							{
								int this_index = j + firstPiece;
								DiskManagerPiece dm_piece = dm_pieces[this_index];
								if (dm_piece.isDone())
									nbAvailable++;
								if (!written)
								{
									if (pe_pieces != null)
									{
										PEPiece pe_piece = pe_pieces[this_index];
										if (pe_piece != null)
											written = written || pe_piece.getLastDownloadTime(now) + 500L > last_draw_time;
									}
									if (!written && !partially_written)
									{
										boolean blocks[] = dm_piece.getWritten();
										if (blocks != null)
										{
											int k = 0;
											do
											{
												if (k >= blocks.length)
													break;
												if (blocks[k])
												{
													partially_written = true;
													break;
												}
												k++;
											} while (true);
										}
									}
								}
							}

						} else
						{
							nbAvailable = 1;
						}
						gcImage.setBackground(written ? Colors.red : partially_written ? Colors.grey : Colors.blues[(nbAvailable * 9) / (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));
		}

		public Cell(TableCell cell)
		{
			this$0 = ProgressGraphItem.this;
			super();
			lastPercentDone = 0;
			last_draw_time = SystemTime.getCurrentTime();
			bNoRed = false;
			was_running = false;
			cell.setFillCell(true);
			cell.addListeners(this);
		}
	}


	private static final int borderWidth = 1;

	public ProgressGraphItem()
	{
		super("pieces", "Files");
		initializeAsGraphic(-2, 200);
		setMinWidth(100);
	}

	public void fillTableColumnInfo(TableColumnInfo info)
	{
		info.addCategories(new String[] {
			"progress"
		});
	}

	public void cellAdded(TableCell cell)
	{
		new Cell(cell);
	}

	public void cellVisibilityChanged(TableCell cell, int visibility)
	{
		if (visibility == 1)
			dispose(cell);
	}

	public void dispose(TableCell cell)
	{
		org.gudy.azureus2.plugins.ui.Graphic graphic = cell.getGraphic();
		if (graphic instanceof UISWTGraphic)
		{
			Image img = ((UISWTGraphic)graphic).getImage();
			if (img != null && !img.isDisposed())
				img.dispose();
		}
	}
}

⌨️ 快捷键说明

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