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

📄 transferstatsview.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// 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:   TransferStatsView.java

package org.gudy.azureus2.ui.swt.views.stats;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.speedmanager.*;
import java.text.DecimalFormat;
import java.util.*;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.global.GlobalManagerStats;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.stats.transfer.OverallStats;
import org.gudy.azureus2.core3.stats.transfer.StatsFactory;
import org.gudy.azureus2.core3.util.DisplayFormatters;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.components.BufferedLabel;
import org.gudy.azureus2.ui.swt.components.Legend;
import org.gudy.azureus2.ui.swt.components.graphics.*;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.views.AbstractIView;

public class TransferStatsView extends AbstractIView
{
	public static class limitToTextHelper
	{

		String msg_text_unknown;
		String msg_text_estimate;
		String msg_text_choke_estimate;
		String msg_text_measured_min;
		String msg_text_measured;
		String msg_text_manual;
		String msg_unlimited;
		String setable_types[];

		public String[] getSettableTypes()
		{
			return setable_types;
		}

		public String getSettableType(SpeedManagerLimitEstimate limit)
		{
			float type = limit.getEstimateType();
			String text;
			if (type == -0.1F)
				text = "";
			else
			if (type == 1.0F)
				text = msg_text_manual;
			else
			if (type == 0.9F)
				text = msg_text_measured;
			else
			if (type == 0.8F)
				text = msg_text_measured;
			else
			if (type == 0.5F)
				text = msg_text_estimate;
			else
				text = msg_text_estimate;
			return text;
		}

		public String typeToText(float type)
		{
			String text;
			if (type == -0.1F)
				text = msg_text_unknown;
			else
			if (type == 1.0F)
				text = msg_text_manual;
			else
			if (type == 0.9F)
				text = msg_text_measured;
			else
			if (type == 0.8F)
				text = msg_text_measured_min;
			else
			if (type == 0.5F)
				text = msg_text_choke_estimate;
			else
				text = msg_text_estimate;
			return text;
		}

		public float textToType(String text)
		{
			if (text.equals(msg_text_estimate))
				return 0.0F;
			if (text.equals(msg_text_choke_estimate))
				return 0.5F;
			if (text.equals(msg_text_measured))
				return 0.9F;
			return !text.equals(msg_text_manual) ? -0.1F : 1.0F;
		}

		public String getLimitText(SpeedManagerLimitEstimate limit)
		{
			float type = limit.getEstimateType();
			String text = typeToText(type);
			int l = limit.getBytesPerSec();
			if (l == 0)
				return (new StringBuilder()).append(msg_unlimited).append(" (").append(text).append(")").toString();
			else
				return (new StringBuilder()).append(DisplayFormatters.formatByteCountToKiBEtcPerSec(l)).append(" (").append(text).append(")").toString();
		}

		public String getUnlimited()
		{
			return msg_unlimited;
		}

		public limitToTextHelper()
		{
			msg_text_unknown = MessageText.getString("SpeedView.stats.unknown");
			msg_text_estimate = MessageText.getString("SpeedView.stats.estimate");
			msg_text_choke_estimate = MessageText.getString("SpeedView.stats.estimatechoke");
			msg_text_measured = MessageText.getString("SpeedView.stats.measured");
			msg_text_measured_min = MessageText.getString("SpeedView.stats.measuredmin");
			msg_text_manual = MessageText.getString("SpeedView.stats.manual");
			msg_unlimited = MessageText.getString("ConfigView.unlimited");
			setable_types = (new String[] {
				"", msg_text_estimate, msg_text_measured, msg_text_manual
			});
		}
	}

	class plotView
	{

		private SpeedManagerPingMapper mapper;
		private Plot3D plotGraph;
		final TransferStatsView this$0;

		protected void update()
		{
			int history[][] = mapper.getHistory();
			plotGraph.update(history);
			plotGraph.setTitle(getMapperTitle(mapper));
		}

		protected void refresh()
		{
			plotGraph.refresh();
		}

		protected void dispose()
		{
			plotGraph.dispose();
		}


		protected plotView(SpeedManagerPingMapper _mapper, Canvas _canvas, String _labels[], ValueFormater _formatters[])
		{
			this$0 = TransferStatsView.this;
			super();
			mapper = _mapper;
			plotGraph = new Plot3D(_labels, _formatters);
			plotGraph.initialize(_canvas);
		}
	}

	class zoneView
		implements ParameterListener
	{

		private SpeedManagerPingMapper mapper;
		private SpeedManagerPingZone zones[];
		private Canvas canvas;
		private ValueFormater formatters[];
		private String labels[];
		private String title;
		private int refresh_count;
		private int graphicsUpdate;
		private Point old_size;
		protected Image buffer_image;
		final TransferStatsView this$0;

		public void parameterChanged(String name)
		{
			graphicsUpdate = COConfigurationManager.getIntParameter(name);
		}

		protected void update()
		{
			zones = mapper.getZones();
			title = getMapperTitle(mapper);
		}

		private void refresh()
		{
			if (canvas.isDisposed())
				return;
			Rectangle bounds = canvas.getClientArea();
			if (bounds.height < 30 || bounds.width < 100 || bounds.width > 2000 || bounds.height > 2000)
				return;
			boolean size_changed = old_size == null || old_size.x != bounds.width || old_size.y != bounds.height;
			old_size = new Point(bounds.width, bounds.height);
			refresh_count++;
			if (refresh_count > graphicsUpdate)
				refresh_count = 0;
			if (refresh_count == 0 || size_changed)
			{
				if (buffer_image != null && !buffer_image.isDisposed())
					buffer_image.dispose();
				buffer_image = draw(bounds);
			}
			if (buffer_image != null)
			{
				GC gc = new GC(canvas);
				gc.drawImage(buffer_image, bounds.x, bounds.y);
				gc.dispose();
			}
		}

		private Image draw(Rectangle bounds)
		{
			int PAD_TOP = 10;
			int PAD_BOTTOM = 10;
			int PAD_RIGHT = 10;
			int PAD_LEFT = 10;
			int usable_width = bounds.width - 10 - 10;
			int usable_height = bounds.height - 10 - 10;
			Image image = new Image(canvas.getDisplay(), bounds);
			GC gc = new GC(image);
			try
			{
				gc.setAntialias(1);
			}
			catch (Exception e) { }
			int font_height = gc.getFontMetrics().getHeight();
			int char_width = gc.getFontMetrics().getAverageCharWidth();
			org.eclipse.swt.graphics.Color colours[] = plot_views[0].plotGraph.getColours();
			int max_x = 0;
			int max_y = 0;
			if (zones.length > 0)
			{
				int max_metric = 0;
				for (int i = 0; i < zones.length; i++)
				{
					SpeedManagerPingZone zone = zones[i];
					int metric = zone.getMetric();
					if (metric > 0)
					{
						max_metric = Math.max(max_metric, metric);
						max_x = Math.max(max_x, zone.getUploadEndBytesPerSec());
						max_y = Math.max(max_y, zone.getDownloadEndBytesPerSec());
					}
				}

				if (max_x > 0 && max_y > 0)
				{
					double x_ratio = (double)usable_width / (double)max_x;
					double y_ratio = (double)usable_height / (double)max_y;
					List texts = new ArrayList();
					for (int i = 0; i < zones.length; i++)
					{
						SpeedManagerPingZone zone = zones[i];
						int metric = zone.getMetric();
						int x1 = zone.getUploadStartBytesPerSec();
						int y1 = zone.getDownloadStartBytesPerSec();
						int x2 = zone.getUploadEndBytesPerSec();
						int y2 = zone.getDownloadEndBytesPerSec();
						if (metric <= 0)
							continue;
						int colour_index = (int)(((float)metric * (float)colours.length) / (float)max_metric);
						if (colour_index >= colours.length)
							colour_index = colours.length - 1;
						gc.setBackground(colours[colour_index]);
						int x = 10 + (int)((double)x1 * x_ratio);
						int y = 10 + (int)((double)y1 * y_ratio);
						int width = (int)Math.ceil((double)((x2 - x1) + 1) * x_ratio);
						int height = (int)Math.ceil((double)((y2 - y1) + 1) * y_ratio);
						int y_draw = (usable_height + 10 + 10) - y - height;
						gc.fillRectangle(x, y_draw, width, height);
						int text_metric = zone.getMetric();
						String text = String.valueOf(metric);
						int text_width = text.length() * char_width + 4;
						if (width < text_width || height < font_height)
							continue;
						Rectangle text_rect = new Rectangle(x + (width - text_width) / 2, y_draw + (height - font_height) / 2, text_width, font_height);
						Iterator it = texts.iterator();
						do
						{
							if (!it.hasNext())
								break;
							Object old[] = (Object[])(Object[])it.next();
							Rectangle old_coords = (Rectangle)old[1];
							if (old_coords.intersects(text_rect))
								it.remove();
						} while (true);
						texts.add(((Object) (new Object[] {
							new Integer(text_metric), text_rect
						})));
					}

					int text_num = texts.size();
					for (int i = text_num <= 100 ? 0 : text_num - 100; i < text_num; i++)
					{
						Object entry[] = (Object[])(Object[])texts.get(i);
						String str = String.valueOf(entry[0]);
						Rectangle rect = (Rectangle)entry[1];
						gc.drawText(str, rect.x, rect.y, 1);
					}

				}
			}
			int x_axis_left_x = 10;
			int x_axis_left_y = usable_height + 10;
			int x_axis_right_x = 10 + usable_width;
			int x_axis_right_y = x_axis_left_y;
			gc.drawLine(x_axis_left_x, x_axis_left_y, x_axis_right_x, x_axis_right_y);
			gc.drawLine(usable_width, x_axis_right_y - 4, x_axis_right_x, x_axis_right_y);
			gc.drawLine(usable_width, x_axis_right_y + 4, x_axis_right_x, x_axis_right_y);
			for (int i = 1; i < 10; i++)
			{
				int x = x_axis_left_x + ((x_axis_right_x - x_axis_left_x) * i) / 10;
				gc.drawLine(x, x_axis_left_y, x, x_axis_left_y + 4);
			}

			SpeedManagerLimitEstimate le = mapper.getEstimatedUploadLimit(false);
			if (le != null)
			{
				gc.setForeground(Colors.grey);
				int segs[][] = le.getSegments();
				if (segs.length > 0)
				{
					int max_metric = 0;
					int max_pos = 0;
					for (int i = 0; i < segs.length; i++)
					{
						int seg[] = segs[i];
						max_metric = Math.max(max_metric, seg[0]);
						max_pos = Math.max(max_pos, seg[2]);
					}

					double metric_ratio = max_metric != 0 ? 50F / (float)max_metric : 1.0D;
					double pos_ratio = max_pos != 0 ? (float)usable_width / (float)max_pos : 1.0D;
					int prev_x = 1;
					int prev_y = 1;
					for (int i = 0; i < segs.length; i++)
					{
						int seg[] = segs[i];
						int next_x = (int)((double)(seg[1] + (seg[2] - seg[1]) / 2) * pos_ratio) + 1;
						int next_y = (int)((double)seg[0] * metric_ratio) + 1;
						gc.drawLine(x_axis_left_x + prev_x, x_axis_left_y - prev_y, x_axis_left_x + next_x, x_axis_left_y - next_y);
						prev_x = next_x;
						prev_y = next_y;
					}

				}
				gc.setForeground(Colors.black);
			}
			SpeedManagerLimitEstimate bad_up[] = mapper.getBadUploadHistory();
			if (bad_up.length > 0)
			{
				gc.setLineWidth(3);
				gc.setForeground(Colors.red);
				for (int i = 0; i < bad_up.length; i++)
				{
					int speed = bad_up[i].getBytesPerSec();
					int x = max_x != 0 ? (speed * usable_width) / max_x : 0;
					gc.drawLine(x_axis_left_x + x, x_axis_left_y - 0, x_axis_left_x + x, x_axis_left_y - 10);
				}

				gc.setForeground(Colors.black);
				gc.setLineWidth(1);
			}
			String x_text = (new StringBuilder()).append(labels[0]).append(" - ").append(formatters[0].format(max_x + 1)).toString();
			gc.drawText(x_text, x_axis_right_x - 20 - x_text.length() * char_width, x_axis_right_y - font_height - 2, 1);
			int y_axis_bottom_x = 10;
			int y_axis_bottom_y = usable_height + 10;
			int y_axis_top_x = 10;
			int y_axis_top_y = 10;
			gc.drawLine(y_axis_bottom_x, y_axis_bottom_y, y_axis_top_x, y_axis_top_y);
			gc.drawLine(y_axis_top_x - 4, y_axis_top_y + 10, y_axis_top_x, y_axis_top_y);
			gc.drawLine(y_axis_top_x + 4, y_axis_top_y + 10, y_axis_top_x, y_axis_top_y);
			for (int i = 1; i < 10; i++)
			{
				int y = y_axis_bottom_y + ((y_axis_top_y - y_axis_bottom_y) * i) / 10;
				gc.drawLine(y_axis_bottom_x, y, y_axis_bottom_x - 4, y);
			}

			le = mapper.getEstimatedDownloadLimit(false);
			if (le != null)
			{
				gc.setForeground(Colors.grey);
				int segs[][] = le.getSegments();
				if (segs.length > 0)
				{
					int max_metric = 0;
					int max_pos = 0;
					for (int i = 0; i < segs.length; i++)
					{
						int seg[] = segs[i];
						max_metric = Math.max(max_metric, seg[0]);
						max_pos = Math.max(max_pos, seg[2]);
					}

					double metric_ratio = max_metric != 0 ? 50F / (float)max_metric : 1.0D;
					double pos_ratio = max_pos != 0 ? (float)usable_height / (float)max_pos : 1.0D;
					int prev_x = 1;
					int prev_y = 1;
					for (int i = 0; i < segs.length; i++)
					{
						int seg[] = segs[i];
						int next_x = (int)((double)seg[0] * metric_ratio) + 1;
						int next_y = (int)((double)(seg[1] + (seg[2] - seg[1]) / 2) * pos_ratio) + 1;
						gc.drawLine(y_axis_bottom_x + prev_x, y_axis_bottom_y - prev_y, y_axis_bottom_x + next_x, y_axis_bottom_y - next_y);
						prev_x = next_x;
						prev_y = next_y;
					}

⌨️ 快捷键说明

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