📄 speedgraphic.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: SpeedGraphic.java
package org.gudy.azureus2.ui.swt.components.graphics;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
// Referenced classes of package org.gudy.azureus2.ui.swt.components.graphics:
// ScaledGraphic, Scale, ValueFormater
public class SpeedGraphic extends ScaledGraphic
implements ParameterListener
{
private static final int DEFAULT_ENTRIES = 2000;
public static final int COLOR_AVERAGE = 0;
public static final int COLOR_MAINSPEED = 1;
public static final int COLOR_OVERHEAD = 2;
public static final int COLOR_LIMIT = 3;
public static final int COLOR_OTHERS = 4;
public static final int COLOR_TRIMMED = 5;
private static final int ALPHA_FOCUS = 200;
private static final int ALPHA_NOFOCUS = 150;
public Color colors[];
private int internalLoop;
private int graphicsUpdate;
private Point oldSize;
protected Image bufferImage;
private int nbValues;
private int maxEntries;
private int all_values[][];
private int currentPosition;
private int alpha;
private boolean autoAlpha;
private SpeedGraphic(Scale scale, ValueFormater formater)
{
super(scale, formater);
colors = (new Color[] {
Colors.red, Colors.blues[7], Colors.colorInverse, Colors.blue, Colors.grey, Colors.light_grey
});
nbValues = 0;
maxEntries = 2000;
all_values = new int[1][maxEntries];
alpha = 255;
autoAlpha = false;
currentPosition = 0;
COConfigurationManager.addParameterListener("Graphics Update", this);
parameterChanged("Graphics Update");
}
public void initialize(Canvas canvas)
{
super.initialize(canvas);
canvas.addMouseTrackListener(new MouseTrackListener() {
final SpeedGraphic this$0;
public void mouseHover(MouseEvent mouseevent)
{
}
public void mouseExit(MouseEvent e)
{
if (autoAlpha)
setAlpha(150);
}
public void mouseEnter(MouseEvent e)
{
if (autoAlpha)
setAlpha(200);
}
{
this$0 = SpeedGraphic.this;
super();
}
});
drawCanvas.addPaintListener(new PaintListener() {
final SpeedGraphic this$0;
public void paintControl(PaintEvent e)
{
if (bufferImage != null && !bufferImage.isDisposed())
{
Rectangle bounds = bufferImage.getBounds();
if (bounds.width >= e.width && bounds.height >= e.height)
{
if (alpha != 255)
try
{
e.gc.setAlpha(alpha);
}
catch (Exception ex) { }
e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
}
}
}
{
this$0 = SpeedGraphic.this;
super();
}
});
drawCanvas.addListener(11, new Listener() {
final SpeedGraphic this$0;
public void handleEvent(Event event)
{
drawChart(true);
}
{
this$0 = SpeedGraphic.this;
super();
}
});
}
public static SpeedGraphic getInstance()
{
return new SpeedGraphic(new Scale(), new ValueFormater() {
public String format(int value)
{
return DisplayFormatters.formatByteCountToBase10KBEtcPerSec(value);
}
});
}
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[maxEntries];
all_values = new_all_values;
}
for (int i = 0; i < new_values.length; i++)
all_values[i][currentPosition] = new_values[i];
currentPosition++;
if (nbValues < maxEntries)
nbValues++;
currentPosition %= maxEntries;
this_mon.exit();
break MISSING_BLOCK_LABEL_175;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void addIntValue(int value)
{
addIntsValue(new int[] {
value
});
}
public void refresh()
{
Rectangle bounds;
if (drawCanvas == null || drawCanvas.isDisposed())
return;
bounds = drawCanvas.getClientArea();
if (bounds.height < 30 || bounds.width < 100 || bounds.width > 10000 || bounds.height > 10000)
return;
if (bounds.width <= maxEntries)
break MISSING_BLOCK_LABEL_181;
this_mon.enter();
for (; maxEntries < bounds.width; maxEntries += 1000);
for (int i = 0; i < all_values.length; i++)
{
int newValues[] = new int[maxEntries];
System.arraycopy(all_values[i], 0, newValues, 0, all_values[i].length);
all_values[i] = newValues;
}
this_mon.exit();
break MISSING_BLOCK_LABEL_181;
Exception exception;
exception;
this_mon.exit();
throw exception;
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);
drawCanvas.redraw();
drawCanvas.update();
return;
}
protected void drawChart(boolean sizeChanged)
{
GC gcImage;
if (drawCanvas == null || drawCanvas.isDisposed() || !drawCanvas.isVisible())
return;
gcImage = null;
this_mon.enter();
drawScale(sizeChanged);
if (bufferScale == null || bufferScale.isDisposed())
{
if (gcImage != null)
gcImage.dispose();
this_mon.exit();
return;
}
Rectangle bounds = drawCanvas.getClientArea();
if (bounds.isEmpty())
{
if (gcImage != null)
gcImage.dispose();
this_mon.exit();
return;
}
if (bufferImage != null && !bufferImage.isDisposed())
bufferImage.dispose();
bufferImage = new Image(drawCanvas.getDisplay(), bounds);
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 += maxEntries;
if (position < 0)
position = 0;
}
for (int chartIdx = 0; chartIdx < all_values.length; chartIdx++)
{
int value = all_values[chartIdx][position];
if (value > maxs[chartIdx])
maxs[chartIdx] = value;
}
}
int max = maxs[0];
int max_primary = max;
for (int i = 1; i < maxs.length; i++)
{
int m = maxs[i];
if (i == 1)
{
if (max < m)
{
max = m;
max_primary = max;
}
continue;
}
if (max >= m)
continue;
if (m <= 2 * max_primary)
{
max = m;
continue;
}
max = 2 * max_primary;
break;
}
scale.setMax(max);
int maxHeight = scale.getScaledValue(max);
Color background = colors[1];
Color foreground = colors[1];
for (int x = 0; x < bounds.width - 71; x++)
{
int position = currentPosition - x - 1;
if (position < 0)
{
position += maxEntries;
if (position < 0)
position = 0;
}
int xDraw = bounds.width - 71 - x;
int height = scale.getScaledValue(all_values[0][position]);
gcImage.setForeground(background);
gcImage.setBackground(foreground);
gcImage.setClipping(xDraw, bounds.height - 1 - height, 1, height);
gcImage.fillGradientRectangle(xDraw, bounds.height - 1 - maxHeight, 1, maxHeight, true);
gcImage.setClipping(0, 0, bounds.width, bounds.height);
if (all_values.length > 1)
{
gcImage.setForeground(colors[2]);
height = scale.getScaledValue(all_values[1][position]);
Utils.drawStriped(gcImage, xDraw, bounds.height - 1 - height, 1, height, 1, currentPosition, false);
}
for (int chartIdx = 2; chartIdx < all_values.length; chartIdx++)
{
int targetValue = all_values[chartIdx][position];
int oldTargetValue = oldTargetValues[chartIdx];
if (x > 1 && (chartIdx == 2 && targetValue > 0 && oldTargetValue > 0 || chartIdx > 2 && (targetValue > 0 || oldTargetValue > 0)))
{
int trimmed = 0;
if (targetValue > max)
{
targetValue = max;
trimmed++;
}
if (oldTargetValue > max)
{
oldTargetValue = max;
trimmed++;
}
if (trimmed < 2 || trimmed == 2 && position % 3 == 0)
{
int h1 = bounds.height - scale.getScaledValue(targetValue) - 2;
int h2 = bounds.height - scale.getScaledValue(oldTargetValue) - 2;
gcImage.setForeground(chartIdx != 2 ? trimmed <= 0 ? colors[4] : colors[5] : colors[3]);
gcImage.drawLine(xDraw, h1, xDraw + 1, h2);
}
}
oldTargetValues[chartIdx] = all_values[chartIdx][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.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);
}
if (gcImage != null)
gcImage.dispose();
this_mon.exit();
break MISSING_BLOCK_LABEL_1081;
Exception e;
e;
Debug.out("Warning", e);
if (gcImage != null)
gcImage.dispose();
this_mon.exit();
break MISSING_BLOCK_LABEL_1081;
Exception exception;
exception;
if (gcImage != null)
gcImage.dispose();
this_mon.exit();
throw exception;
}
protected int computeAverage(int position)
{
long sum = 0L;
for (int i = -5; i < 6; i++)
{
int pos = position + i;
pos %= maxEntries;
if (pos < 0)
pos += maxEntries;
sum += all_values[0][pos];
}
return (int)(sum / 11L);
}
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);
}
private int getAlpha()
{
return alpha;
}
public void setAlpha(int alpha)
{
this.alpha = alpha;
if (drawCanvas != null && !drawCanvas.isDisposed())
drawCanvas.redraw();
}
private boolean isAutoAlpha()
{
return autoAlpha;
}
private void setAutoAlpha(boolean autoAlpha)
{
this.autoAlpha = autoAlpha;
if (autoAlpha)
setAlpha(drawCanvas.getDisplay().getCursorControl() != drawCanvas ? 150 : 200);
}
public void setLineColors(Color average, Color speed, Color overhead, Color limit, Color others, Color trimmed)
{
if (average != null)
colors[0] = average;
if (speed != null)
colors[1] = speed;
if (overhead != null)
colors[2] = overhead;
if (limit != null)
colors[3] = limit;
if (others != null)
colors[4] = others;
if (trimmed != null)
colors[5] = trimmed;
if (drawCanvas != null && !drawCanvas.isDisposed())
drawCanvas.redraw();
}
public void setLineColors(Color newChangeableColorSet[])
{
colors = newChangeableColorSet;
if (drawCanvas != null && !drawCanvas.isDisposed())
drawCanvas.redraw();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -