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

📄 pieceinfoview.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	protected void refreshInfoCanvas()
	{
		Rectangle bounds;
		int iNumCols;
		int iNeededHeight;
		DiskManagerPiece dm_pieces[];
		PEPiece currentDLPieces[];
		byte uploadingPieces[];
		int availability[];
		int minAvailability;
		int minAvailability2;
		GC gcImg;
		BlockInfo newBlockInfo[];
		int iRow;
		alreadyFilling = false;
		if (!pieceInfoCanvas.isVisible())
			return;
		pieceInfoCanvas.layout(true);
		bounds = pieceInfoCanvas.getClientArea();
		if (bounds.width <= 0 || bounds.height <= 0)
		{
			topLabel.setText("");
			return;
		}
		if (dlm == null)
		{
			GC gc = new GC(pieceInfoCanvas);
			gc.fillRectangle(bounds);
			gc.dispose();
			topLabel.setText("");
			return;
		}
		PEPeerManager pm = dlm.getPeerManager();
		DiskManager dm = dlm.getDiskManager();
		if (pm == null || dm == null)
		{
			GC gc = new GC(pieceInfoCanvas);
			gc.fillRectangle(bounds);
			gc.dispose();
			topLabel.setText("");
			return;
		}
		iNumCols = bounds.width / 17;
		iNeededHeight = ((dm.getNbPieces() - 1) / iNumCols + 1) * 17;
		if (img != null && !img.isDisposed())
		{
			Rectangle imgBounds = img.getBounds();
			if (imgBounds.width != bounds.width || imgBounds.height != iNeededHeight)
			{
				oldBlockInfo = null;
				img.dispose();
				img = null;
			}
		}
		dm_pieces = dm.getPieces();
		currentDLPieces = pm.getPieces();
		uploadingPieces = new byte[dm_pieces.length];
		Iterator peer_it = pm.getPeers().iterator();
		do
		{
			if (!peer_it.hasNext())
				break;
			PEPeer peer = (PEPeer)peer_it.next();
			int peerRequestedPieces[] = peer.getIncomingRequestedPieceNumbers();
			if (peerRequestedPieces != null && peerRequestedPieces.length > 0)
			{
				int pieceNum = peerRequestedPieces[0];
				if (uploadingPieces[pieceNum] < 2)
					uploadingPieces[pieceNum] = 2;
				int j = 1;
				while (j < peerRequestedPieces.length) 
				{
					pieceNum = peerRequestedPieces[j];
					if (uploadingPieces[pieceNum] < 1)
						uploadingPieces[pieceNum] = 1;
					j++;
				}
			}
		} while (true);
		if (sc.getMinHeight() != iNeededHeight)
		{
			sc.setMinHeight(iNeededHeight);
			sc.layout(true, true);
			bounds = pieceInfoCanvas.getClientArea();
		}
		availability = pm.getAvailability();
		minAvailability = 0x7fffffff;
		minAvailability2 = 0x7fffffff;
		if (availability != null && availability.length > 0)
		{
			for (int i = 0; i < availability.length; i++)
			{
				if (availability[i] == 0 || availability[i] >= minAvailability)
					continue;
				minAvailability2 = minAvailability;
				minAvailability = availability[i];
				if (minAvailability == 1)
					break;
			}

		}
		if (img == null)
			img = new Image(pieceInfoCanvas.getDisplay(), bounds.width, iNeededHeight);
		gcImg = new GC(img);
		newBlockInfo = new BlockInfo[dm_pieces.length];
		iRow = 0;
		gcImg.setAdvanced(true);
		if (oldBlockInfo == null)
		{
			gcImg.setBackground(pieceInfoCanvas.getBackground());
			gcImg.fillRectangle(0, 0, bounds.width, iNeededHeight);
		}
		gcImg.setFont(font);
		int iCol = 0;
		for (int i = 0; i < dm_pieces.length; i++)
		{
			if (iCol >= iNumCols)
			{
				iCol = 0;
				iRow++;
			}
			newBlockInfo[i] = new BlockInfo();
			boolean done = dm_pieces[i].isDone();
			int iXPos = iCol * 17 + 1;
			int iYPos = iRow * 17 + 1;
			int colorIndex;
			if (done)
			{
				colorIndex = 0;
				newBlockInfo[i].haveWidth = 14;
			} else
			{
				boolean partiallyDone = dm_pieces[i].getNbWritten() > 0;
				int width = 14;
				if (partiallyDone)
				{
					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;
					newBlockInfo[i].haveWidth = iNewWidth;
				}
			}
			if (currentDLPieces[i] != null && currentDLPieces[i].hasUndownloadedBlock())
				newBlockInfo[i].downloadingIndicator = true;
			newBlockInfo[i].uploadingIndicator = uploadingPieces[i] > 0;
			if (newBlockInfo[i].uploadingIndicator)
				newBlockInfo[i].uploadingIndicatorSmall = uploadingPieces[i] < 2;
			if (availability != null)
			{
				newBlockInfo[i].availNum = availability[i];
				if (minAvailability2 == availability[i])
					newBlockInfo[i].availDotted = true;
			} else
			{
				newBlockInfo[i].availNum = -1;
			}
			if (oldBlockInfo != null && i < oldBlockInfo.length && oldBlockInfo[i].equals(newBlockInfo[i]))
			{
				iCol++;
				continue;
			}
			gcImg.setBackground(pieceInfoCanvas.getBackground());
			gcImg.fillRectangle(iCol * 17, iRow * 17, 17, 17);
			colorIndex = 0;
			gcImg.setBackground(blockColors[colorIndex]);
			gcImg.fillRectangle(iXPos, iYPos, newBlockInfo[i].haveWidth, 14);
			colorIndex = 1;
			gcImg.setBackground(blockColors[colorIndex]);
			gcImg.fillRectangle(iXPos + newBlockInfo[i].haveWidth, iYPos, 14 - newBlockInfo[i].haveWidth, 14);
			if (newBlockInfo[i].downloadingIndicator)
				drawDownloadIndicator(gcImg, iXPos, iYPos, false);
			if (newBlockInfo[i].uploadingIndicator)
				drawUploadIndicator(gcImg, iXPos, iYPos, newBlockInfo[i].uploadingIndicatorSmall);
			if (newBlockInfo[i].availNum != -1)
			{
				if (minAvailability == newBlockInfo[i].availNum)
				{
					gcImg.setForeground(blockColors[4]);
					gcImg.drawRectangle(iXPos - 1, iYPos - 1, 15, 15);
				}
				if (minAvailability2 == newBlockInfo[i].availNum)
				{
					gcImg.setLineStyle(3);
					gcImg.setForeground(blockColors[4]);
					gcImg.drawRectangle(iXPos - 1, iYPos - 1, 15, 15);
					gcImg.setLineStyle(1);
				}
				String sNumber = String.valueOf(newBlockInfo[i].availNum);
				Point size = gcImg.stringExtent(sNumber);
				if (newBlockInfo[i].availNum < 100)
				{
					int x = (iXPos + 7) - size.x / 2;
					int y = (iYPos + 7) - size.y / 2;
					gcImg.setForeground(blockColors[4]);
					gcImg.drawText(sNumber, x, y, true);
				}
			}
			iCol++;
		}

		oldBlockInfo = newBlockInfo;
		gcImg.dispose();
		break MISSING_BLOCK_LABEL_1384;
		Exception e;
		e;
		Logger.log(new LogEvent(LogIDs.GUI, "drawing piece map", e));
		gcImg.dispose();
		break MISSING_BLOCK_LABEL_1384;
		Exception exception;
		exception;
		gcImg.dispose();
		throw exception;
		topLabel.setText(MessageText.getString("PiecesView.BlockView.Header", new String[] {
			(new StringBuilder()).append("").append(iNumCols).toString(), (new StringBuilder()).append("").append(iRow + 1).toString(), (new StringBuilder()).append("").append(dm_pieces.length).toString()
		}));
		pieceInfoCanvas.redraw();
		return;
	}

	private void drawDownloadIndicator(GC gcImg, int iXPos, int iYPos, boolean small)
	{
		if (small)
		{
			gcImg.setBackground(blockColors[3]);
			gcImg.fillPolygon(new int[] {
				iXPos + 2, iYPos + 2, (iXPos + 14) - 1, iYPos + 2, iXPos + 7, (iYPos + 14) - 1
			});
		} else
		{
			gcImg.setBackground(blockColors[2]);
			gcImg.fillPolygon(new int[] {
				iXPos, iYPos, iXPos + 14, iYPos, iXPos + 7, iYPos + 14
			});
		}
	}

	private void drawUploadIndicator(GC gcImg, int iXPos, int iYPos, boolean small)
	{
		if (!small)
		{
			gcImg.setBackground(blockColors[2]);
			gcImg.fillPolygon(new int[] {
				iXPos, iYPos + 14, iXPos + 14, iYPos + 14, iXPos + 7, iYPos
			});
		} else
		{
			gcImg.setBackground(blockColors[3]);
			gcImg.fillPolygon(new int[] {
				iXPos + 1, (iYPos + 14) - 2, (iXPos + 14) - 2, (iYPos + 14) - 2, iXPos + 7, iYPos + 2
			});
		}
	}

	public Composite getComposite()
	{
		return pieceInfoComposite;
	}

	public void delete()
	{
		if (imageLabel != null && !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;
		}
		if (dlm != null)
			dlm.removePieceListener(this);
		super.delete();
	}

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

	public void pieceAdded(PEPiece piece)
	{
		fillPieceInfoSection();
	}

	public void pieceRemoved(PEPiece piece)
	{
		fillPieceInfoSection();
	}



}

⌨️ 快捷键说明

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