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

📄 peerinfoview.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			topLabel.setText("");
		} else
		{
			String s = peer.getClient();
			if (s == null)
				s = "";
			if (s != "")
				s = (new StringBuilder()).append(s).append("; ").toString();
			s = (new StringBuilder()).append(s).append(peer.getIp()).append("; ").append(DisplayFormatters.formatPercentFromThousands(peer.getPercentDoneInThousandNotation())).toString();
			topLabel.setText(s);
			if (countryLocator != null)
				try
				{
					String sCountry = (String)countryLocator.getClass().getMethod("getIPCountry", new Class[] {
						java/lang/String, java/util/Locale
					}).invoke(countryLocator, new Object[] {
						peer.getIp(), Locale.getDefault()
					});
					String sCode = (String)countryLocator.getClass().getMethod("getIPISO3166", new Class[] {
						java/lang/String
					}).invoke(countryLocator, new Object[] {
						peer.getIp()
					});
					imageLabel.setToolTipText((new StringBuilder()).append(sCode).append("- ").append(sCountry).toString());
					java.io.InputStream is = countryLocator.getClass().getClassLoader().getResourceAsStream((new StringBuilder()).append(sCountryImagesDir).append("/").append(sCode.toLowerCase()).append(".png").toString());
					if (is != null)
					{
						Image img = new Image(imageLabel.getDisplay(), is);
						img.setBackground(imageLabel.getBackground());
						imageLabel.setImage(img);
					}
				}
				catch (Exception e) { }
		}
		refreshInfoCanvas();
	}

	public void refresh()
	{
		super.refresh();
		if (loopFactor++ % graphicsUpdate == 0)
			refreshInfoCanvas();
	}

	protected void refreshInfoCanvas()
	{
		Rectangle bounds;
		BitFlags peerHavePieces;
		DiskManagerPiece dm_pieces[];
		PEPeerManager pm;
		int iNumCols;
		int iNeededHeight;
		GC gcImg;
		peerInfoCanvas.layout(true);
		bounds = peerInfoCanvas.getClientArea();
		if (bounds.width <= 0 || bounds.height <= 0)
			return;
		if (img != null && !img.isDisposed())
		{
			img.dispose();
			img = null;
		}
		if (peer == null || peer.getPeerState() != 30)
		{
			GC gc = new GC(peerInfoCanvas);
			gc.fillRectangle(bounds);
			gc.dispose();
			return;
		}
		peerHavePieces = peer.getAvailable();
		if (peerHavePieces == null)
		{
			GC gc = new GC(peerInfoCanvas);
			gc.fillRectangle(bounds);
			gc.dispose();
			return;
		}
		dm_pieces = null;
		pm = peer.getManager();
		DiskManager dm = pm.getDiskManager();
		dm_pieces = dm.getPieces();
		iNumCols = bounds.width / 16;
		iNeededHeight = ((dm.getNbPieces() - 1) / iNumCols + 1) * 16;
		if (sc.getMinHeight() != iNeededHeight)
		{
			sc.setMinHeight(iNeededHeight);
			sc.layout(true, true);
			bounds = peerInfoCanvas.getClientArea();
		}
		img = new Image(peerInfoCanvas.getDisplay(), bounds.width, iNeededHeight);
		gcImg = new GC(img);
		gcImg.setAdvanced(true);
		gcImg.setBackground(peerInfoCanvas.getBackground());
		gcImg.fillRectangle(0, 0, bounds.width, iNeededHeight);
		int availability[] = pm.getAvailability();
		int iNextDLPieceID = -1;
		int iDLPieceID = -1;
		int ourRequestedPieces[] = peer.getOutgoingRequestedPieceNumbers();
		if (ourRequestedPieces != null)
			if (!peer.isChokingMe())
			{
				if (ourRequestedPieces.length > 0)
				{
					iDLPieceID = ourRequestedPieces[0];
					if (ourRequestedPieces.length > 1)
						iNextDLPieceID = ourRequestedPieces[1];
				}
			} else
			if (ourRequestedPieces.length > 0)
				iNextDLPieceID = ourRequestedPieces[0];
		int peerRequestedPieces[] = peer.getIncomingRequestedPieceNumbers();
		if (peerRequestedPieces == null)
			peerRequestedPieces = new int[0];
		int peerNextRequestedPiece = -1;
		if (peerRequestedPieces.length > 0)
			peerNextRequestedPiece = peerRequestedPieces[0];
		Arrays.sort(peerRequestedPieces);
		int iRow = 0;
		int iCol = 0;
		for (int i = 0; i < peerHavePieces.flags.length; i++)
		{
			boolean done = dm_pieces != null ? dm_pieces[i].isDone() : false;
			int iXPos = iCol * 16;
			int iYPos = iRow * 16;
			if (done)
			{
				int colorIndex;
				if (peerHavePieces.flags[i])
					colorIndex = 0;
				else
					colorIndex = 2;
				gcImg.setBackground(blockColors[colorIndex]);
				gcImg.fillRectangle(iXPos, iYPos, 14, 14);
			} else
			{
				boolean partiallyDone = dm_pieces != null ? dm_pieces[i].getNbWritten() > 0 : false;
				int x = iXPos;
				int width = 14;
				int colorIndex;
				if (partiallyDone)
				{
					if (peerHavePieces.flags[i])
						colorIndex = 0;
					else
						colorIndex = 2;
					gcImg.setBackground(blockColors[colorIndex]);
					int iNewWidth = (int)(((float)dm_pieces[i].getNbWritten() / (float)dm_pieces[i].getNbBlocks()) * (float)width);
					if (iNewWidth >= width)
						iNewWidth = width - 1;
					else
					if (iNewWidth <= 0)
						iNewWidth = 1;
					gcImg.fillRectangle(x, iYPos, iNewWidth, 14);
					width -= iNewWidth;
					x += iNewWidth;
				}
				if (peerHavePieces.flags[i])
					colorIndex = 1;
				else
					colorIndex = 3;
				gcImg.setBackground(blockColors[colorIndex]);
				gcImg.fillRectangle(x, iYPos, width, 14);
			}
			if (i == iDLPieceID)
			{
				gcImg.setBackground(blockColors[4]);
				gcImg.fillPolygon(new int[] {
					iXPos, iYPos, iXPos + 14, iYPos, iXPos + 7, iYPos + 14
				});
			}
			if (i == iNextDLPieceID)
			{
				gcImg.setBackground(blockColors[5]);
				gcImg.fillPolygon(new int[] {
					iXPos + 2, iYPos + 2, (iXPos + 14) - 1, iYPos + 2, iXPos + 7, (iYPos + 14) - 1
				});
			}
			if (i == peerNextRequestedPiece)
			{
				gcImg.setBackground(blockColors[4]);
				gcImg.fillPolygon(new int[] {
					iXPos, iYPos + 14, iXPos + 14, iYPos + 14, iXPos + 7, iYPos
				});
			} else
			if (Arrays.binarySearch(peerRequestedPieces, i) >= 0)
			{
				gcImg.setBackground(blockColors[5]);
				gcImg.fillPolygon(new int[] {
					iXPos + 1, (iYPos + 14) - 2, (iXPos + 14) - 2, (iYPos + 14) - 2, iXPos + 7, iYPos + 2
				});
			}
			if (availability != null)
			{
				gcImg.setFont(font);
				String sNumber = String.valueOf(availability[i]);
				Point size = gcImg.stringExtent(sNumber);
				if (availability[i] < 100)
				{
					int x = (iXPos + 7) - size.x / 2;
					int y = (iYPos + 7) - size.y / 2;
					gcImg.setForeground(blockColors[6]);
					gcImg.drawText(sNumber, x, y, true);
				}
			}
			if (++iCol >= iNumCols)
			{
				iCol = 0;
				iRow++;
			}
		}

		gcImg.dispose();
		break MISSING_BLOCK_LABEL_1185;
		Exception e;
		e;
		Logger.log(new LogEvent(LogIDs.GUI, "drawing piece map", e));
		gcImg.dispose();
		break MISSING_BLOCK_LABEL_1185;
		Exception exception;
		exception;
		gcImg.dispose();
		throw exception;
		peerInfoCanvas.redraw();
		return;
	}

	public Composite getComposite()
	{
		return peerInfoComposite;
	}

	public void delete()
	{
		if (!imageLabel.isDisposed() && imageLabel.getImage() != null)
		{
			Image image = imageLabel.getImage();
			imageLabel.setImage(null);
			image.dispose();
		}
		if (img != null && !img.isDisposed())
		{
			img.dispose();
			img = null;
		}
		if (font != null && !font.isDisposed())
		{
			font.dispose();
			font = null;
		}
		super.delete();
	}

	public Image obfusticatedImage(Image image, Point shellOffset)
	{
		UIDebugGenerator.obfusticateArea(image, topLabel, shellOffset, "");
		return image;
	}
}

⌨️ 快捷键说明

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