📄 pinggraphic.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: PingGraphic.java
package org.gudy.azureus2.ui.swt.components.graphics;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Canvas;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.util.AEMonitor;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
// Referenced classes of package org.gudy.azureus2.ui.swt.components.graphics:
// ScaledGraphic, Scale, ValueFormater
public class PingGraphic extends ScaledGraphic
implements ParameterListener
{
private static final int ENTRIES = 2000;
private static final int COLOR_AVERAGE = 0;
public static Color colors[];
private int internalLoop;
private int graphicsUpdate;
private Point oldSize;
protected Image bufferImage;
private int average;
private int nbValues;
private int all_values[][];
private int currentPosition;
private PingGraphic(Scale scale, ValueFormater formater)
{
super(scale, formater);
average = 0;
nbValues = 0;
all_values = new int[1][2000];
currentPosition = 0;
COConfigurationManager.addParameterListener("Graphics Update", this);
parameterChanged("Graphics Update");
}
public static PingGraphic getInstance()
{
return new PingGraphic(new Scale(), new ValueFormater() {
public String format(int value)
{
return (new StringBuilder()).append(value).append(" ms").toString();
}
});
}
public void addIntsValue(int new_values[])
{
this_mon.enter();
if (all_values.length < new_values.length)
{
int new_all_values[][] = new int[new_values.length][];
for (int i = 0; i < all_values.length; i++)
new_all_values[i] = all_values[i];
for (int i = all_values.length; i < new_all_values.length; i++)
new_all_values[i] = new int[2000];
all_values = new_all_values;
}
average += new_values[0] - all_values[0][currentPosition];
for (int i = 0; i < new_values.length; i++)
all_values[i][currentPosition] = new_values[i];
currentPosition++;
if (nbValues < 2000)
nbValues++;
if (currentPosition >= 2000)
currentPosition = 0;
this_mon.exit();
break MISSING_BLOCK_LABEL_199;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void refresh()
{
if (drawCanvas == null || drawCanvas.isDisposed())
return;
Rectangle bounds = drawCanvas.getClientArea();
if (bounds.height < 30 || bounds.width < 100 || bounds.width > 2000 || bounds.height > 2000)
return;
boolean sizeChanged = oldSize == null || oldSize.x != bounds.width || oldSize.y != bounds.height;
oldSize = new Point(bounds.width, bounds.height);
internalLoop++;
if (internalLoop > graphicsUpdate)
internalLoop = 0;
if (internalLoop == 0 || sizeChanged)
drawChart(sizeChanged);
GC gc = new GC(drawCanvas);
gc.drawImage(bufferImage, bounds.x, bounds.y);
gc.dispose();
}
protected void drawChart(boolean sizeChanged)
{
this_mon.enter();
drawScale(sizeChanged);
Rectangle bounds = drawCanvas.getClientArea();
if (bufferImage != null && !bufferImage.isDisposed())
bufferImage.dispose();
bufferImage = new Image(drawCanvas.getDisplay(), bounds);
GC gcImage = new GC(bufferImage);
gcImage.drawImage(bufferScale, 0, 0);
int oldAverage = 0;
int oldTargetValues[] = new int[all_values.length];
int maxs[] = new int[all_values.length];
for (int x = 0; x < bounds.width - 71; x++)
{
int position = currentPosition - x - 1;
if (position < 0)
position += 2000;
for (int z = 0; z < all_values.length; z++)
{
int value = all_values[z][position];
if (value > maxs[z])
maxs[z] = value;
}
}
int max = 0;
for (int i = 0; i < maxs.length; i++)
if (maxs[i] > max)
max = maxs[i];
scale.setMax(max);
int maxHeight = scale.getScaledValue(max);
for (int x = 0; x < bounds.width - 71; x++)
{
int position = currentPosition - x - 1;
if (position < 0)
position += 2000;
int xDraw = bounds.width - 71 - x;
gcImage.setLineWidth(1);
for (int z = 0; z < all_values.length; z++)
{
int targetValue = all_values[z][position];
int oldTargetValue = oldTargetValues[z];
if (x > 1)
{
int h1 = bounds.height - scale.getScaledValue(targetValue) - 2;
int h2 = bounds.height - scale.getScaledValue(oldTargetValue) - 2;
gcImage.setForeground(z > 2 ? colors[3] : colors[z + 1]);
gcImage.drawLine(xDraw, h1, xDraw + 1, h2);
}
oldTargetValues[z] = all_values[z][position];
}
int average = computeAverage(position);
if (x > 6)
{
int h1 = bounds.height - scale.getScaledValue(average) - 2;
int h2 = bounds.height - scale.getScaledValue(oldAverage) - 2;
gcImage.setForeground(colors[0]);
gcImage.setLineWidth(2);
gcImage.drawLine(xDraw, h1, xDraw + 1, h2);
}
oldAverage = average;
}
if (nbValues > 0)
{
int height = bounds.height - scale.getScaledValue(computeAverage(currentPosition - 6)) - 2;
gcImage.setForeground(colors[0]);
gcImage.drawText(formater.format(computeAverage(currentPosition - 6)), bounds.width - 65, height - 12, true);
}
gcImage.dispose();
this_mon.exit();
break MISSING_BLOCK_LABEL_638;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
protected int computeAverage(int position)
{
int sum = 0;
int nbItems = 0;
for (int i = -5; i < 6; i++)
{
int pos = position + i;
if (pos < 0)
pos += 2000;
if (pos >= 2000)
pos -= 2000;
for (int z = 0; z < all_values.length; z++)
{
sum += all_values[z][pos];
nbItems++;
}
}
return sum / nbItems;
}
public void parameterChanged(String parameter)
{
graphicsUpdate = COConfigurationManager.getIntParameter("Graphics Update");
}
public void dispose()
{
super.dispose();
if (bufferImage != null && !bufferImage.isDisposed())
bufferImage.dispose();
COConfigurationManager.removeParameterListener("Graphics Update", this);
}
static
{
colors = (new Color[] {
Colors.grey, Colors.blues[7], Colors.fadedGreen, Colors.fadedRed
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -